From 9774aa5439a4345c29e9a6783a36aa4e79b9489f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Sat, 27 Feb 2021 00:02:56 +0000 Subject: [PATCH 01/61] Remove passing-by-reference feature (#335) --- .../WhereRef/WhereRef.Array.Tests.cs | 34 -- .../WhereRef/WhereRef.ArraySegment.Tests.cs | 53 --- .../WhereRef/WhereRef.Memory.Tests.cs | 32 -- .../WhereRef/WhereRef.ReadOnlyMemory.Tests.cs | 32 -- .../WhereRef/WhereRef.ReadOnlySpan.Tests.cs | 29 -- .../Filtering/WhereRef/WhereRef.Span.Tests.cs | 29 -- .../WhereRefAt/WhereRefAt.Array.Tests.cs | 34 -- .../WhereRefAt.ArraySegment.Tests.cs | 53 --- .../WhereRefAt/WhereRefAt.Memory.Tests.cs | 32 -- .../WhereRefAt.ReadOnlyMemory.Tests.cs | 32 -- .../WhereRefAt.ReadOnlySpan.Tests.cs | 29 -- .../WhereRefAt/WhereRefAt.Span.Tests.cs | 29 -- .../Aggregation/Count/Count.ReadOnlyList.cs | 13 +- .../Aggregation/Count/Count.ReadOnlySpan.cs | 23 - .../Aggregation/Sum/Sum.ReadOnlyList.cs | 80 ---- .../Aggregation/Sum/Sum.ReadOnlySpan.cs | 67 +-- .../Aggregation/Sum/Sum.ValueEnumerable.cs | 87 +--- .../Sum/Sum.ValueReadOnlyCollection.cs | 31 ++ .../System/Collections/Generic/List.cs | 4 - .../AsValueEnumerableRef.Array.cs | 13 - .../AsValueEnumerableRef.ArraySegment.cs | 412 ------------------ .../AsValueEnumerableRef.Memory.cs | 367 ---------------- .../AsValueEnumerableRef.ReadOnlyMemory.cs | 367 ---------------- .../ReadOnlySpanEnumeratorRef.cs | 29 -- .../AsValueEnumerableRef/SpanEnumeratorRef.cs | 29 -- .../ToArray/ToArray.ReadOnlySpan.cs | 176 -------- .../ToDictionary/ToDictionary.ReadOnlySpan.cs | 146 +------ .../ToDictionary/ToDictionary.Span.cs | 23 - .../Conversion/ToList/ToList.ReadOnlySpan.cs | 46 -- .../ElementAt/ElementAt.ReadOnlyList.cs | 7 +- .../Where/{ => Where}/Where.ArraySegment.cs | 2 +- .../{ => Where}/Where.AsyncValueEnumerable.cs | 0 .../Where/{ => Where}/Where.ReadOnlyList.cs | 0 .../Where/{ => Where}/Where.ReadOnlyMemory.cs | 0 .../Where/{ => Where}/Where.ReadOnlySpan.cs | 0 .../Filtering/Where/{ => Where}/Where.Span.cs | 0 .../{ => Where}/Where.ValueEnumerable.cs | 0 .../Where.ValueReadOnlyCollection.cs | 0 .../Where/{ => Where}/WhereEnumerator.cs | 0 .../WhereAt/WhereAt.ArraySegment.cs | 0 .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 0 .../WhereAt/WhereAt.ReadOnlyList.cs | 0 .../WhereAt/WhereAt.ReadOnlyMemory.cs | 0 .../WhereAt/WhereAt.ReadOnlySpan.cs | 0 .../{ => Where}/WhereAt/WhereAt.Span.cs | 0 .../WhereAt/WhereAt.ValueEnumerable.cs | 0 .../WhereAt.ValueReadOnlyCollection.cs | 0 .../{ => Where}/WhereAt/WhereAtEnumerator.cs | 0 .../WhereAtReadOnlyRefEnumerator.cs | 40 -- .../WhereAtRef/WhereAtRef.ArraySegment.cs | 134 ------ .../Filtering/WhereAtRef/WhereAtRef.Memory.cs | 80 ---- .../WhereAtRef/WhereAtRef.ReadOnlyMemory.cs | 130 ------ .../WhereAtRef/WhereAtRef.ReadOnlySpan.cs | 134 ------ .../Filtering/WhereAtRef/WhereAtRef.Span.cs | 84 ---- .../WhereAtRef/WhereAtRefEnumerator.cs | 41 -- .../WhereRef/WhereReadOnlyRefEnumerator.cs | 40 -- .../WhereRef/WhereRef.ArraySegment.cs | 219 ---------- .../Filtering/WhereRef/WhereRef.Memory.cs | 80 ---- .../WhereRef/WhereRef.ReadOnlyMemory.cs | 131 ------ .../WhereRef/WhereRef.ReadOnlySpan.cs | 134 ------ .../Filtering/WhereRef/WhereRef.Span.cs | 84 ---- .../Filtering/WhereRef/WhereRefEnumerator.cs | 41 -- .../WhereSelect.ArraySegment.cs | 0 .../WhereSelect.AsyncValueEnumerable.cs | 0 .../WhereSelect.ReadOnlyList.cs | 0 .../WhereSelect.ReadOnlyMemory.cs | 0 .../WhereSelect.ReadOnlySpan.cs | 0 .../WhereSelect.ValueEnumerable.cs | 0 .../WhereSelect.ValueReadOnlyCollection.cs | 0 .../WhereSelectEnumerator.cs | 0 .../WhereSelectReadOnlyRefEnumerator.cs | 43 -- .../WhereSelectRef.ArraySegment.cs | 312 ------------- .../WhereSelectRefEnumerator.cs | 43 -- .../NetFabric.Hyperlinq.csproj | 6 + .../{ => Select}/Select.ArraySegment.cs | 0 .../Select.AsyncValueEnumerable.cs | 0 .../{ => Select}/Select.ReadOnlyList.cs | 0 .../{ => Select}/Select.ReadOnlyMemory.cs | 0 .../{ => Select}/Select.ReadOnlySpan.cs | 0 .../Select/{ => Select}/Select.Span.cs | 0 .../{ => Select}/Select.ValueEnumerable.cs | 0 .../Select.ValueReadOnlyCollection.cs | 0 .../Select/{ => Select}/SelectEnumerator.cs | 0 .../SelectAt/SelectAt.ArraySegment.cs | 0 .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 0 .../SelectAt/SelectAt.ReadOnlyList.cs | 0 .../SelectAt/SelectAt.ReadOnlyMemory.cs | 0 .../SelectAt/SelectAt.ReadOnlySpan.cs | 0 .../{ => Select}/SelectAt/SelectAt.Span.cs | 0 .../SelectAt/SelectAt.ValueEnumerable.cs | 0 .../SelectAt.ValueReadOnlyCollection.cs | 0 .../SelectAt/SelectAtEnumerator.cs | 0 .../SelectVector/SelectVector.ArraySegment.cs | 0 .../SelectVector/SelectVector.Memory.cs | 0 .../SelectVector/SelectVector.Range.cs | 0 .../SelectVector.ReadOnlyMemory.cs | 0 .../SelectVector/SelectVector.ReadOnlySpan.cs | 0 .../SelectVector/SelectVector.Span.cs | 0 .../SelectAtRef/SelectAtRef.ArraySegment.cs | 291 ------------- .../SelectAtRef/SelectAtRefEnumerator.cs | 32 -- .../SelectMany.ArraySegment.cs | 0 .../SelectMany.ReadOnlyList.cs | 0 .../SelectMany.ReadOnlyMemory.cs | 0 .../SelectMany.ValueEnumerable.cs | 0 .../SelectRef/SelectRef.ArraySegment.cs | 268 ------------ .../SelectRef/SelectRef.ReadOnlyMemory.cs | 284 ------------ .../SelectRef/SelectRef.ReadOnlySpan.cs | 193 -------- .../SelectRef/SelectRefEnumerator.cs | 32 -- .../Quantifier/AllRef/AllRef.Memory.cs | 29 -- .../Quantifier/AllRef/AllRef.ReadOnlySpan.cs | 41 -- .../Quantifier/AllRef/AllRef.Span.cs | 29 -- .../Quantifier/AnyRef/AnyRef.ReadOnlySpan.cs | 41 -- .../Quantifier/AnyRef/AnyRef.Span.cs | 28 -- .../Contains/Contains.ReadOnlySpan.cs | 67 --- .../Contains/Contains.ValueEnumerable.cs | 34 -- .../ToArrayBuilder.ReadOnlySpan.cs | 38 -- .../Utils/Copy/Copy.ReadOnlySpan.cs | 26 -- .../Utils/IndexOf/IndexOf.ReadOnlyList.cs | 85 ---- .../Utils/IndexOf/IndexOf.ReadOnlySpan.cs | 60 --- README.md | 21 - 120 files changed, 44 insertions(+), 5671 deletions(-) delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ReadOnlySpan.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ReadOnlySpan.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Span.Tests.cs create mode 100644 NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.Array.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.Memory.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.ReadOnlyMemory.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/ReadOnlySpanEnumeratorRef.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/SpanEnumeratorRef.cs rename NetFabric.Hyperlinq/Filtering/Where/{ => Where}/Where.ArraySegment.cs (99%) rename NetFabric.Hyperlinq/Filtering/Where/{ => Where}/Where.AsyncValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Filtering/Where/{ => Where}/Where.ReadOnlyList.cs (100%) rename NetFabric.Hyperlinq/Filtering/Where/{ => Where}/Where.ReadOnlyMemory.cs (100%) rename NetFabric.Hyperlinq/Filtering/Where/{ => Where}/Where.ReadOnlySpan.cs (100%) rename NetFabric.Hyperlinq/Filtering/Where/{ => Where}/Where.Span.cs (100%) rename NetFabric.Hyperlinq/Filtering/Where/{ => Where}/Where.ValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Filtering/Where/{ => Where}/Where.ValueReadOnlyCollection.cs (100%) rename NetFabric.Hyperlinq/Filtering/Where/{ => Where}/WhereEnumerator.cs (100%) rename NetFabric.Hyperlinq/Filtering/{ => Where}/WhereAt/WhereAt.ArraySegment.cs (100%) rename NetFabric.Hyperlinq/Filtering/{ => Where}/WhereAt/WhereAt.AsyncValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Filtering/{ => Where}/WhereAt/WhereAt.ReadOnlyList.cs (100%) rename NetFabric.Hyperlinq/Filtering/{ => Where}/WhereAt/WhereAt.ReadOnlyMemory.cs (100%) rename NetFabric.Hyperlinq/Filtering/{ => Where}/WhereAt/WhereAt.ReadOnlySpan.cs (100%) rename NetFabric.Hyperlinq/Filtering/{ => Where}/WhereAt/WhereAt.Span.cs (100%) rename NetFabric.Hyperlinq/Filtering/{ => Where}/WhereAt/WhereAt.ValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Filtering/{ => Where}/WhereAt/WhereAt.ValueReadOnlyCollection.cs (100%) rename NetFabric.Hyperlinq/Filtering/{ => Where}/WhereAt/WhereAtEnumerator.cs (100%) delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtReadOnlyRefEnumerator.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.Memory.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ReadOnlyMemory.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ReadOnlySpan.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.Span.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRefEnumerator.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereRef/WhereReadOnlyRefEnumerator.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.Memory.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ReadOnlyMemory.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ReadOnlySpan.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.Span.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereRef/WhereRefEnumerator.cs rename NetFabric.Hyperlinq/Filtering/WhereSelect/{ => WhereSelect}/WhereSelect.ArraySegment.cs (100%) rename NetFabric.Hyperlinq/Filtering/WhereSelect/{ => WhereSelect}/WhereSelect.AsyncValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Filtering/WhereSelect/{ => WhereSelect}/WhereSelect.ReadOnlyList.cs (100%) rename NetFabric.Hyperlinq/Filtering/WhereSelect/{ => WhereSelect}/WhereSelect.ReadOnlyMemory.cs (100%) rename NetFabric.Hyperlinq/Filtering/WhereSelect/{ => WhereSelect}/WhereSelect.ReadOnlySpan.cs (100%) rename NetFabric.Hyperlinq/Filtering/WhereSelect/{ => WhereSelect}/WhereSelect.ValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Filtering/WhereSelect/{ => WhereSelect}/WhereSelect.ValueReadOnlyCollection.cs (100%) rename NetFabric.Hyperlinq/Filtering/WhereSelect/{ => WhereSelect}/WhereSelectEnumerator.cs (100%) delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectReadOnlyRefEnumerator.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectRef.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectRefEnumerator.cs rename NetFabric.Hyperlinq/Projection/Select/{ => Select}/Select.ArraySegment.cs (100%) rename NetFabric.Hyperlinq/Projection/Select/{ => Select}/Select.AsyncValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Projection/Select/{ => Select}/Select.ReadOnlyList.cs (100%) rename NetFabric.Hyperlinq/Projection/Select/{ => Select}/Select.ReadOnlyMemory.cs (100%) rename NetFabric.Hyperlinq/Projection/Select/{ => Select}/Select.ReadOnlySpan.cs (100%) rename NetFabric.Hyperlinq/Projection/Select/{ => Select}/Select.Span.cs (100%) rename NetFabric.Hyperlinq/Projection/Select/{ => Select}/Select.ValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Projection/Select/{ => Select}/Select.ValueReadOnlyCollection.cs (100%) rename NetFabric.Hyperlinq/Projection/Select/{ => Select}/SelectEnumerator.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectAt/SelectAt.ArraySegment.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectAt/SelectAt.AsyncValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectAt/SelectAt.ReadOnlyList.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectAt/SelectAt.ReadOnlyMemory.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectAt/SelectAt.ReadOnlySpan.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectAt/SelectAt.Span.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectAt/SelectAt.ValueEnumerable.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectAt/SelectAt.ValueReadOnlyCollection.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectAt/SelectAtEnumerator.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectVector/SelectVector.ArraySegment.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectVector/SelectVector.Memory.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectVector/SelectVector.Range.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectVector/SelectVector.ReadOnlyMemory.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectVector/SelectVector.ReadOnlySpan.cs (100%) rename NetFabric.Hyperlinq/Projection/{ => Select}/SelectVector/SelectVector.Span.cs (100%) delete mode 100644 NetFabric.Hyperlinq/Projection/SelectAtRef/SelectAtRef.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq/Projection/SelectAtRef/SelectAtRefEnumerator.cs rename NetFabric.Hyperlinq/Projection/SelectMany/{ => SelectMany}/SelectMany.ArraySegment.cs (100%) rename NetFabric.Hyperlinq/Projection/SelectMany/{ => SelectMany}/SelectMany.ReadOnlyList.cs (100%) rename NetFabric.Hyperlinq/Projection/SelectMany/{ => SelectMany}/SelectMany.ReadOnlyMemory.cs (100%) rename NetFabric.Hyperlinq/Projection/SelectMany/{ => SelectMany}/SelectMany.ValueEnumerable.cs (100%) delete mode 100644 NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ReadOnlyMemory.cs delete mode 100644 NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ReadOnlySpan.cs delete mode 100644 NetFabric.Hyperlinq/Projection/SelectRef/SelectRefEnumerator.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.Memory.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.ReadOnlySpan.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.Span.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/AnyRef/AnyRef.ReadOnlySpan.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/AnyRef/AnyRef.Span.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Array.Tests.cs deleted file mode 100644 index 6588517ea..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Array.Tests.cs +++ /dev/null @@ -1,34 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRef -{ - public class ArrayTests - { -/* - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void WhereRef_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = source.AsValueEnumerableRef() - .Where(function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefReturns: false, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } -*/ - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ArraySegment.Tests.cs deleted file mode 100644 index 0f11e2fd3..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ArraySegment.Tests.cs +++ /dev/null @@ -1,53 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRef -{ - public class ArraySegmentTests - { - [Fact] - public void WhereRef_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - var function = Wrap.AsFunctionIn(_ => true); - var expected = Enumerable.Empty(); - - // Act - var result = ArrayExtensions - .Where(source, function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefReturns: false, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void WhereRef_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(wrapped, predicate); - - // Act - var result = ArrayExtensions - .Where(wrapped, function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefReturns: false, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Memory.Tests.cs deleted file mode 100644 index a0751afc8..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Memory.Tests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRef -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void WhereRef_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = source.AsMemory().AsValueEnumerableRef() - .Where(function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ReadOnlyMemory.Tests.cs deleted file mode 100644 index 840835c76..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRef -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void WhereRef_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ReadOnlySpan.Tests.cs deleted file mode 100644 index dd16d2ff6..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.ReadOnlySpan.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRef -{ - public class ReadOnlySpanTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void WhereRef_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), function); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Span.Tests.cs deleted file mode 100644 index 2afbd42a3..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRef/WhereRef.Span.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRef -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void WhereRef_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), function); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Array.Tests.cs deleted file mode 100644 index 35b8331c4..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Array.Tests.cs +++ /dev/null @@ -1,34 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereAtRef -{ - public class ArrayTests - { -/* - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void WhereAtRef_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = source.AsValueEnumerableRef() - .Where(function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } -*/ - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ArraySegment.Tests.cs deleted file mode 100644 index 2ada0b4e6..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ArraySegment.Tests.cs +++ /dev/null @@ -1,53 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereAtRef -{ - public class ArraySegmentTests - { - [Fact] - public void WhereAtRef_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - var function = Wrap.AsFunctionIn((_, __) => true); - var expected = Enumerable.Empty(); - - // Act - var result = ArrayExtensions - .Where(source, function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void WhereAtRef_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(wrapped, predicate); - - // Act - var result = ArrayExtensions - .Where(wrapped, function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Memory.Tests.cs deleted file mode 100644 index 70438089d..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Memory.Tests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRefIndex -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void WhereAtRef_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = source.AsMemory().AsValueEnumerableRef() - .Where(function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ReadOnlyMemory.Tests.cs deleted file mode 100644 index 27cda9295..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRefIndex -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void WhereAtRef_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), function); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ReadOnlySpan.Tests.cs deleted file mode 100644 index 97143bedf..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.ReadOnlySpan.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRefIndex -{ - public class ReadOnlySpanTests - { - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void WhereAtRef_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), function); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Span.Tests.cs deleted file mode 100644 index 5175bebed..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereRefAt/WhereRefAt.Span.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereRefIndex -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void WhereAtRef_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var function = Wrap.AsFunctionIn(predicate); - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), function); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs index fd75b1be5..d829b51a9 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs @@ -6,11 +6,6 @@ namespace NetFabric.Hyperlinq { public static partial class ReadOnlyListExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this TList source) - where TList : struct, IReadOnlyList - => source.Count(0, source.Count); - [MethodImpl(MethodImplOptions.AggressiveInlining)] static int Count(this TList source, int offset, int count) where TList : struct, IReadOnlyList @@ -30,12 +25,6 @@ static int Count(this TList source, TPredicate predi return counter; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static int CountAt(this TList source, TPredicate predicate) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.CountAt(predicate, 0, source.Count); - static int CountAt(this TList source, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate: struct, IFunction @@ -47,7 +36,7 @@ static int CountAt(this TList source, TPredicate pre for (var index = 0; index < end; index++) { var item = source[index]; - counter += predicate.Invoke(source[index], index).AsByte(); + counter += predicate.Invoke(item, index).AsByte(); } } else diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs index 73da3db62..7dbfd2a38 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs @@ -20,17 +20,6 @@ static int Count(this ReadOnlySpan source, TPredic return counter; } - static int CountRef(this ReadOnlySpan source, TPredicate predicate) - where TPredicate : struct, IFunctionIn - { - var counter = 0; - foreach (ref readonly var item in source) - { - counter += predicate.Invoke(in item).AsByte(); - } - return counter; - } - static int CountAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate: struct, IFunction { @@ -42,18 +31,6 @@ static int CountAt(this ReadOnlySpan source, TPred } return counter; } - - static int CountAtRef(this ReadOnlySpan source, TPredicate predicate) - where TPredicate : struct, IFunctionIn - { - var counter = 0; - for (var index = 0; index < source.Length; index++) - { - ref readonly var item = ref source[index]; - counter += predicate.Invoke(in item, index).AsByte(); - } - return counter; - } } } diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs index 09030dde1..d9386b3ee 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs @@ -41,22 +41,6 @@ static TSum Sum(this TList source, TPredicate return sum; } - static TSum SumRef(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(in item)) - sum = GenericsOperator.AddNullable(item, sum); - } - return sum; - } - static TSum SumAt(this TList source, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction @@ -73,22 +57,6 @@ static TSum SumAt(this TList source, TPredicat return sum; } - static TSum SumAtRef(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(in item, index)) - sum = GenericsOperator.AddNullable(item, sum); - } - return sum; - } - static TSum Sum(this TList source, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction @@ -104,21 +72,6 @@ static TSum Sum(this TList source, TSe return sum; } - static TSum SumRef(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - sum = GenericsOperator.AddNullable(selector.Invoke(in item), sum); - } - return sum; - } - static TSum SumAt(this TList source, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction @@ -134,22 +87,6 @@ static TSum SumAt(this TList source, T return sum; } - static TSum SumAtRef(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - sum = GenericsOperator.AddNullable(selector.Invoke(in item, index), sum); - } - return sum; - } - - static TSum Sum(this TList source, TPredicate predicate, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction @@ -166,23 +103,6 @@ static TSum Sum(this TList } return sum; } - - static TSum SumRef(this TList source, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(in item)) - sum = GenericsOperator.AddNullable(selector.Invoke(in item), sum); - } - return sum; - } } } diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs index 04223d559..11530199d 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs @@ -137,19 +137,6 @@ static TSum Sum(this ReadOnlySpan source, TP return sum; } - static TSum SumRef(this ReadOnlySpan source, TPredicate predicate) - where TPredicate : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - foreach (ref readonly var item in source) - { - if (predicate.Invoke(in item)) - sum = GenericsOperator.AddNullable(item, sum); - } - return sum; - } - static TSum SumAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction where TSum : struct @@ -164,20 +151,6 @@ static TSum SumAt(this ReadOnlySpan source, return sum; } - static TSum SumAtRef(this ReadOnlySpan source, TPredicate predicate) - where TPredicate : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - for (var index = 0; index < source.Length; index++) - { - ref readonly var item = ref source[index]; - if (predicate.Invoke(in item, index)) - sum = GenericsOperator.AddNullable(item, sum); - } - return sum; - } - static TSum Sum(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction where TSum : struct @@ -188,16 +161,6 @@ static TSum Sum(this ReadOnlySpan so return sum; } - static TSum SumRef(this ReadOnlySpan source, TSelector selector) - where TSelector : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - foreach (ref readonly var item in source) - sum = GenericsOperator.AddNullable(selector.Invoke(in item), sum); - return sum; - } - static TSum SumAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction where TSum : struct @@ -210,21 +173,7 @@ static TSum SumAt(this ReadOnlySpan } return sum; } - - static TSum SumAtRef(this ReadOnlySpan source, TSelector selector) - where TSelector : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - for (var index = 0; index < source.Length; index++) - { - ref readonly var item = ref source[index]; - sum = GenericsOperator.AddNullable(selector.Invoke(in item, index), sum); - } - return sum; - } - - + static TSum Sum(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction @@ -238,20 +187,6 @@ static TSum Sum(this ReadOnlySpan } return sum; } - - static TSum SumRef(this ReadOnlySpan source, TPredicate predicate, TSelector selector) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - foreach (ref readonly var item in source) - { - if (predicate.Invoke(in item)) - sum = GenericsOperator.AddNullable(selector.Invoke(in item), sum); - } - return sum; - } } } diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs index 9c14936ba..febb91e25 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs @@ -35,23 +35,6 @@ internal static TSum Sum(th return sum; } - internal static TSum SumRef(this TEnumerable source, TPredicate predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - using var enumerator = source.GetEnumerator(); - while (enumerator.MoveNext()) - { - var item = enumerator.Current; - if (predicate.Invoke(in item)) - sum = GenericsOperator.AddNullable(item, sum); - } - return sum; - } - internal static TSum SumAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -69,23 +52,6 @@ internal static TSum SumAt( return sum; } - internal static TSum SumAtRef(this TEnumerable source, TPredicate predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - using var enumerator = source.GetEnumerator(); - for (var index = 0; enumerator.MoveNext(); index++) - { - var item = enumerator.Current; - if (predicate.Invoke(in item, index)) - sum = GenericsOperator.AddNullable(item, sum); - } - return sum; - } - internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -102,22 +68,6 @@ internal static TSum Sum(this TEnumerable source, TSelector selector) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - using var enumerator = source.GetEnumerator(); - while (enumerator.MoveNext()) - { - var item = enumerator.Current; - sum = GenericsOperator.AddNullable(selector.Invoke(in item), sum); - } - return sum; - } - static TSum SumAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -133,24 +83,7 @@ static TSum SumAt(t } return sum; } - - internal static TSum SumAtRef(this TEnumerable source, TSelector selector) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - using var enumerator = source.GetEnumerator(); - for (var index = 0; enumerator.MoveNext(); index++) - { - var item = enumerator.Current; - sum = GenericsOperator.AddNullable(selector.Invoke(in item, index), sum); - } - return sum; - } - - + internal static TSum Sum(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -168,24 +101,6 @@ internal static TSum Sum(this TEnumerable source, TPredicate predicate, TSelector selector) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - where TSum : struct - { - var sum = default(TSum); - using var enumerator = source.GetEnumerator(); - while (enumerator.MoveNext()) - { - var item = enumerator.Current; - if (predicate.Invoke(in item)) - sum = GenericsOperator.AddNullable(selector.Invoke(in item), sum); - } - return sum; - } } } diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs new file mode 100644 index 000000000..b25ab7ee9 --- /dev/null +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyCollectionExtensions + { + static TSum Sum(this TEnumerable source, TPredicate predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate: struct, IFunction + where TSum : struct + => source switch + { + {Count: 0} => default, + _ => ValueEnumerableExtensions.Sum(source, predicate) + }; + + static TSum SumAt(this TEnumerable source, TPredicate predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate: struct, IFunction + where TSum : struct + => source switch + { + {Count: 0} => default, + _ => ValueEnumerableExtensions.SumAt(source, predicate) + }; + + } +} + diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs index 042036bec..254d1b658 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs @@ -12,9 +12,5 @@ public static class ListBindings [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ArrayExtensions.ArraySegmentValueEnumerable AsValueEnumerable(this List source) => source.AsArraySegment().AsValueEnumerable(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ArrayExtensions.ArraySegmentValueEnumerableRef AsValueEnumerableRef(this List source) - => source.AsArraySegment().AsValueEnumerableRef(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.Array.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.Array.cs deleted file mode 100644 index bedccd1e5..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.Array.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ArraySegmentValueEnumerableRef AsValueEnumerableRef(this TSource[] source) - => new(new ArraySegment(source)); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.ArraySegment.cs deleted file mode 100644 index 0b6bc4f68..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.ArraySegment.cs +++ /dev/null @@ -1,412 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ArraySegmentValueEnumerableRef AsValueEnumerableRef(this ArraySegment source) - => new(source); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ArraySegmentValueEnumerableRef - : IValueReadOnlyList.DisposableEnumerator> - , IList - { - internal readonly ArraySegment source; - - internal ArraySegmentValueEnumerableRef(ArraySegment source) - => this.source = source; - - public readonly int Count - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source.Count; - } - - public readonly ref TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if ((uint)index >= (uint)source.Count) Throw.IndexOutOfRangeException(); - - return ref source.Array![source.Offset + index]; - } - } - TSource IReadOnlyList.this[int index] - => this[index]; - TSource IList.this[int index] - { - get => this[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SpanEnumeratorRef GetEnumerator() - => new(source); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(source); - - - bool ICollection.IsReadOnly - => true; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(Span span) - => source.AsSpan().CopyTo(span); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => Copy(source, array.AsSpan().Slice(arrayIndex)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => ((ICollection)source).Contains(item); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int IndexOf(TSource item) - => ArrayExtensions.IndexOf(source.AsSpan(), item); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly ArraySegment source; - int index; - - internal DisposableEnumerator(ArraySegment source) - { - this.source = source; - index = -1; - } - - public readonly ref TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if ((uint)index >= (uint)source.Count) Throw.IndexOutOfRangeException(); - - return ref source.Array![source.Offset + index]; - } - } - readonly TSource IEnumerator.Current - => this.Current; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => this.Current; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index < source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [ExcludeFromCodeCoverage] - public void Reset() - => index = -1; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly void Dispose() { } - } - - #region Aggregation - - #endregion - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerableRef AsEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerableRef AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TSource[] ToArray() - => source.AsSpan().ToArray(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.AsSpan().ToArray(memoryPool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.AsSpan().ToList(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(FunctionIn keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.AsSpan().ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - => source.AsSpan().ToDictionaryRef(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(FunctionIn keySelector, FunctionIn elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.AsSpan().ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TElementSelector : struct, IFunctionIn - => source.AsSpan().ToDictionaryRef(keySelector, elementSelector, comparer); - - #endregion - - #region Element - - public Option ElementAt(int index) - => source.AsSpan().ElementAt(index); - - public Option First() - => source.AsSpan().First(); - - public Option Single() - => source.AsSpan().Single(); - - #endregion - - #region Filtering - - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentWhereEnumerable> Where(FunctionIn predicate) - // => source.WhereRef(predicate); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentWhereEnumerable Where(TPredicate predicate = default) - // where TPredicate : struct, IFunctionIn - // => source.WhereRef(predicate); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentWhereAtEnumerable> Where(FunctionIn predicate) - // => source.WhereRef(predicate); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentWhereAtEnumerable WhereAt(TPredicate predicate = default) - // where TPredicate : struct, IFunctionIn - // => source.WhereAtRef(predicate); - - #endregion - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerableRef Skip(int count) - { - var (skipCount, takeCount) = Utils.Skip(source.Count, count); - return new ArraySegmentValueEnumerableRef(new ArraySegment(source.Array!, source.Offset + skipCount, takeCount)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerableRef Take(int count) - => new(new ArraySegment(source.Array!, source.Offset, Utils.Take(source.Count, count))); - - #endregion - - #region Projection - - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentSelectEnumerable> Select(FunctionIn selector) - // => source.SelectRef(selector); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentSelectEnumerable Select(TSelector selector = default) - // where TSelector : struct, IFunctionIn - // => source.SelectRef(selector); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentSelectAtEnumerable> Select(FunctionIn selector) - // => source.SelectRef(selector); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentSelectAtEnumerable SelectAt(TSelector selector = default) - // where TSelector : struct, IFunctionIn - // => source.SelectAtRef(selector); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentSelectManyEnumerable> SelectMany(FunctionIn selector) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // => source.SelectManyRef(selector); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ArraySegmentSelectManyEnumerable SelectMany(TSelector selector = default) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // where TSelector : struct, IFunctionIn - // => source.SelectManyRef(selector); - - #endregion - - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(FunctionIn predicate) - => All(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.AsSpan().AllRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(FunctionIn predicate) - => AllAt(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.AsSpan().AllAtRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.AsSpan().Any(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(FunctionIn predicate) - => Any(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.AsSpan().AnyRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(FunctionIn predicate) - => AnyAt(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.AsSpan().AnyAtRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer) - => source.AsSpan().Contains(value, comparer); - - #endregion - - #region Set - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentDistinctEnumerable Distinct(IEqualityComparer? comparer = default) - => source.Distinct(comparer); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentValueEnumerableRef source) - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentValueEnumerableRef source) - => source.source.AsSpan().Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool ContainsVector(this ArraySegmentValueEnumerableRef source, TSource value) - where TSource : struct - => source.source.AsSpan().ContainsVector(value); - - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public static ArraySegmentSelectVectorEnumerable, Vector>, FunctionInWrapper> SelectVector(this ArraySegmentValueEnumerableRef source, FunctionIn, Vector> vectorSelector, FunctionIn selector) - // where TSource : struct - // where TResult : struct - // => source.source.SelectVector(vectorSelector, selector); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public static ArraySegmentSelectVectorEnumerable SelectVector(this ArraySegmentValueEnumerableRef source, TSelector selector = default) - // where TSelector : struct, IFunctionIn, Vector>, IFunctionIn - // where TSource : struct - // where TResult : struct - // => source.source.SelectVector(selector, selector); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public static ArraySegmentSelectVectorEnumerable SelectVector(this ArraySegmentValueEnumerableRef source, TVectorSelector vectorSelector = default, TSelector selector = default) - // where TVectorSelector : struct, IFunctionIn, Vector> - // where TSelector : struct, IFunctionIn - // where TSource : struct - // where TResult : struct - // => source.source.SelectVector(vectorSelector, selector); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.Memory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.Memory.cs deleted file mode 100644 index 1e3c7f5f4..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.Memory.cs +++ /dev/null @@ -1,367 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class MemoryBindings - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerableRef AsValueEnumerableRef(this Memory source) - => new(source); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerableRef - : IValueReadOnlyList.DisposableEnumerator> - , IList - { - internal readonly Memory source; - - internal ValueEnumerableRef(Memory source) - => this.source = source; - - public readonly int Count - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source.Length; - } - - public readonly ref TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source.Span[index]; - } - TSource IReadOnlyList.this[int index] - => source.Span[index]; - TSource IList.this[int index] - { - get => source.Span[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SpanEnumeratorRef GetEnumerator() - => new(source.Span); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(source); - - - bool ICollection.IsReadOnly - => true; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(Span span) - => source.Span.CopyTo(span); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan(arrayIndex)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - bool ICollection.Contains(TSource item) - => source.Span.Contains(item); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int IndexOf(TSource item) - => ArrayExtensions.IndexOf(source.Span, item); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly Memory source; - int index; - - internal DisposableEnumerator(Memory source) - { - this.source = source; - index = -1; - } - - public readonly ref TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source.Span[index]; - } - readonly TSource IEnumerator.Current - => source.Span[index]; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source.Span[index]; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index < source.Length; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [ExcludeFromCodeCoverage] - public void Reset() - => index = -1; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly void Dispose() { } - } - - #region Aggregation - - #endregion - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableRef AsEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableRef AsValueEnumerableRef() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Memory ToArray() - => source.Span.ToArray(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.Span.ToArray(memoryPool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.Span.ToList(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(FunctionIn keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.Span.ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - => source.Span.ToDictionaryRef(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(FunctionIn keySelector, FunctionIn elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.Span.ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TElementSelector : struct, IFunctionIn - => source.Span.ToDictionaryRef(keySelector, elementSelector, comparer); - - #endregion - - #region Element - - public Option ElementAt(int index) - => source.Span.ElementAt(index); - - public Option First() - => source.Span.First(); - - public Option Single() - => source.Span.Single(); - - #endregion - - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArrayExtensions.MemoryWhereRefEnumerable> Where(FunctionIn predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArrayExtensions.MemoryWhereRefEnumerable Where(TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => source.WhereRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArrayExtensions.MemoryWhereAtRefEnumerable> Where(FunctionIn predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArrayExtensions.MemoryWhereAtRefEnumerable WhereAt(TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => source.WhereAtRef(predicate); - - #endregion - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Memory Skip(int count) - => source.Skip(count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Memory Take(int count) - => source.Take(count); - - #endregion - - #region Projection - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectRefEnumerable> Select(FunctionIn selector) - // => source.Select(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectRefEnumerable Select(TSelector selector = default) - // where TSelector : struct, IFunctionIn - // => source.SelectRef(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectAtRefEnumerable> Select(FunctionIn selector) - // => source.Select(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectAtRefEnumerable SelectAt(TSelector selector = default) - // where TSelector : struct, IFunctionIn - // => source.SelectAtRef(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectManyRefEnumerable> SelectMany(FunctionIn selector) - // where TSubEnumerable : IValueEnumerableRef - // where TSubEnumerator : struct, IEnumerator - // => source.SelectMany(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectManyRefEnumerable SelectMany(TSelector selector = default) - // where TSubEnumerable : IValueEnumerableRef - // where TSubEnumerator : struct, IEnumerator - // where TSelector : struct, IFunctionIn - // => source.SelectManyRef(selector); - - #endregion - - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(FunctionIn predicate) - => source.Span.All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.Span.AllRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(FunctionIn predicate) - => source.Span.All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.Span.AllAtRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.Span.Any(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(FunctionIn predicate) - => source.Span.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.Span.AnyRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(FunctionIn predicate) - => source.Span.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.Span.AnyAtRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer = null) - => source.Span.Contains(value, comparer); - - #endregion - - #region Set - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArrayExtensions.MemoryDistinctEnumerable Distinct(IEqualityComparer? comparer = default) - => ((ReadOnlyMemory)source).Distinct(comparer); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.ReadOnlyMemory.cs deleted file mode 100644 index 7df64e2f5..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/AsValueEnumerableRef.ReadOnlyMemory.cs +++ /dev/null @@ -1,367 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ReadOnlyMemoryBindings - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerableRef AsValueEnumerableRef(this ReadOnlyMemory source) - => new(source); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerableRef - : IValueReadOnlyList.DisposableEnumerator> - , IList - { - internal readonly ReadOnlyMemory source; - - internal ValueEnumerableRef(ReadOnlyMemory source) - => this.source = source; - - public readonly int Count - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source.Length; - } - - public readonly ref readonly TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source.Span[index]; - } - TSource IReadOnlyList.this[int index] - => source.Span[index]; - TSource IList.this[int index] - { - get => source.Span[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlySpanEnumeratorRef GetEnumerator() - => new(source.Span); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(source); - - - bool ICollection.IsReadOnly - => true; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(Span span) - => source.Span.CopyTo(span); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan(arrayIndex)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - bool ICollection.Contains(TSource item) - => source.Span.Contains(item); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int IndexOf(TSource item) - => ArrayExtensions.IndexOf(source.Span, item); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly ReadOnlyMemory source; - int index; - - internal DisposableEnumerator(ReadOnlyMemory source) - { - this.source = source; - index = -1; - } - - public readonly ref readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source.Span[index]; - } - readonly TSource IEnumerator.Current - => source.Span[index]; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source.Span[index]; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index < source.Length; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [ExcludeFromCodeCoverage] - public void Reset() - => index = -1; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly void Dispose() { } - } - - #region Aggregation - - #endregion - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableRef AsEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableRef AsValueEnumerableRef() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyMemory ToArray() - => source.Span.ToArray(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.Span.ToArray(memoryPool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.Span.ToList(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(FunctionIn keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.Span.ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - => source.Span.ToDictionaryRef(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(FunctionIn keySelector, FunctionIn elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.Span.ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TElementSelector : struct, IFunctionIn - => source.Span.ToDictionaryRef(keySelector, elementSelector, comparer); - - #endregion - - #region Element - - public Option ElementAt(int index) - => source.Span.ElementAt(index); - - public Option First() - => source.Span.First(); - - public Option Single() - => source.Span.Single(); - - #endregion - - #region Filtering - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemoryWhereRefEnumerable> Where(FunctionIn predicate) - // => source.Where(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemoryWhereRefEnumerable Where(TPredicate predicate = default) - // where TPredicate : struct, IFunctionIn - // => source.WhereRef(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemoryWhereAtRefEnumerable> Where(FunctionIn predicate) - // => source.Where(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemoryWhereAtRefEnumerable WhereAt(TPredicate predicate = default) - // where TPredicate : struct, IFunctionIn - // => source.WhereAtRef(predicate); - - #endregion - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyMemory Skip(int count) - => source.Skip(count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyMemory Take(int count) - => source.Take(count); - - #endregion - - #region Projection - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectRefEnumerable> Select(FunctionIn selector) - // => source.Select(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectRefEnumerable Select(TSelector selector = default) - // where TSelector : struct, IFunctionIn - // => source.SelectRef(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectAtRefEnumerable> Select(FunctionIn selector) - // => source.Select(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectAtRefEnumerable SelectAt(TSelector selector = default) - // where TSelector : struct, IFunctionIn - // => source.SelectAtRef(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectManyRefEnumerable> SelectMany(FunctionIn selector) - // where TSubEnumerable : IValueEnumerableRef - // where TSubEnumerator : struct, IEnumerator - // => source.SelectMany(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArrayExtensions.MemorySelectManyRefEnumerable SelectMany(TSelector selector = default) - // where TSubEnumerable : IValueEnumerableRef - // where TSubEnumerator : struct, IEnumerator - // where TSelector : struct, IFunctionIn - // => source.SelectManyRef(selector); - - #endregion - - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(FunctionIn predicate) - => source.Span.All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.Span.AllRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(FunctionIn predicate) - => source.Span.All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.Span.AllAtRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.Span.Any(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(FunctionIn predicate) - => source.Span.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.Span.AnyRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(FunctionIn predicate) - => source.Span.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source.Span.AnyAtRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer = null) - => source.Span.Contains(value, comparer); - - #endregion - - #region Set - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArrayExtensions.MemoryDistinctEnumerable Distinct(IEqualityComparer? comparer = default) - => source.Distinct(comparer); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerableRef source) - => source.source.Span.Sum(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/ReadOnlySpanEnumeratorRef.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/ReadOnlySpanEnumeratorRef.cs deleted file mode 100644 index cd67ad41a..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/ReadOnlySpanEnumeratorRef.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct ReadOnlySpanEnumeratorRef - { - readonly ReadOnlySpan source; - int index; - - internal ReadOnlySpanEnumeratorRef(ReadOnlySpan source) - { - this.source = source; - index = -1; - } - - public readonly ref readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index < source.Length; - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/SpanEnumeratorRef.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/SpanEnumeratorRef.cs deleted file mode 100644 index a0d6efa89..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerableRef/SpanEnumeratorRef.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct SpanEnumeratorRef - { - readonly Span source; - int index; - - internal SpanEnumeratorRef(Span source) - { - this.source = source; - index = -1; - } - - public readonly ref TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index < source.Length; - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index bcee2ac54..bcb11041b 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -45,23 +45,6 @@ static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TSource[] ToArrayRef(this ReadOnlySpan source, TPredicate predicate) - where TPredicate : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, predicate) - }; - - static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) - { - using var arrayBuilder = ToArrayBuilderRef(source, predicate, ArrayPool.Shared); - return arrayBuilder.ToArray(); - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] static IMemoryOwner ToArray(this ReadOnlySpan source, TPredicate predicate, MemoryPool pool) where TPredicate : struct, IFunction @@ -79,23 +62,6 @@ static IMemoryOwner BuildArray(ReadOnlySpan source, TPredicate } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayRef(this ReadOnlySpan source, TPredicate predicate, MemoryPool pool) - where TPredicate : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, predicate, pool) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, TPredicate predicate, MemoryPool pool) - { - using var arrayBuilder = ToArrayBuilderRef(source, predicate, ArrayPool.Shared); - return arrayBuilder.ToArray(pool); - } - } - ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -116,23 +82,6 @@ static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TSource[] ToArrayAtRef(this ReadOnlySpan source, TPredicate predicate) - where TPredicate : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, predicate) - }; - - static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) - { - using var arrayBuilder = ToArrayBuilderAtRef(source, predicate, ArrayPool.Shared); - return arrayBuilder.ToArray(); - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] static IMemoryOwner ToArrayAt(this ReadOnlySpan source, TPredicate predicate, MemoryPool pool) where TPredicate : struct, IFunction @@ -150,23 +99,6 @@ static IMemoryOwner BuildArray(ReadOnlySpan source, TPredicate } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAtRef(this ReadOnlySpan source, TPredicate predicate, MemoryPool pool) - where TPredicate : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, predicate, pool) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, TPredicate predicate, MemoryPool pool) - { - using var arrayBuilder = ToArrayBuilderAtRef(source, predicate, ArrayPool.Shared); - return arrayBuilder.ToArray(pool); - } - } - ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -230,24 +162,6 @@ static IMemoryOwner BuildArray(ReadOnlySpan source, TVectorSel } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TResult[] ToArrayRef(this ReadOnlySpan source, TSelector selector) - where TSelector : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, selector) - }; - - static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) - { - var result = Utils.AllocateUninitializedArray(source.Length); - CopyRef(source, result.AsSpan(), selector); - return result; - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] static IMemoryOwner ToArray(this ReadOnlySpan source, TSelector selector, MemoryPool pool) where TSelector : struct, IFunction @@ -266,24 +180,6 @@ static IMemoryOwner BuildArray(ReadOnlySpan source, TSelector } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayRef(this ReadOnlySpan source, TSelector selector, MemoryPool pool) - where TSelector : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, selector, pool) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, TSelector selector, MemoryPool pool) - { - var result = pool.RentSliced(source.Length); - CopyRef(source, result.Memory.Span, selector); - return result; - } - } - ////////////////////////////////////////////////////////////////////////////////////////////////// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -304,24 +200,6 @@ static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TResult[] ToArrayAtRef(this ReadOnlySpan source, TSelector selector) - where TSelector : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, selector) - }; - - static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) - { - var result = Utils.AllocateUninitializedArray(source.Length); - CopyAtRef(source, result.AsSpan(), selector); - return result; - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] static IMemoryOwner ToArrayAt(this ReadOnlySpan source, TSelector selector, MemoryPool pool) where TSelector : struct, IFunction @@ -340,24 +218,6 @@ static IMemoryOwner BuildArray(ReadOnlySpan source, TSelector } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAtRef(this ReadOnlySpan source, TSelector selector, MemoryPool pool) - where TSelector : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, selector, pool) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, TSelector selector, MemoryPool pool) - { - var result = pool.RentSliced(source.Length); - CopyAtRef(source, result.Memory.Span, selector); - return result; - } - } - ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -379,24 +239,6 @@ static TResult[] BuildArray(ReadOnlySpan source, TPredicate predicate, } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TResult[] ToArrayRef(this ReadOnlySpan source, TPredicate predicate, TSelector selector) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, predicate, selector) - }; - - static TResult[] BuildArray(ReadOnlySpan source, TPredicate predicate, TSelector selector) - { - using var arrayBuilder = ToArrayBuilderRef(source, predicate, selector, ArrayPool.Shared); - return arrayBuilder.ToArray(); - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] static IMemoryOwner ToArray(this ReadOnlySpan source, TPredicate predicate, TSelector selector, MemoryPool pool) where TPredicate : struct, IFunction @@ -414,24 +256,6 @@ static IMemoryOwner BuildArray(ReadOnlySpan source, TPredicate return arrayBuilder.ToArray(pool); } } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayRef(this ReadOnlySpan source, TPredicate predicate, TSelector selector, MemoryPool pool) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, predicate, selector, pool) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, TPredicate predicate, TSelector selector, MemoryPool pool) - { - using var arrayBuilder = ToArrayBuilderRef(source, predicate, selector, ArrayPool.Shared); - return arrayBuilder.ToArray(pool); - } - } } } diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs index 3c5c28376..9c195512f 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs @@ -22,22 +22,6 @@ public static Dictionary ToDictionary ToDictionary(this ReadOnlySpan source, FunctionIn keySelector, IEqualityComparer? comparer = null) - where TKey : notnull - => source.ToDictionaryRef(new FunctionInWrapper(keySelector), comparer); - - public static Dictionary ToDictionaryRef(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer = null) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Length, comparer); - foreach (ref readonly var item in source) - dictionary.Add(keySelector.Invoke(in item), item); - return dictionary; - } - static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TKey : notnull where TKeySelector : struct, IFunction @@ -53,21 +37,6 @@ static Dictionary ToDictionary ToDictionaryRef(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TPredicate : struct, IFunctionIn - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Length, comparer); - foreach (ref readonly var item in source) - { - if (predicate.Invoke(in item)) - dictionary.Add(keySelector.Invoke(in item), item); - } - return dictionary; - } - static Dictionary ToDictionaryAt(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TKey : notnull where TKeySelector : struct, IFunction @@ -84,22 +53,6 @@ static Dictionary ToDictionaryAt ToDictionaryAtRef(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TPredicate : struct, IFunctionIn - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Length, comparer); - for (var index = 0; index < source.Length; index++) - { - ref readonly var item = ref source[index]; - if (predicate.Invoke(in item, index)) - dictionary.Add(keySelector.Invoke(in item), item); - } - return dictionary; - } - static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TKey : notnull where TKeySelector : struct, IFunction @@ -119,25 +72,6 @@ static Dictionary ToDictionary ToDictionaryRef(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Length, comparer); - foreach (ref readonly var item in source) - { - if (predicate.Invoke(in item)) - { - var result = selector.Invoke(in item); - dictionary.Add(keySelector.Invoke(in result), result); - } - } - return dictionary; - } - ////////////////////////////////////////////////////////////////////////////////////////////////// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -157,23 +91,6 @@ public static Dictionary ToDictionary ToDictionary(this ReadOnlySpan source, FunctionIn keySelector, FunctionIn elementSelector, IEqualityComparer? comparer = null) - where TKey : notnull - => source.ToDictionaryRef, FunctionInWrapper>(new FunctionInWrapper(keySelector), new FunctionInWrapper(elementSelector), comparer); - - public static Dictionary ToDictionaryRef(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = null) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TElementSelector : struct, IFunctionIn - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Length, comparer); - foreach (ref readonly var item in source) - dictionary.Add(keySelector.Invoke(in item), elementSelector.Invoke(in item)); - return dictionary; - } - static Dictionary ToDictionary( this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, @@ -192,26 +109,7 @@ static Dictionary } return dictionary; } - - static Dictionary - ToDictionaryRef( - this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, - IEqualityComparer? comparer, TPredicate predicate) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TElementSelector : struct, IFunctionIn - where TPredicate : struct, IFunctionIn - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Length, comparer); - foreach (ref readonly var item in source) - { - if (predicate.Invoke(in item)) - dictionary.Add(keySelector.Invoke(in item), elementSelector.Invoke(in item)); - } - return dictionary; - } - + static Dictionary ToDictionaryAt( this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, @@ -233,27 +131,6 @@ static Dictionary return dictionary; } - static Dictionary - ToDictionaryAtRef( - this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, - IEqualityComparer? comparer, TPredicate predicate) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TElementSelector : struct, IFunctionIn - where TPredicate : struct, IFunctionIn - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Length, comparer); - for (var index = 0; index < source.Length; index++) - { - ref readonly var item = ref source[index]; - if (predicate.Invoke(in item, index)) - dictionary.Add(keySelector.Invoke(in item), elementSelector.Invoke(in item)); - } - - return dictionary; - } - static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TKey : notnull where TKeySelector : struct, IFunction @@ -274,27 +151,6 @@ static Dictionary ToDictionary ToDictionaryRef(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TElementSelector : struct, IFunctionIn - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Length, comparer); - foreach (var item in source) - { - if (predicate.Invoke(in item)) - { - var result = selector.Invoke(in item); - dictionary.Add(keySelector.Invoke(in result), elementSelector.Invoke(in result)); - } - } - - return dictionary; - } } } diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.Span.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.Span.cs index bf4958bcc..adf7d9a86 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.Span.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.Span.cs @@ -17,17 +17,6 @@ public static Dictionary ToDictionary => ((ReadOnlySpan)source).ToDictionary(keySelector, comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this Span source, FunctionIn keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ((ReadOnlySpan)source).ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionaryRef(this Span source, TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - => ((ReadOnlySpan)source).ToDictionaryRef(keySelector, comparer); - ////////////////////////////////////////////////////////////////////////////////////////////////// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -41,18 +30,6 @@ public static Dictionary ToDictionary where TElementSelector : struct, IFunction => ((ReadOnlySpan)source).ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this Span source, FunctionIn keySelector, FunctionIn elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ((ReadOnlySpan)source).ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionaryRef(this Span source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunctionIn - where TElementSelector : struct, IFunctionIn - => ((ReadOnlySpan)source).ToDictionaryRef(keySelector, elementSelector, comparer); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs index 49eb5d75d..df32dcba2 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs @@ -27,15 +27,6 @@ static List ToList(this ReadOnlySpan sour _ => source.ToArray(predicate).AsList() }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToListRef(this ReadOnlySpan source, TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArrayRef(predicate).AsList() - }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction @@ -45,15 +36,6 @@ static List ToListAt(this ReadOnlySpan so _ => source.ToArrayAt(predicate).AsList() }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToListAtRef(this ReadOnlySpan source, TPredicate predicate) - where TPredicate : struct, IFunctionIn - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArrayAtRef(predicate).AsList() - }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -75,15 +57,6 @@ static List ToListVector( _ => source.ToArrayVector(vectorSelector, selector).AsList() }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToListRef(this ReadOnlySpan source, TSelector selector) - where TSelector : struct, IFunctionIn - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArrayRef(selector).AsList() - }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -93,15 +66,6 @@ static List ToListAt(this ReadOnlySpan source.ToArrayAt(selector).AsList() }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToListAtRef(this ReadOnlySpan source, TSelector selector) - where TSelector : struct, IFunctionIn - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArrayAtRef(selector).AsList() - }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction @@ -111,15 +75,5 @@ static List ToList(this ReadOn { Length: 0 } => new List(), _ => source.ToArray(predicate, selector).AsList() }; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToListRef(this ReadOnlySpan source, TPredicate predicate, TSelector selector) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArrayRef(predicate, selector).AsList() - }; } } diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs index a1e77817a..128f93162 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs @@ -34,8 +34,7 @@ static Option ElementAt(this TList source, } return Option.None; } - - + static Option ElementAtAt(this TList source, int index, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction @@ -63,7 +62,6 @@ static Option ElementAtAt(this TList source } return Option.None; } - static Option ElementAt(this TList source, int index, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList @@ -72,7 +70,7 @@ static Option ElementAt(this TList ? Option.None : Option.Some(selector.Invoke(source[index + offset])); - + static Option ElementAtAt(this TList source, int index, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction @@ -80,7 +78,6 @@ static Option ElementAtAt(this TLis ? Option.None : Option.Some(selector.Invoke(source[index + offset], index)); - static Option ElementAt(this TList source, int index, TPredicate predicate, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs similarity index 99% rename from NetFabric.Hyperlinq/Filtering/Where/Where.ArraySegment.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index 1f40a70ee..f68cf0e39 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -155,7 +155,7 @@ public ArraySegmentWhereEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ArraySegmentWhereAtEnumerable> WhereAt(TPredicate2 predicate = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/Where.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/Where.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/Where.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/Where.ReadOnlySpan.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where.Span.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.Span.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/Where.Span.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/Where.Span.cs diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/Where.ValueEnumerable.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/Where.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereEnumerator.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/WhereEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/WhereEnumerator.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/WhereEnumerator.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ArraySegment.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ReadOnlySpan.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.Span.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.Span.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.Span.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.Span.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ValueEnumerable.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAt/WhereAtEnumerator.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAtEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereAt/WhereAtEnumerator.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAtEnumerator.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtReadOnlyRefEnumerator.cs b/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtReadOnlyRefEnumerator.cs deleted file mode 100644 index 49c89b6e1..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtReadOnlyRefEnumerator.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct WhereAtReadOnlyRefEnumerator - where TPredicate : struct, IFunctionIn - { - readonly ReadOnlySpan source; - TPredicate predicate; - int index; - - internal WhereAtReadOnlyRefEnumerator(ReadOnlySpan source, TPredicate predicate) - { - this.source = source; - this.predicate = predicate; - index = -1; - } - - public readonly ref readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - var span = source; - while (++index < span.Length) - { - if (predicate.Invoke(in span[index], index)) - return true; - } - return false; - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ArraySegment.cs deleted file mode 100644 index 42ebd0cfe..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ArraySegment.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereAtRefEnumerable> Where(this in ArraySegment source, FunctionIn predicate) - => source.WhereAtRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereAtRefEnumerable WhereAtRef(this in ArraySegment source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly struct ArraySegmentWhereAtRefEnumerable - where TPredicate : struct, IFunctionIn - { - internal readonly ArraySegment source; - internal readonly TPredicate predicate; - - internal ArraySegmentWhereAtRefEnumerable(in ArraySegment source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public readonly WhereAtRefEnumerator GetEnumerator() - => new(source.AsSpan(), predicate); - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.Memory.cs b/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.Memory.cs deleted file mode 100644 index 63048db57..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.Memory.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemoryWhereAtRefEnumerable> Where(this Memory source, FunctionIn predicate) - => source.WhereAtRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemoryWhereAtRefEnumerable WhereAtRef(this Memory source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly struct MemoryWhereAtRefEnumerable - where TPredicate : struct, IFunctionIn - { - readonly Memory source; - readonly TPredicate predicate; - - internal MemoryWhereAtRefEnumerable(Memory source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public readonly WhereAtRefEnumerator GetEnumerator() - => new (source.Span, predicate); - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - } -} diff --git a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ReadOnlyMemory.cs deleted file mode 100644 index 508400801..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ReadOnlyMemory.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ReadOnlyMemoryWhereAtRefEnumerable> Where(this ReadOnlyMemory source, FunctionIn predicate) - => source.WhereAtRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ReadOnlyMemoryWhereAtRefEnumerable WhereAtRef(this ReadOnlyMemory source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly struct ReadOnlyMemoryWhereAtRefEnumerable - where TPredicate : struct, IFunctionIn - { - internal readonly ReadOnlyMemory source; - internal readonly TPredicate predicate; - - internal ReadOnlyMemoryWhereAtRefEnumerable(ReadOnlyMemory source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public readonly WhereAtReadOnlyRefEnumerator GetEnumerator() - => new (source.Span, predicate); - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlyMemoryWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumAtRef(source.predicate); - } -} diff --git a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ReadOnlySpan.cs deleted file mode 100644 index 062441541..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.ReadOnlySpan.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpanWhereAtRefEnumerable> Where(this ReadOnlySpan source, FunctionIn predicate) - => source.WhereAtRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpanWhereAtRefEnumerable WhereAtRef(this ReadOnlySpan source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly ref struct ReadOnlySpanWhereAtRefEnumerable - where TPredicate : struct, IFunctionIn - { - internal readonly ReadOnlySpan source; - internal readonly TPredicate predicate; - - internal ReadOnlySpanWhereAtRefEnumerable(ReadOnlySpan source, TPredicate predicate) - { - this.source = source; - this.predicate = predicate; - } - - public readonly WhereAtReadOnlyRefEnumerator GetEnumerator() - => new (source, predicate); - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlySpanWhereAtRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumAtRef(source.predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.Span.cs b/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.Span.cs deleted file mode 100644 index 22b8dce8c..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRef.Span.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereAtRefEnumerable> Where(this Span source, FunctionIn predicate) - => source.WhereAtRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereAtRefEnumerable WhereAtRef(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly ref struct SpanWhereAtRefEnumerable - where TPredicate : struct, IFunctionIn - { - readonly Span source; - readonly TPredicate predicate; - - internal SpanWhereAtRefEnumerable(Span source, TPredicate predicate) - { - this.source = source; - this.predicate = predicate; - } - - public readonly WhereAtRefEnumerator GetEnumerator() - => new(source, predicate); - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRefEnumerator.cs b/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRefEnumerator.cs deleted file mode 100644 index ff6c12895..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereAtRef/WhereAtRefEnumerator.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct WhereAtRefEnumerator - where TPredicate : struct, IFunctionIn - { - readonly Span source; - TPredicate predicate; - int index; - - internal WhereAtRefEnumerator(Span source, TPredicate predicate) - { - this.source = source; - this.predicate = predicate; - index = -1; - } - - public readonly ref TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - var span = source; - while (++index < span.Length) - { - ref readonly var item = ref span[index]; - if (predicate.Invoke(in item, index)) - return true; - } - return false; - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereReadOnlyRefEnumerator.cs b/NetFabric.Hyperlinq/Filtering/WhereRef/WhereReadOnlyRefEnumerator.cs deleted file mode 100644 index 0e6312eec..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereReadOnlyRefEnumerator.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct WhereReadOnlyRefEnumerator - where TPredicate : struct, IFunctionIn - { - readonly ReadOnlySpan source; - TPredicate predicate; - int index; - - internal WhereReadOnlyRefEnumerator(ReadOnlySpan source, TPredicate predicate) - { - this.source = source; - this.predicate = predicate; - index = -1; - } - - public readonly ref readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - var span = source; - while (++index < span.Length) - { - if (predicate.Invoke(in span[index])) - return true; - } - return false; - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ArraySegment.cs deleted file mode 100644 index b3c62cbd6..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ArraySegment.cs +++ /dev/null @@ -1,219 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereRefEnumerable> Where(this in ArraySegment source, FunctionIn predicate) - => source.WhereRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereRefEnumerable WhereRef(this in ArraySegment source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly struct ArraySegmentWhereRefEnumerable - where TPredicate : struct, IFunctionIn - { - internal readonly ArraySegment source; - internal readonly TPredicate predicate; - - internal ArraySegmentWhereRefEnumerable(in ArraySegment source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public readonly WhereRefEnumerator GetEnumerator() - => new(source.AsSpan(), predicate); - - #region Aggregation - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count() - => ((ReadOnlySpan)source.AsSpan()).CountRef(predicate); - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All() - => ((ReadOnlySpan)source.AsSpan()).AllRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(FunctionIn predicate) - => All(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) - where TPredicate2 : struct, IFunctionIn - => ((ReadOnlySpan)source.AsSpan()).AllRef(new PredicatePredicateCombinationIn(this.predicate, predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(FunctionIn predicate) - => AllAt(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) - where TPredicate2 : struct, IFunctionIn - => ((ReadOnlySpan)source.AsSpan()).AllAtRef(new PredicatePredicateAtCombinationIn(this.predicate, predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => ((ReadOnlySpan)source.AsSpan()).AnyRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(FunctionIn predicate) - => Any(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) - where TPredicate2 : struct, IFunctionIn - => ((ReadOnlySpan)source.AsSpan()).AnyRef(new PredicatePredicateCombinationIn(this.predicate, predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(FunctionIn predicate) - => AnyAt(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) - where TPredicate2 : struct, IFunctionIn - => ((ReadOnlySpan)source.AsSpan()).AnyAtRef(new PredicatePredicateAtCombinationIn(this.predicate, predicate)); - - #endregion - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereRefEnumerable, TSource>> Where(FunctionIn predicate) - => WhereRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereRefEnumerable> WhereRef(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunctionIn - => source.WhereRef(new PredicatePredicateCombinationIn(this.predicate, predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereAtRefEnumerable, TSource>> Where(FunctionIn predicate) - => WhereAtRef>(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereAtRefEnumerable> WhereAtRef(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunctionIn - => source.WhereAtRef(new PredicatePredicateAtCombinationIn(this.predicate, predicate)); - - #endregion - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereSelectRefEnumerable> Select(FunctionIn selector) - => Select>(new FunctionInWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereSelectRefEnumerable Select(TSelector selector = default) - where TSelector : struct, IFunctionIn - => source.WhereSelectRef(predicate, selector); - - #endregion - - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.Memory.cs b/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.Memory.cs deleted file mode 100644 index 0ebc75733..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.Memory.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemoryWhereRefEnumerable> Where(this Memory source, FunctionIn predicate) - => source.WhereRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemoryWhereRefEnumerable WhereRef(this Memory source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly struct MemoryWhereRefEnumerable - where TPredicate : struct, IFunctionIn - { - readonly Memory source; - readonly TPredicate predicate; - - internal MemoryWhereRefEnumerable(Memory source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public readonly WhereRefEnumerator GetEnumerator() - => new(source.Span, predicate); - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ReadOnlyMemory.cs deleted file mode 100644 index 5445d0bc1..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ReadOnlyMemory.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ReadOnlyMemoryWhereRefEnumerable> Where(this ReadOnlyMemory source, FunctionIn predicate) - => source.WhereRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ReadOnlyMemoryWhereRefEnumerable WhereRef(this ReadOnlyMemory source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly struct ReadOnlyMemoryWhereRefEnumerable - where TPredicate : struct, IFunctionIn - { - internal readonly ReadOnlyMemory source; - internal readonly TPredicate predicate; - - internal ReadOnlyMemoryWhereRefEnumerable(ReadOnlyMemory source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public readonly WhereReadOnlyRefEnumerator GetEnumerator() - => new(source.Span, predicate); - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlyMemoryWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.Span.SumRef(source.predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ReadOnlySpan.cs deleted file mode 100644 index 7bd92968b..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.ReadOnlySpan.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpanWhereRefEnumerable> Where(this ReadOnlySpan source, FunctionIn predicate) - => source.WhereRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpanWhereRefEnumerable WhereRef(this ReadOnlySpan source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly ref struct ReadOnlySpanWhereRefEnumerable - where TPredicate : struct, IFunctionIn - { - internal readonly ReadOnlySpan source; - internal readonly TPredicate predicate; - - internal ReadOnlySpanWhereRefEnumerable(ReadOnlySpan source, TPredicate predicate) - { - this.source = source; - this.predicate = predicate; - } - - public readonly WhereReadOnlyRefEnumerator GetEnumerator() - => new(source, predicate); - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlySpanWhereRefEnumerable source) - where TPredicate : struct, IFunctionIn - => source.source.SumRef(source.predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.Span.cs b/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.Span.cs deleted file mode 100644 index f3abddba9..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRef.Span.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionInWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereRefEnumerable> Where(this Span source, FunctionIn predicate) - => source.WhereRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereRefEnumerable WhereRef(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => new(source, predicate); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly ref struct SpanWhereRefEnumerable - where TPredicate : struct, IFunctionIn - { - readonly Span source; - readonly TPredicate predicate; - - internal SpanWhereRefEnumerable(Span source, TPredicate predicate) - { - this.source = source; - this.predicate = predicate; - } - - public readonly WhereRefEnumerator GetEnumerator() - => new (source, predicate); - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - if (Utils.UseDefault(comparer)) - { - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!EqualityComparer.Default.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - else - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - } - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRefEnumerator.cs b/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRefEnumerator.cs deleted file mode 100644 index c983219ba..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereRef/WhereRefEnumerator.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct WhereRefEnumerator - where TPredicate : struct, IFunctionIn - { - readonly Span source; - TPredicate predicate; - int index; - - internal WhereRefEnumerator(Span source, TPredicate predicate) - { - this.source = source; - this.predicate = predicate; - index = -1; - } - - public readonly ref TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => ref source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - var span = source; - while (++index < span.Length) - { - ref readonly var item = ref span[index]; - if (predicate.Invoke(in item)) - return true; - } - return false; - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ArraySegment.cs rename to NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.cs rename to NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ValueEnumerable.cs rename to NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelectEnumerator.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelectEnumerator.cs rename to NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectReadOnlyRefEnumerator.cs b/NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectReadOnlyRefEnumerator.cs deleted file mode 100644 index 6117d3786..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectReadOnlyRefEnumerator.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct WhereSelectReadOnlyRefEnumerator - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunction - { - readonly ReadOnlySpan source; - TPredicate predicate; - TSelector selector; - int index; - - internal WhereSelectReadOnlyRefEnumerator(ReadOnlySpan source, TPredicate predicate, TSelector selector) - { - this.source = source; - this.predicate = predicate; - this.selector = selector; - index = -1; - } - - public readonly TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(source[index]); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - var span = source; - while (++index < span.Length) - { - if (predicate.Invoke(in span[index])) - return true; - } - return false; - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectRef.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectRef.ArraySegment.cs deleted file mode 100644 index 8bfde6acc..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectRef.ArraySegment.cs +++ /dev/null @@ -1,312 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereSelectRefEnumerable WhereSelectRef( - this ArraySegment source, - TPredicate predicate, - TSelector selector) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => new(source, predicate, selector); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ArraySegmentWhereSelectRefEnumerable - : IValueEnumerable.Enumerator> - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - { - internal readonly ArraySegment source; - internal readonly TPredicate predicate; - internal readonly TSelector selector; - - internal ArraySegmentWhereSelectRefEnumerable(ArraySegment source, TPredicate predicate, TSelector selector) - => (this.source, this.predicate, this.selector) = (source, predicate, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereSelectRefEnumerator GetEnumerator() - => new(source.AsSpan(), predicate, selector); - readonly Enumerator IValueEnumerable.GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - : IEnumerator - { - readonly TSource[]? source; - TPredicate predicate; - TSelector selector; - readonly int end; - int index; - - internal Enumerator(in ArraySegmentWhereSelectRefEnumerable enumerable) - { - source = enumerable.source.Array; - predicate = enumerable.predicate; - selector = enumerable.selector; - index = enumerable.source.Offset - 1; - end = index + enumerable.source.Count; - } - - public readonly TResult Current - => selector.Invoke(in source![index]); - readonly TResult IEnumerator.Current - => selector.Invoke(in source![index]); - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(in source![index])!; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - while (++index <= end) - { - if (predicate.Invoke(in source![index])) - return true; - } - return false; - } - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - - #region Aggregation - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count() - => ((ReadOnlySpan)source.AsSpan()).CountRef(predicate); - - #endregion - #region Quantifier - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All() - => ((ReadOnlySpan)source.AsSpan()).AllRef(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool All(Func predicate) - // => All(new FunctionInWrapper(predicate)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool All(TPredicate2 predicate) - // where TPredicate2 : struct, IFunctionIn - // => this.AllRef, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TPredicate2>(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool All(Func predicate) - // => AllAt(new FunctionInWrapper(predicate)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool AllAt(TPredicate2 predicate) - // where TPredicate2 : struct, IFunctionIn - // => this.AllAt, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TPredicate2>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => ((ReadOnlySpan)source.AsSpan()).AnyRef(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool Any(Func predicate) - // => Any(new FunctionInWrapper(predicate)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool Any(TPredicate2 predicate) - // where TPredicate2 : struct, IFunctionIn - // => this.AnyRef, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TPredicate2>(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool Any(Func predicate) - // => AnyAt(new FunctionInWrapper(predicate)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool AnyAt(TPredicate2 predicate) - // where TPredicate2 : struct, IFunctionIn - // => this.AnyAtRef, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TPredicate2>(predicate); - - #endregion - #region Filtering - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ValueEnumerableExtensions.WhereRefEnumerable, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, FunctionInWrapper> Where(FunctionIn predicate) - // => this.Where, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult>(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ValueEnumerableExtensions.WhereRefEnumerable, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) - // where TPredicate2 : struct, IFunctionIn - // => this.WhereRef, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TPredicate2>(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ValueEnumerableExtensions.WhereAtRefEnumerable, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, FunctionInWrapper> Where(FunctionIn predicate) - // => this.Where, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult>(predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ValueEnumerableExtensions.WhereAtRefEnumerable, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) - // where TPredicate2 : struct, IFunctionIn - // => this.WhereAtRef, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TPredicate2>(predicate); - - #endregion - #region Projection - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentWhereSelectRefEnumerable, TSource, TResult, TResult2>> Select(Func selector) - // => Select>(new FunctionInWrapper(selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentWhereSelectRefEnumerable> Select(TSelector2 selector = default) - // where TSelector2 : struct, IFunctionIn - // => source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ValueEnumerableExtensions.SelectManyEnumerable, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionInWrapper> SelectMany(Func selector) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // => this.SelectMany, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ValueEnumerableExtensions.SelectManyEnumerable, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // where TSelector2 : struct, IFunctionIn - // => this.SelectMany, ArraySegmentWhereSelectRefEnumerable.DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - - #endregion - #region Element - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option ElementAt(int index) - // => source.ElementAtRef(index, predicate, selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option First() - // => source.FirstRef(predicate, selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option Single() - // => source.SingleRef(predicate, selector); - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TResult[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArrayRef(predicate, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => ((ReadOnlySpan)source.AsSpan()).ToArrayRef(predicate, selector, memoryPool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToListRef(predicate, selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - // where TKey : notnull - // => ToDictionary>(new FunctionInWrapper(keySelector), comparer); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - // where TKey : notnull - // where TKeySelector : struct, IFunctionIn - // => source.ToDictionary(keySelector, comparer, predicate, selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - // where TKey : notnull - // => ToDictionary, FunctionInWrapper>(new FunctionInWrapper(keySelector), new FunctionInWrapper(elementSelector), comparer); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - // where TKey : notnull - // where TKeySelector : struct, IFunctionIn - // where TElementSelector : struct, IFunctionIn - // => source.ToDictionary(keySelector, elementSelector, comparer, predicate, selector); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentWhereSelectRefEnumerable source) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.predicate, source.selector); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectRefEnumerator.cs b/NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectRefEnumerator.cs deleted file mode 100644 index 42a835ba3..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereSelectRef/WhereSelectRefEnumerator.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct WhereSelectRefEnumerator - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - { - readonly Span source; - TPredicate predicate; - TSelector selector; - int index; - - internal WhereSelectRefEnumerator(Span source, TPredicate predicate, TSelector selector) - { - this.source = source; - this.predicate = predicate; - this.selector = selector; - index = -1; - } - - public readonly TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(in source[index]); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - var span = source; - while (++index < span.Length) - { - if (predicate.Invoke(in span[index])) - return true; - } - return false; - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index e7fceb2e2..2c78b2bb8 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -76,4 +76,10 @@ + + + + + + diff --git a/NetFabric.Hyperlinq/Projection/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/Select.ArraySegment.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/Select.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/Select.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/Select.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/Select.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/Select.ReadOnlySpan.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/Select.Span.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.Span.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/Select.Span.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/Select.Span.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/Select.ValueEnumerable.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/Select.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectEnumerator.cs b/NetFabric.Hyperlinq/Projection/Select/Select/SelectEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/SelectEnumerator.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/SelectEnumerator.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ArraySegment.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ReadOnlySpan.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.Span.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.Span.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.Span.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.Span.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ValueEnumerable.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAt/SelectAtEnumerator.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAtEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectAt/SelectAtEnumerator.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAtEnumerator.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ArraySegment.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.ArraySegment.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ArraySegment.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.Memory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Memory.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.Memory.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Memory.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.Range.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlyMemory.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlyMemory.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.ReadOnlySpan.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.Span.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Span.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectVector/SelectVector.Span.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Span.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectAtRef/SelectAtRef.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectAtRef/SelectAtRef.ArraySegment.cs deleted file mode 100644 index 21389167f..000000000 --- a/NetFabric.Hyperlinq/Projection/SelectAtRef/SelectAtRef.ArraySegment.cs +++ /dev/null @@ -1,291 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectAtRefEnumerable> Select(this in ArraySegment source, FunctionIn selector) - => source.SelectAtRef>(new FunctionInWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectAtRefEnumerable SelectAtRef(this in ArraySegment source, TSelector selector = default) - where TSelector : struct, IFunctionIn - => new(in source, selector); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public partial struct ArraySegmentSelectAtRefEnumerable - : IValueReadOnlyList.Enumerator> - , IList - where TSelector : struct, IFunctionIn - { - internal readonly ArraySegment source; - internal TSelector selector; - - internal ArraySegmentSelectAtRefEnumerable(in ArraySegment source, TSelector selector) - { - this.source = source; - this.selector = selector; - } - - public readonly int Count - => source.Count; - - public TResult this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if (index < 0 || index >= source.Count) Throw.IndexOutOfRangeException(); - - return selector.Invoke(in source.Array![index + source.Offset], index); - } - } - TResult IReadOnlyList.this[int index] - => this[index]!; - TResult IList.this[int index] - { - get => this[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectAtRefEnumerator GetEnumerator() - => new(source.AsSpan(), selector); - readonly Enumerator IValueEnumerable.GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - - - bool ICollection.IsReadOnly - => true; - - void ICollection.CopyTo(TResult[] array, int arrayIndex) - => CopyAtRef(source.AsSpan(), array.AsSpan(arrayIndex), selector); - void ICollection.Add(TResult item) - => Throw.NotSupportedException(); - void ICollection.Clear() - => Throw.NotSupportedException(); - public bool Contains(TResult item) - => ((ReadOnlySpan)source.AsSpan()).ContainsAtRef(item, default, selector); - bool ICollection.Remove(TResult item) - => Throw.NotSupportedException(); - int IList.IndexOf(TResult item) - => ArrayExtensions.IndexOfAtRef(source, item, selector); - void IList.Insert(int index, TResult item) - => Throw.NotSupportedException(); - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - : IEnumerator - { - readonly TSource[]? source; - TSelector selector; - readonly int offset; - readonly int end; - int index; - - internal Enumerator(in ArraySegmentSelectAtRefEnumerable enumerable) - { - source = enumerable.source.Array; - selector = enumerable.selector; - offset = enumerable.source.Offset; - index = -1; - end = index + enumerable.source.Count; - } - - public readonly TResult Current - => selector.Invoke(in source![index + offset], index); - readonly TResult IEnumerator.Current - => selector.Invoke(in source![index + offset], index)!; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(in source![index + offset], index); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public void Dispose() { } - } - - #region Aggregation - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.Count is not 0; - - #endregion - #region Filtering - - #endregion - #region Projection - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentSelectAtRefEnumerable, TSource, TResult, TResult2>> Select(Func selector) - // => Select>(new FunctionWrapper(selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentSelectAtRefEnumerable> Select(TSelector2 selector = default) - // where TSelector2 : struct, IFunction - // => source.SelectAt>(new SelectorAtSelectorCombination(this.selector, selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentSelectAtRefEnumerable, TSource, TResult, TResult2>> Select(Func selector) - // => SelectAt>(new FunctionWrapper(selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentSelectAtRefEnumerable> SelectAt(TSelector2 selector = default) - // where TSelector2 : struct, IFunction - // => source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // where TSelector2 : struct, IFunction - // => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - - #endregion - #region Element - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option ElementAt(int index) - // => ((ReadOnlySpan)source.AsSpan()).ElementAtAtRef(index, selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option First() - // => ((ReadOnlySpan)source.AsSpan()).FirstAtRef(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option Single() - // => ((ReadOnlySpan)source.AsSpan()).SingleAtRef(selector); - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TResult[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArrayAtRef(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => ((ReadOnlySpan)source.AsSpan()).ToArrayAtRef(selector, pool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToListAtRef(selector); - - #endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentSelectAtRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumAtRef(source.selector); - } -} - diff --git a/NetFabric.Hyperlinq/Projection/SelectAtRef/SelectAtRefEnumerator.cs b/NetFabric.Hyperlinq/Projection/SelectAtRef/SelectAtRefEnumerator.cs deleted file mode 100644 index dbbaf61a9..000000000 --- a/NetFabric.Hyperlinq/Projection/SelectAtRef/SelectAtRefEnumerator.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct SelectAtRefEnumerator - where TSelector : struct, IFunctionIn - { - readonly ReadOnlySpan source; - TSelector selector; - int index; - - internal SelectAtRefEnumerator(ReadOnlySpan source, TSelector selector) - { - this.source = source; - this.selector = selector; - index = -1; - } - - public readonly TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(in source[index], index); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index < source.Length; - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectMany/SelectMany.ArraySegment.cs rename to NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectMany/SelectMany.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectMany/SelectMany.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/SelectMany/SelectMany.ValueEnumerable.cs rename to NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ArraySegment.cs deleted file mode 100644 index 0adce42b4..000000000 --- a/NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ArraySegment.cs +++ /dev/null @@ -1,268 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectRefEnumerable> Select(this in ArraySegment source, FunctionIn selector) - => source.SelectRef>(new FunctionInWrapper(selector)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectRefEnumerable SelectRef(this in ArraySegment source, TSelector selector = default) - where TSelector : struct, IFunctionIn - => new(in source, selector); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public partial struct ArraySegmentSelectRefEnumerable - : IValueReadOnlyList.Enumerator> - , IList - where TSelector : struct, IFunctionIn - { - internal readonly ArraySegment source; - internal TSelector selector; - - internal ArraySegmentSelectRefEnumerable(in ArraySegment source, TSelector selector) - => (this.source, this.selector) = (source, selector); - - public readonly int Count - => source.Count; - - public TResult this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if (index < 0 || index >= source.Count) Throw.IndexOutOfRangeException(); - - return selector.Invoke(in source.Array![index + source.Offset]); - } - } - TResult IReadOnlyList.this[int index] - => this[index]; - TResult IList.this[int index] - { - get => this[index]; - - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - public readonly SelectRefEnumerator GetEnumerator() - => new (source.AsSpan(), selector); - readonly Enumerator IValueEnumerable.GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - - - bool ICollection.IsReadOnly - => true; - - void ICollection.CopyTo(TResult[] array, int arrayIndex) - => CopyRef(source.AsSpan(), array.AsSpan(arrayIndex), selector); - void ICollection.Add(TResult item) - => Throw.NotSupportedException(); - void ICollection.Clear() - => Throw.NotSupportedException(); - public bool Contains(TResult item) - => ((ReadOnlySpan)source.AsSpan()).ContainsRef(item, default, selector); - bool ICollection.Remove(TResult item) - => Throw.NotSupportedException(); - int IList.IndexOf(TResult item) - => ArrayExtensions.IndexOfRef(source, item, selector); - void IList.Insert(int index, TResult item) - => Throw.NotSupportedException(); - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - : IEnumerator - { - readonly TSource[]? source; - TSelector selector; - readonly int end; - int index; - - internal Enumerator(in ArraySegmentSelectRefEnumerable enumerable) - { - source = enumerable.source.Array; - selector = enumerable.selector; - index = enumerable.source.Offset - 1; - end = index + enumerable.source.Count; - } - - public readonly TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(in source![index]); - } - readonly TResult IEnumerator.Current - => selector.Invoke(in source![index]); - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(in source![index]); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public void Dispose() { } - } - - #region Aggregation - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.Count is not 0; - - #endregion - #region Filtering - - #endregion - #region Projection - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentSelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - // => Select>(new FunctionWrapper(selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentSelectEnumerable> Select(TSelector2 selector = default) - // where TSelector2 : struct, IFunction - // => ((ReadOnlySpan)source.AsSpan()).SelectRef>(new SelectorSelectorCombination(this.selector, selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentSelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - // => SelectAt>(new FunctionWrapper(selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public ArraySegmentSelectAtEnumerable> SelectAt(TSelector2 selector = default) - // where TSelector2 : struct, IFunction - // => ((ReadOnlySpan)source.AsSpan()).SelectAtRef>(new SelectorSelectorAtCombination(this.selector, selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // => this.SelectManyRef, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // where TSelector2 : struct, IFunction - // => this.SelectManyRef, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - - #endregion - #region Element - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option ElementAt(int index) - // => ((ReadOnlySpan)source.AsSpan()).ElementAtRef(index, selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option First() - // => ((ReadOnlySpan)source.AsSpan()).FirstRef(selector); - - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option Single() - // => ((ReadOnlySpan)source.AsSpan()).SingleRef(selector); - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TResult[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArrayRef(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => ((ReadOnlySpan)source.AsSpan()).ToArrayRef(selector, pool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToListRef(selector); - - #endregion - - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => ((ReadOnlySpan)source.source.AsSpan()).SumRef(source.selector); - } -} - diff --git a/NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ReadOnlyMemory.cs deleted file mode 100644 index 8aa551a3a..000000000 --- a/NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ReadOnlyMemory.cs +++ /dev/null @@ -1,284 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemorySelectRefEnumerable> Select(this ReadOnlyMemory source, FunctionIn selector) - => source.SelectRef>(new FunctionInWrapper(selector)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemorySelectRefEnumerable SelectRef(this ReadOnlyMemory source, TSelector selector = default) - where TSelector : struct, IFunctionIn - => new(source, selector); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public partial struct MemorySelectRefEnumerable - : IValueReadOnlyList.Enumerator> - , IList - where TSelector : struct, IFunctionIn - { - internal readonly ReadOnlyMemory source; - internal TSelector selector; - - internal MemorySelectRefEnumerable(ReadOnlyMemory source, TSelector selector) - { - this.source = source; - this.selector = selector; - } - - public readonly int Count - => source.Length; - - public TResult this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(in source.Span[index]); - } - TResult IReadOnlyList.this[int index] - => selector.Invoke(in source.Span[index]); - TResult IList.this[int index] - { - get => selector.Invoke(in source.Span[index]); - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - public readonly SelectRefEnumerator GetEnumerator() - => new(source.Span, selector); - readonly Enumerator IValueEnumerable.GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - - - bool ICollection.IsReadOnly - => true; - - void ICollection.CopyTo(TResult[] array, int arrayIndex) - => ArrayExtensions.CopyRef(source.Span, array.AsSpan(arrayIndex), selector); - void ICollection.Add(TResult item) - => Throw.NotSupportedException(); - void ICollection.Clear() - => Throw.NotSupportedException(); - public bool Contains(TResult item) - => source.Span.ContainsRef(item, default, selector); - bool ICollection.Remove(TResult item) - => Throw.NotSupportedException(); - int IList.IndexOf(TResult item) - => ArrayExtensions.IndexOfRef(source.Span, item, selector); - void IList.Insert(int index, TResult item) - => Throw.NotSupportedException(); - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - : IEnumerator - { - readonly ReadOnlyMemory source; - TSelector selector; - int index; - - internal Enumerator(in MemorySelectRefEnumerable enumerable) - { - source = enumerable.source; - selector = enumerable.selector; - index = -1; - } - - public readonly TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(in source.Span[index]); - } - readonly TResult IEnumerator.Current - => selector.Invoke(in source.Span[index]); - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(in source.Span[index]); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index < source.Length; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public void Dispose() { } - } - - //#region Aggregation - - //#endregion - //#region Quantifier - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool Any() - // => source.Length is not 0; - - //#endregion - //#region Filtering - - //#endregion - //#region Projection - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public MemorySelectRefEnumerable, TSource, TResult, TResult2>> Select(Func selector) - // => Select>(new FunctionWrapper(selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public MemorySelectRefEnumerable> Select(TSelector2 selector = default) - // where TSelector2 : struct, IFunction - // => source.Select>(new SelectorSelectorCombination(this.selector, selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public MemorySelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - // => SelectAt>(new FunctionWrapper(selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public MemorySelectAtEnumerable> SelectAt(TSelector2 selector = default) - // where TSelector2 : struct, IFunction - // => source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // where TSelector2 : struct, IFunction - // => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - - //#endregion - //#region Element - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option ElementAt(int index) - // => source.Span.ElementAt(index, selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option First() - // => source.Span.First(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option Single() - // => source.Span.Single(selector); - - //#endregion - //#region Conversion - - //public TResult[] ToArray() - // => source.Span.ToArray(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public IMemoryOwner ToArray(MemoryPool pool) - // => source.Span.ToArray(selector, pool); - - //public List ToList() - // => source.Span.ToList(selector); - - //#endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this MemorySelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.Span.SumRef(source.selector); - } -} - diff --git a/NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ReadOnlySpan.cs deleted file mode 100644 index be17e77a2..000000000 --- a/NetFabric.Hyperlinq/Projection/SelectRef/SelectRef.ReadOnlySpan.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectRefEnumerable> Select(this ReadOnlySpan source, FunctionIn selector) - => source.SelectRef>(new FunctionInWrapper(selector)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectRefEnumerable SelectRef(this ReadOnlySpan source, TSelector selector = default) - where TSelector : struct, IFunctionIn - => new(source, selector); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public ref struct SpanSelectRefEnumerable - where TSelector : struct, IFunctionIn - { - internal readonly ReadOnlySpan source; - internal TSelector selector; - - internal SpanSelectRefEnumerable(ReadOnlySpan source, TSelector selector) - { - this.source = source; - this.selector = selector; - } - - public readonly SelectRefEnumerator GetEnumerator() - => new(source, selector); - - public readonly int Count - => source.Length; - - public TResult this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(in source[index]); - } - - //#region Aggregation - - //#endregion - //#region Quantifier - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public bool Any() - // => source.Length is not 0; - - //#endregion - //#region Filtering - - //#endregion - //#region Projection - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public SpanSelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - // => Select>(new FunctionWrapper(selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public SpanSelectEnumerable> Select(TSelector2 selector = default) - // where TSelector2 : struct, IFunction - // => source.Select>(new SelectorSelectorCombination(this.selector, selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public SpanSelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - // => SelectAt>(new FunctionWrapper(selector)); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public SpanSelectAtEnumerable> SelectAt(TSelector2 selector = default) - // where TSelector2 : struct, IFunction - // => source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); - - //#endregion - //#region Element - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option ElementAt(int index) - // => source.ElementAt(index, selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option First() - // => source.First(selector); - - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public Option Single() - // => source.Single(selector); - - //#endregion - //#region Conversion - - //public TResult[] ToArray() - // => source.ToArray(selector); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public IMemoryOwner ToArray(MemoryPool pool) - // => source.ToArray(selector, pool); - - //public List ToList() - // => source.ToList(selector); - - //#endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this SpanSelectRefEnumerable source) - where TSelector : struct, IFunctionIn - => source.source.SumRef(source.selector); - } -} - diff --git a/NetFabric.Hyperlinq/Projection/SelectRef/SelectRefEnumerator.cs b/NetFabric.Hyperlinq/Projection/SelectRef/SelectRefEnumerator.cs deleted file mode 100644 index 5d4683a61..000000000 --- a/NetFabric.Hyperlinq/Projection/SelectRef/SelectRefEnumerator.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - [StructLayout(LayoutKind.Auto)] - public ref struct SelectRefEnumerator - where TSelector : struct, IFunctionIn - { - readonly ReadOnlySpan source; - TSelector selector; - int index; - - internal SelectRefEnumerator(ReadOnlySpan source, TSelector selector) - { - this.source = source; - this.selector = selector; - index = -1; - } - - public readonly TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(in source[index]); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index < source.Length; - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.Memory.cs b/NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.Memory.cs deleted file mode 100644 index 0b3f5828e..000000000 --- a/NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.Memory.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this Memory source, FunctionIn predicate) - => source.AllRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AllRef(this Memory source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => source.Span.AllRef(predicate); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this Memory source, FunctionIn predicate) - => source.AllAtRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AllAtRef(this Memory source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => source.Span.AllAtRef(predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.ReadOnlySpan.cs deleted file mode 100644 index 5de264e8c..000000000 --- a/NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.ReadOnlySpan.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this ReadOnlySpan source, FunctionIn predicate) - => source.AllRef(new FunctionInWrapper(predicate)); - - public static bool AllRef(this ReadOnlySpan source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - { - foreach (ref readonly var item in source) - { - if (!predicate.Invoke(in item)) - return false; - } - - return true; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this ReadOnlySpan source, FunctionIn predicate) - => source.AllAtRef(new FunctionInWrapper(predicate)); - - public static bool AllAtRef(this ReadOnlySpan source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - { - for (var index = 0; index < source.Length; index++) - { - ref readonly var item = ref source[index]; - if (!predicate.Invoke(in item, index)) - return false; - } - return true; - } - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.Span.cs b/NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.Span.cs deleted file mode 100644 index 87de90700..000000000 --- a/NetFabric.Hyperlinq/Quantifier/AllRef/AllRef.Span.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this Span source, FunctionIn predicate) - => source.AllRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AllRef(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source).AllRef(predicate); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this Span source, FunctionIn predicate) - => source.AllAtRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AllAtRef(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source).AllAtRef(predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/AnyRef/AnyRef.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/AnyRef/AnyRef.ReadOnlySpan.cs deleted file mode 100644 index 048a4a432..000000000 --- a/NetFabric.Hyperlinq/Quantifier/AnyRef/AnyRef.ReadOnlySpan.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this in ReadOnlySpan source, FunctionIn predicate) - => source.AnyRef(new FunctionInWrapper(predicate)); - - public static bool AnyRef(this ReadOnlySpan source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - { - foreach (ref readonly var item in source) - { - if (predicate.Invoke(in item)) - return true; - } - return false; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this in ReadOnlySpan source, FunctionIn predicate) - => source.AnyAtRef(new FunctionInWrapper(predicate)); - - public static bool AnyAtRef(this ReadOnlySpan source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - { - for (var index = 0; index < source.Length; index++) - { - ref readonly var item = ref source[index]; - if (predicate.Invoke(in item, index)) - return true; - } - return false; - } - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/AnyRef/AnyRef.Span.cs b/NetFabric.Hyperlinq/Quantifier/AnyRef/AnyRef.Span.cs deleted file mode 100644 index 1c95df676..000000000 --- a/NetFabric.Hyperlinq/Quantifier/AnyRef/AnyRef.Span.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this Span source, FunctionIn predicate) - => source.AnyRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AnyRef(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source).AnyRef(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this Span source, FunctionIn predicate) - => source.AnyAtRef(new FunctionInWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AnyAtRef(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunctionIn - => ((ReadOnlySpan)source).AnyAtRef(predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs index 6655f44fd..8f3b578d4 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs @@ -70,40 +70,6 @@ static bool ReferenceContains(ReadOnlySpan source, TResult value, IEqua } } - static bool ContainsRef(this ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) - where TSelector : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => false, - _ => Utils.UseDefault(comparer) - ? ValueContains(source, value, selector) - : ReferenceContains(source, value, comparer, selector) - }; - - static bool ValueContains(ReadOnlySpan source, TResult value, TSelector selector) - { - foreach (ref readonly var item in source) - { - if (EqualityComparer.Default.Equals(selector.Invoke(in item), value)) - return true; - } - return false; - } - - static bool ReferenceContains(ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) - { - comparer ??= EqualityComparer.Default; - foreach (ref readonly var item in source) - { - if (comparer.Equals(selector.Invoke(in item), value)) - return true; - } - return false; - } - } - - static bool ContainsAt(this ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) where TSelector : struct, IFunction { @@ -136,39 +102,6 @@ static bool ReferenceContains(ReadOnlySpan source, TResult value, IEqua return false; } } - - static bool ContainsAtRef(this ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) - where TSelector : struct, IFunctionIn - { - return source switch - { - { Length: 0 } => false, - _ => Utils.IsValueType() - ? ValueContains(source, value, selector) - : ReferenceContains(source, value, comparer, selector), - }; - - static bool ValueContains(ReadOnlySpan source, TResult value, TSelector selector) - { - for (var index = 0; index < source.Length; index++) - { - if (EqualityComparer.Default.Equals(selector.Invoke(in source[index], index), value)) - return true; - } - return false; - } - - static bool ReferenceContains(ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) - { - comparer ??= EqualityComparer.Default; - for (var index = 0; index < source.Length; index++) - { - if (comparer.Equals(selector.Invoke(in source[index], index), value)) - return true; - } - return false; - } - } } } diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs index c2954c2ca..f5d5347b3 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -80,40 +80,6 @@ static bool ReferenceContains(TEnumerable source, TResult value, IEqualityCompar } } - internal static bool ContainsRef(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunctionIn - { - return Utils.IsValueType() - ? ValueContains(source, value, selector) - : ReferenceContains(source, value, comparer, selector); - - static bool ValueContains(TEnumerable source, TResult value, TSelector selector) - { - using var enumerator = source.GetEnumerator(); - while (enumerator.MoveNext()) - { - if (EqualityComparer.Default.Equals(selector.Invoke(enumerator.Current), value)) - return true; - } - return false; - } - - static bool ReferenceContains(TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) - { - comparer ??= EqualityComparer.Default; - - using var enumerator = source.GetEnumerator(); - while (enumerator.MoveNext()) - { - if (comparer.Equals(selector.Invoke(enumerator.Current), value)) - return true; - } - return false; - } - } - internal static bool ContainsAt(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs index d282df0c2..bd9b009a5 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs @@ -19,18 +19,6 @@ static LargeArrayBuilder ToArrayBuilder(ReadOnlySp return builder; } - static LargeArrayBuilder ToArrayBuilderRef(ReadOnlySpan source, TPredicate predicate, ArrayPool arrayPool) - where TPredicate : struct, IFunctionIn - { - var builder = new LargeArrayBuilder(arrayPool); - foreach (ref readonly var item in source) - { - if (predicate.Invoke(in item)) - builder.AddRef(in item); - } - return builder; - } - static LargeArrayBuilder ToArrayBuilderAt(ReadOnlySpan source, TPredicate predicate, ArrayPool arrayPool) where TPredicate: struct, IFunction { @@ -44,19 +32,6 @@ static LargeArrayBuilder ToArrayBuilderAt(ReadOnly return builder; } - static LargeArrayBuilder ToArrayBuilderAtRef(ReadOnlySpan source, TPredicate predicate, ArrayPool arrayPool) - where TPredicate : struct, IFunctionIn - { - var builder = new LargeArrayBuilder(arrayPool); - for (var index = 0; index < source.Length; index++) - { - ref readonly var item = ref source[index]; - if (predicate.Invoke(in item, index)) - builder.AddRef(in item); - } - return builder; - } - static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, TPredicate predicate, TSelector selector, ArrayPool arrayPool) where TPredicate: struct, IFunction where TSelector: struct, IFunction @@ -69,18 +44,5 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderRef(ReadOnlySpan source, TPredicate predicate, TSelector selector, ArrayPool arrayPool) - where TPredicate : struct, IFunctionIn - where TSelector : struct, IFunctionIn - { - var builder = new LargeArrayBuilder(arrayPool); - foreach (ref readonly var item in source) - { - if (predicate.Invoke(in item)) - builder.Add(selector.Invoke(in item)); - } - return builder; - } } } diff --git a/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs index 729ed969b..e2919534d 100644 --- a/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs @@ -66,19 +66,6 @@ public static void CopyVector(Read } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CopyRef(ReadOnlySpan source, Span destination, TSelector selector) - where TSelector : struct, IFunctionIn - { - Debug.Assert(destination.Length >= source.Length); - - for (var index = 0; index < source.Length && index < destination.Length; index++) - { - ref readonly var item = ref source[index]; - destination[index] = selector.Invoke(in item); - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CopyAt(ReadOnlySpan source, Span destination, TSelector selector) where TSelector : struct, IFunction @@ -91,18 +78,5 @@ public static void CopyAt(ReadOnlySpan sou destination[index] = selector.Invoke(item, index); } } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CopyAtRef(ReadOnlySpan source, Span destination, TSelector selector) - where TSelector : struct, IFunctionIn - { - Debug.Assert(destination.Length >= source.Length); - - for (var index = 0; index < source.Length && index < destination.Length; index++) - { - ref readonly var item = ref source[index]; - destination[index] = selector.Invoke(in item, index); - } - } } } diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs index 40df061ce..d6f1ddb1e 100644 --- a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs @@ -70,37 +70,6 @@ public static int IndexOf(IReadOnlyList so return -1; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfRef(IReadOnlyList source, TResult item, TSelector selector, int offset, int count) - where TSelector : struct, IFunctionIn - { - if (count is 0) - return -1; - - var end = offset + count; - if (Utils.IsValueType()) - { - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(in arrayItem), item)) - return index - offset; - } - } - else - { - var defaultComparer = EqualityComparer.Default; - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (defaultComparer.Equals(selector.Invoke(in arrayItem), item)) - return index - offset; - } - } - - return -1; - } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOfAt(IReadOnlyList source, TResult item, TSelector selector, int offset, int count) @@ -155,59 +124,5 @@ public static int IndexOfAt(IReadOnlyList } return -1; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAtRef(IReadOnlyList source, TResult item, TSelector selector, int offset, int count) - where TSelector : struct, IFunctionIn - { - if (count is 0) - return -1; - - if (Utils.IsValueType()) - { - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var listItem = source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(in listItem, index), item)) - return index; - } - } - else - { - for (var index = 0; index < count; index++) - { - var listItem = source[index + offset]; - if (EqualityComparer.Default.Equals(selector.Invoke(in listItem, index), item)) - return index; - } - } - } - else - { - var defaultComparer = EqualityComparer.Default; - - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var listItem = source[index]; - if (defaultComparer.Equals(selector.Invoke(in listItem, index), item)) - return index; - } - } - else - { - for (var index = 0; index < count; index++) - { - var listItem = source[index + offset]; - if (defaultComparer.Equals(selector.Invoke(in listItem, index), item)) - return index; - } - } - } - return -1; - } } } diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs index 35c8c85ce..422d1dc08 100644 --- a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs @@ -65,36 +65,6 @@ public static int IndexOf(ReadOnlySpan sou return -1; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfRef(ReadOnlySpan source, TResult item, TSelector selector) - where TSelector : struct, IFunctionIn - { - if (source.Length is 0) - return -1; - - if (Utils.IsValueType()) - { - for (var index = 0; index < source.Length; index++) - { - ref readonly var arrayItem = ref source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(in arrayItem), item)) - return index; - } - } - else - { - var defaultComparer = EqualityComparer.Default; - for (var index = 0; index < source.Length; index++) - { - ref readonly var arrayItem = ref source[index]; - if (defaultComparer.Equals(selector.Invoke(in arrayItem), item)) - return index; - } - } - - return -1; - } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOfAt(ReadOnlySpan source, TResult item, TSelector selector) @@ -126,35 +96,5 @@ public static int IndexOfAt(ReadOnlySpan s return -1; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAtRef(ReadOnlySpan source, TResult item, TSelector selector) - where TSelector : struct, IFunctionIn - { - if (source.Length is 0) - return -1; - - if (Utils.IsValueType()) - { - for (var index = 0; index < source.Length; index++) - { - ref readonly var arrayItem = ref source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(in arrayItem, index), item)) - return index; - } - } - else - { - var defaultComparer = EqualityComparer.Default; - for (var index = 0; index < source.Length; index++) - { - ref readonly var arrayItem = ref source[index]; - if (defaultComparer.Equals(selector.Invoke(in arrayItem, index), item)) - return index; - } - } - - return -1; - } - } } diff --git a/README.md b/README.md index 14ea605be..306be854a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ This implementation **favors performance in detriment of assembly binary size** - [Reduced heap allocations](#reduced-heap-allocations) - [Benchmarks](#benchmarks) - [Usage](#usage) - - [Passing items by reference](#passing-items-by-reference) - [Value delegates](#value-delegates) - [Generation operations](#generation-operations) - [Method return types](#method-return-types) @@ -143,26 +142,6 @@ public static void Example(IReadOnlyList list) To add `NetFabric.Hyperlinq` operations after a `System.Linq` operation, simply add one more `AsValueEnumerable()` or `AsAsyncValueEnumerable()`. -### Passing items by reference - -`NetFabric.Hyperlinq` supports passing the items by reference. This can improve considerably the performance for large structures. - -- Use `AsValueEnumerableRef()` instead to make any collection usable with `NetFabric.Hyperlinq`. -- Declare the lambda expressions with `in` keyword on the first parameter. This also requires the declaration of the parameters' type. - -``` csharp -public static void Example(IReadOnlyList list) -{ - var result = list - .AsValueEnumerable() - .Where((in int item) => item > 2) - .Select((in int item) => item * 2); - - foreach(var value in result) - Console.WriteLine(value); -} -``` - ### Value delegates Calling a lambda expression for each item of the collection is very expensive. `NetFabric.Hyperlinq` supports a much more performant alternative. From b64e633ab7901f8664b100d31ed57bf737d1fa52 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sat, 27 Feb 2021 00:10:12 +0000 Subject: [PATCH 02/61] 3.0.0-beta41 --- NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs | 2 ++ NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs index 692379f88..47a4bfa06 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs @@ -200,6 +200,8 @@ internal ImmutableDictionary> CollectExtensionMethods(C { var builder = new CodeBuilder(); _ = builder + .AppendLine("#nullable enable") + .AppendLine() .AppendLine("using System;") .AppendLine("using System.CodeDom.Compiler;") .AppendLine("using System.Diagnostics;") diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 2c78b2bb8..83a8878a8 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -5,7 +5,7 @@ NetFabric.Hyperlinq NetFabric.Hyperlinq High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays, Memory and Span. - 3.0.0-beta40 + 3.0.0-beta41 Icon.png LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance From b4c4dcd8d52d36990ba78130bf8a43de544c3de0 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sat, 27 Feb 2021 21:17:00 +0000 Subject: [PATCH 03/61] NetFabric.Hyperlinq.Abstractions 1.1.0 --- NetFabric.Hyperlinq.Abstractions/IEnumeratorRef.cs | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 NetFabric.Hyperlinq.Abstractions/IEnumeratorRef.cs diff --git a/NetFabric.Hyperlinq.Abstractions/IEnumeratorRef.cs b/NetFabric.Hyperlinq.Abstractions/IEnumeratorRef.cs deleted file mode 100644 index 8ca23bd73..000000000 --- a/NetFabric.Hyperlinq.Abstractions/IEnumeratorRef.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace NetFabric.Hyperlinq -{ - public interface IEnumeratorRef - { - ref T Current { get; } - - bool MoveNext(); - } -} From 4ddf0430e161ed6e4b40041fc96b476a964192bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Sun, 28 Feb 2021 11:18:02 +0000 Subject: [PATCH 04/61] Fix build (#338) --- NetFabric.Hyperlinq.Abstractions/ValueEnumerable.cs | 8 -------- .../TestData/Results/Dictionary.Select.cs | 4 +++- .../TestData/Results/Dictionary.Where.cs | 4 +++- .../TestData/Results/Distinct.ValueEnumerable.Where.cs | 4 +++- .../TestData/Results/Range.Count.cs | 4 +++- .../TestData/Results/Range.Select.cs | 4 +++- .../TestData/Results/Range.Where.cs | 4 +++- .../TestData/Results/Repeat.Count.cs | 4 +++- .../TestData/Results/Select.ArraySegment.Any.cs | 4 +++- .../TestData/Results/Select.ValueEnumerable.Any.cs | 4 +++- .../TestData/Results/Select.ValueEnumerable.First.cs | 4 +++- .../TestData/Results/Select.ValueEnumerable.Where.cs | 4 +++- .../TestData/Results/Where.ArraySegment.Count.cs | 4 +++- .../TestData/Results/Where.ValueEnumerable.Count.cs | 4 +++- .../TestData/Results/Where.ValueEnumerable.Distinct.cs | 4 +++- .../TestData/Results/Where.ValueEnumerable.First.cs | 4 +++- .../TestData/Results/Where.ValueEnumerable.Select.cs | 4 +++- 17 files changed, 48 insertions(+), 24 deletions(-) diff --git a/NetFabric.Hyperlinq.Abstractions/ValueEnumerable.cs b/NetFabric.Hyperlinq.Abstractions/ValueEnumerable.cs index 05a2cc620..70789c857 100644 --- a/NetFabric.Hyperlinq.Abstractions/ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Abstractions/ValueEnumerable.cs @@ -29,12 +29,4 @@ where TEnumerator , IEnumerator { } - - public interface IValueEnumerableRef - where TEnumerator - : struct - , IEnumeratorRef - { - [return: NotNull] TEnumerator GetEnumerator(); - } } diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs index 4eda86132..ad5c7e588 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs index e5aeeacaf..b0c43413d 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs index 68d5bfe0d..4ad7f8437 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs index 73900248e..2e88d9b0c 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs index 09bf8358a..a59fc2be7 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs index 4b9a35905..7d6a65e34 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs index f31c15431..1957b9a43 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs index 2a75b24f4..3c386baf5 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs index 0a6515ed3..1cb77b73d 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs index 185d5728f..aee9f5219 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs index 58b5dd28e..e688b8599 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs index 9dc5d6d80..2f20d750a 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs index 6b88fa161..ab03bd3f1 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs index b76aac114..ecf3034cb 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs index 1a4283448..3712ad11c 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs index 2bdd06674..091ba4c12 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using System.CodeDom.Compiler; using System.Diagnostics; using System.Runtime.CompilerServices; From 87b6c244785d716bbbcb31d8615a1a4e7c8027aa Mon Sep 17 00:00:00 2001 From: "J. Zebedee" Date: Sun, 28 Feb 2021 19:57:08 +0000 Subject: [PATCH 05/61] Use correct NuGet link (#336) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 306be854a..46b3f6064 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ The names of the benchmarks are structured as follow: - The library used: - _Linq_ - the `System.Linq` namespace (includes [System.Linq.Async](https://www.nuget.org/packages/System.Linq.Async/), [System.Interactive](https://www.nuget.org/packages/System.Interactive/), and [System.Interactive.Async](https://www.nuget.org/packages/System.Interactive.Async/)) - _StructLinq_ - [StructLinq](https://www.nuget.org/packages/StructLinq/) - - _Hyperlinq_ - [NetFabric.Hyperlinq](https://www.nuget.org/packages/Hyperlinq/) + - _Hyperlinq_ - [NetFabric.Hyperlinq](https://www.nuget.org/packages/NetFabric.Hyperlinq/) - The type of collection used as source: - _Array_ - an array - _Span_ - a `Span<>` From b2ea96c061d57480052f95f6d4cb345a46ac8af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Sun, 28 Feb 2021 22:59:51 +0000 Subject: [PATCH 06/61] Add AsValueEnumerable() for Span<> and ReadOnlySpan<> (#337) --- .../FunctionIn.cs | 2 +- .../FunctionWrapper.cs | 12 + NetFabric.Hyperlinq.Abstractions/IFunction.cs | 5 + .../NetFabric.Hyperlinq.Abstractions.csproj | 2 +- .../Benchmarks/CountBenchmarks.cs | 2 +- .../Benchmarks/SumBenchmarks.cs | 2 +- .../Count/Count.ReadOnlySpan.Tests.cs | 12 +- .../Aggregation/Count/Count.Span.Tests.cs | 70 ---- .../ToArray/ToArray.ReadOnlySpan.Tests.cs | 44 +-- .../Conversion/ToArray/ToArray.Span.Tests.cs | 276 --------------- .../Conversion/ToList/ToList.Span.Tests.cs | 149 -------- .../Element/ElementAt/ElementAt.Span.Tests.cs | 304 ---------------- .../Element/First/First.Span.Tests.cs | 237 ------------- .../Element/Single/Single.Span.Tests.cs | 333 ------------------ .../Filtering/Where/Where.Span.Tests.cs | 28 -- .../Filtering/WhereAt/WhereAt.Span.Tests.cs | 28 -- .../WhereSelect/WhereSelect.Span.Tests.cs | 29 -- .../Partitioning/Skip/Skip.Span.Tests.cs | 29 -- .../Partitioning/Take/Take.Span.Tests.cs | 29 -- .../Projection/Select/Select.Span.Tests.cs | 26 -- .../SelectAt/SelectAt.Span.Tests.cs | 26 -- .../Quantifier/All/All.Span.Tests.cs | 47 --- .../Quantifier/Any/Any.Span.Tests.cs | 68 ---- .../Contains/Contains.Span.Tests.cs | 152 -------- .../Set/Distinct/Distinct.Span.Tests.cs | 95 ----- .../Aggregation/Count/Count.ReadOnlySpan.cs | 2 +- .../Aggregation/Count/Count.Span.cs | 13 - .../Aggregation/Sum/Sum.ReadOnlySpan.cs | 43 +-- .../Aggregation/Sum/Sum.Span.cs | 49 --- .../AsValueEnumerable.ArraySegment.cs | 58 +-- .../AsValueEnumerable.ReadOnlyMemory.cs | 14 +- .../AsValueEnumerable.ReadOnlySpan.cs | 295 ++++++++++++++++ .../AsValueEnumerable.Span.cs} | 9 +- .../ToArray/ToArray.ReadOnlySpan.cs | 4 +- .../SelectMany/SelectMany.ReadOnlySpan.cs | 220 ++++++++++++ 35 files changed, 610 insertions(+), 2104 deletions(-) delete mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/First/First.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Span.Tests.cs delete mode 100644 NetFabric.Hyperlinq/Aggregation/Count/Count.Span.cs delete mode 100644 NetFabric.Hyperlinq/Aggregation/Sum/Sum.Span.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs rename NetFabric.Hyperlinq/Conversion/{ToArray/ToArray.Span.cs => AsValueEnumerable/AsValueEnumerable.Span.cs} (51%) create mode 100644 NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq.Abstractions/FunctionIn.cs b/NetFabric.Hyperlinq.Abstractions/FunctionIn.cs index e4e4ab4ac..b10e4d3c8 100644 --- a/NetFabric.Hyperlinq.Abstractions/FunctionIn.cs +++ b/NetFabric.Hyperlinq.Abstractions/FunctionIn.cs @@ -2,5 +2,5 @@ { public delegate TResult FunctionIn(in T arg); - public delegate TResult FunctionIn(in T1 arg, T2 arg2); + public delegate TResult FunctionIn(in T1 arg, T2 arg2); } diff --git a/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs b/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs index 2802ed999..2a27d163c 100644 --- a/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs +++ b/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs @@ -2,6 +2,18 @@ namespace NetFabric.Hyperlinq { + public readonly struct FunctionWrapper + : IFunction + { + readonly Func function; + + public FunctionWrapper(Func function) + => this.function = function ?? throw new ArgumentNullException(nameof(function)); + + public TResult Invoke() + => function(); + } + public readonly struct FunctionWrapper : IFunction { diff --git a/NetFabric.Hyperlinq.Abstractions/IFunction.cs b/NetFabric.Hyperlinq.Abstractions/IFunction.cs index ee309ec5b..446d2eba0 100644 --- a/NetFabric.Hyperlinq.Abstractions/IFunction.cs +++ b/NetFabric.Hyperlinq.Abstractions/IFunction.cs @@ -1,5 +1,10 @@ namespace NetFabric.Hyperlinq { + public interface IFunction + { + TResult Invoke(); + } + public interface IFunction { TResult Invoke(T arg); diff --git a/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj b/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj index 35debdd98..3238fe924 100644 --- a/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj +++ b/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj @@ -5,7 +5,7 @@ NetFabric.Hyperlinq.Abstractions NetFabric.Hyperlinq.Abstractions Abstractions for high performance enumeration. - 1.1.0-beta01 + 1.1.0 Icon.png LICENSE netfabric, hyperlinq, abstractions, linq, enumeration, performance diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs index 64c86f155..0db84d82d 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs @@ -117,7 +117,7 @@ public int Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Span() - => array.AsSpan().Count(); + => array.AsSpan().AsValueEnumerable().Count(); [BenchmarkCategory("Array")] [Benchmark] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs index aa03fabae..4869e3987 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs @@ -126,7 +126,7 @@ public int Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Span() - => array.AsSpan().Sum(); + => array.AsSpan().AsValueEnumerable().Sum(); //[BenchmarkCategory("Array")] //[Benchmark] diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs index ed0caabc6..496cb38b1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs @@ -18,8 +18,8 @@ public void Count_With_ValidData_Must_Succeed(int[] source) .Count(source); // Act - var result = ArrayExtensions - .Count((ReadOnlySpan)source.AsSpan()); + var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Count(); // Assert _ = result.Must() @@ -38,8 +38,8 @@ public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, Func)source.AsSpan(), predicate) + var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Where(predicate) .Count(); // Assert @@ -59,8 +59,8 @@ public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func)source.AsSpan(), predicate) + var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Where(predicate) .Count(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Span.Tests.cs deleted file mode 100644 index 6340538cd..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Span.Tests.cs +++ /dev/null @@ -1,70 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Count -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Count_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Count(source); - - // Act - var result = ArrayExtensions - .Count(source.AsSpan()); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Count(source, predicate); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Count(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs index 62ae28d52..c10f90461 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs @@ -21,8 +21,8 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source) .ToArray(source); // Act - using var result = ArrayExtensions - .ToArray((ReadOnlySpan)source.AsSpan(), pool); + using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .ToArray(pool); // Assert _ = result.Memory.Must() @@ -44,8 +44,8 @@ public void ToArray_Predicate_Must_Succeed(int[] source, Func predica .ToArray(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Where(predicate) .ToArray(); // Assert @@ -68,8 +68,8 @@ public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func)source.AsSpan(), predicate) + using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Where(predicate) .ToArray(pool); // Assert @@ -92,8 +92,8 @@ public void ToArray_PredicateAt_Must_Succeed(int[] source, Func .ToArray(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Where(predicate) .ToArray(); // Assert @@ -116,8 +116,8 @@ public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func)source.AsSpan(), predicate) + using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Where(predicate) .ToArray(pool); // Assert @@ -140,8 +140,8 @@ public void ToArray_Selector_Must_Succeed(int[] source, Func select .ToArray(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Select(selector) .ToArray(); // Assert @@ -164,8 +164,8 @@ public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, Func)source.AsSpan(), selector) + using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Select(selector) .ToArray(pool); // Assert @@ -188,8 +188,8 @@ public void ToArray_SelectorAt_Must_Succeed(int[] source, Func .ToArray(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Select(selector) .ToArray(); // Assert @@ -212,8 +212,8 @@ public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func)source.AsSpan(), selector) + using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Select(selector) .ToArray(pool); // Assert @@ -237,8 +237,8 @@ public void ToArray_Predicate_Selector_Must_Succeed(int[] source, Func)source.AsSpan(), predicate) + var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Where(predicate) .Select(selector) .ToArray(); @@ -263,8 +263,8 @@ public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Fun .ToArray(); // Act - using var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + .Where(predicate) .Select(selector) .ToArray(pool); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Span.Tests.cs deleted file mode 100644 index ad24e3324..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Span.Tests.cs +++ /dev/null @@ -1,276 +0,0 @@ -using System; -using System.Buffers; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToArray -{ - public class SpanTests - { - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToArray_MemoryPool_Must_Succeed(int[] source) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .ToArray(source); - - // Act - using var result = ArrayExtensions - .ToArray(source.AsSpan(), pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ToArray_PredicateAt_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Selector_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ToArray_SelectorAt_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Selector_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToArray(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Span.Tests.cs deleted file mode 100644 index 1b94793c4..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Span.Tests.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToList_With_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .ToList(source); - - // Act - var result = ArrayExtensions - .ToList(source.AsSpan()); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ToList_With_Predicate_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ToList_With_PredicateAt_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ToList_With_Selector_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ToList_With_SelectorAt_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToList_With_Predicate_Selector_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToList(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Span.Tests.cs deleted file mode 100644 index d278ecd20..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Span.Tests.cs +++ /dev/null @@ -1,304 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.ElementAt -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_OutOfRange_Must_Return_None(int[] source) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .ElementAt(source.AsSpan(), -1); - var optionTooLarge = ArrayExtensions - .ElementAt(source.AsSpan(), source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_ValidData_Must_Return_Some(int[] source) - { - for (var index = 0; index < source.Length; index++) - { - // Arrange - var expected = Enumerable - .ElementAt(source, index); - - // Act - var result = ArrayExtensions - .ElementAt(source.AsSpan(), index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_PredicateAt_With_OutOfRange_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Select(source.AsSpan(), selector) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Select(source.AsSpan(), selector) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - for (var index = 0; index < source.Length; index++) - { - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Select(source.AsSpan(), selector) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Select(source.AsSpan(), selector) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - for (var index = 0; index < source.Length; index++) - { - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.Span.Tests.cs deleted file mode 100644 index 7570b9b50..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.Span.Tests.cs +++ /dev/null @@ -1,237 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.First -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void First_With_Empty_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = ArrayExtensions - .First(source.AsSpan()); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void First_With_ValidData_Must_Return_Some(int[] source) - { - // Arrange - var expected = Enumerable - .First(source); - - // Act - var result = ArrayExtensions - .First(source.AsSpan()); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - public void First_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .First(source, predicate); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - public void First_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .First(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - public void First_Selector_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .First(); - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .First(); - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .First(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Span.Tests.cs deleted file mode 100644 index d4d009929..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Span.Tests.cs +++ /dev/null @@ -1,333 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.Single -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void Single_With_Empty_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = ArrayExtensions - .Single(source.AsSpan()); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - public void Single_With_Single_Must_Return_Some(int[] source) - { - // Arrange - var expected = Enumerable - .Single(source); - - // Act - var result = ArrayExtensions - .Single(source.AsSpan()); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Single_With_Multiple_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = ArrayExtensions - .Single(source.AsSpan()); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - public void Single_Predicate_With_Single_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = - Enumerable.Single(source, predicate); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_With_Multiple_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Single(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Multiple_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - public void Single_Selector_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - public void Single_Selector_With_Single_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = - Enumerable.Single( - Enumerable.Select(source, selector)); - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void Single_Selector_With_Multiple_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .Single(); - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select(source.AsSpan(), selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .Single(); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Multiple_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Span.Tests.cs deleted file mode 100644 index d75a5014f..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Span.Tests.cs +++ /dev/null @@ -1,28 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.Where -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Span.Tests.cs deleted file mode 100644 index da5afab63..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Span.Tests.cs +++ /dev/null @@ -1,28 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereIndex -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Span.Tests.cs deleted file mode 100644 index cd389352b..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Span.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereSelect -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(source, predicate), selector); - - // Act - var result = ArrayExtensions - .Where(source.AsSpan(), predicate) - .Select(selector); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Span.Tests.cs deleted file mode 100644 index 6240795d6..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Span.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Skip -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Skip(source, count); - - // Act - var result = ArrayExtensions - .Skip(source.AsSpan(), count); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Span.Tests.cs deleted file mode 100644 index 54167aa9c..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Span.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Take -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void Take_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Take(source, count); - - // Act - var result = ArrayExtensions - .Take(source.AsSpan(), count); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Span.Tests.cs deleted file mode 100644 index 5c7b4658b..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Span.Tests.cs +++ /dev/null @@ -1,26 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.Select -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = - System.Linq.Enumerable.Select(source, selector); - - // Act - var result = ArrayExtensions.Select(source.AsSpan(), selector); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Span.Tests.cs deleted file mode 100644 index 9272e52f6..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Span.Tests.cs +++ /dev/null @@ -1,26 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectIndex -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = - System.Linq.Enumerable.Select(source, selector); - - // Act - var result = ArrayExtensions.Select(source.AsSpan(), selector); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Span.Tests.cs deleted file mode 100644 index 002c501b8..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Span.Tests.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.All -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void All_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = System.Linq.Enumerable.All(source, predicate); - - // Act - var result = ArrayExtensions - .All(source.AsSpan(), predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) == source.Length; - - // Act - var result = ArrayExtensions - .All(source.AsSpan(), predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.Span.Tests.cs deleted file mode 100644 index ad67ef412..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.Span.Tests.cs +++ /dev/null @@ -1,68 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Any -{ - public class SpanTests - { - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Any_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = - System.Linq.Enumerable.Any(source); - - // Act - var result = ArrayExtensions - .Any(source.AsSpan()); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = - System.Linq.Enumerable.Any(source, predicate); - - // Act - var result = ArrayExtensions - .Any(source.AsSpan(), predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) != 0; - - // Act - var result = ArrayExtensions - .Any(source.AsSpan(), predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.Span.Tests.cs deleted file mode 100644 index 63d1563d7..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.Span.Tests.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System; -using System.Collections.Generic; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Contains -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = ArrayExtensions - .Contains(source.AsSpan(), value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = default(string); - var wrapped = source.AsValueEnumerable().AsValueEnumerable().Select(item => item.ToString()).ToArray(); - - // Act - var result = ArrayExtensions - .Contains(wrapped.AsSpan(), value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = System.Linq.Enumerable.Last(source); - - // Act - var result = ArrayExtensions - .Contains(source.AsSpan(), value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = System.Linq.Enumerable.Last(source).ToString(); - var wrapped = source.AsValueEnumerable().Select(item => item.ToString()).ToArray(); - - // Act - var result = ArrayExtensions - .Contains(wrapped.AsSpan(), value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = ArrayExtensions - .Contains(source.AsSpan(), value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = System.Linq.Enumerable.Last(source); - - // Act - var result = ArrayExtensions - .Contains(source.AsSpan(), value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = ArrayExtensions - .Contains(source.AsSpan(), value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = System.Linq.Enumerable.Last(source); - - // Act - var result = ArrayExtensions - .Contains(source.AsSpan(), value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Span.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Span.Tests.cs deleted file mode 100644 index 84b40c0f5..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Span.Tests.cs +++ /dev/null @@ -1,95 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Buffers; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Set.Distinct -{ - public class SpanTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Distinct(source); - - // Act - var result = ArrayExtensions - .Distinct(source.AsSpan()); - - // Assert - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Distinct(source) - .ToArray(); - - // Act - var result = ArrayExtensions - .Distinct(source.AsSpan()) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Distinct(source) - .ToArray(); - - // Act - var result = ArrayExtensions - .Distinct(source.AsSpan()) - .ToArray(pool); - - // Assert - _ = result.Memory - .SequenceEqual(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Distinct(source) - .ToList(); - - // Act - var result = ArrayExtensions - .Distinct(source.AsSpan()) - .ToList(); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs index 7dbfd2a38..bfe3aea7d 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ReadOnlySpan source) + static int Count(this ReadOnlySpan source) => source.Length; static int Count(this ReadOnlySpan source, TPredicate predicate) diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.Span.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.Span.cs deleted file mode 100644 index 9e860e5f1..000000000 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.Span.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this Span source) - => source.Length; - } -} - diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs index 11530199d..598f6b1ec 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs @@ -7,48 +7,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlySpan source) - => Sum(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ReadOnlySpan source) - => Sum(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlySpan source) - => Sum(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ReadOnlySpan source) - => Sum(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlySpan source) - => Sum(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ReadOnlySpan source) - => Sum(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlySpan source) - => Sum(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ReadOnlySpan source) - => Sum(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlySpan source) - => Sum(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ReadOnlySpan source) - => Sum(source); - - /////////////////////////////////////////////////////////// - + static TSource Sum(this ReadOnlySpan source) where TSource : struct { diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Span.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Span.cs deleted file mode 100644 index 687a80d70..000000000 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Span.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this Span source) - => ((ReadOnlySpan)source).Sum(); - } -} - diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index ad1dbca31..c90e6643b 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -72,7 +72,7 @@ bool ICollection.IsReadOnly [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(Span span) - => source.AsSpan().CopyTo(span); + => ((ReadOnlySpan)source.AsSpan()).CopyTo(span); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) @@ -84,7 +84,7 @@ public bool Contains(TSource item) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int IndexOf(TSource item) - => ArrayExtensions.IndexOf(source.AsSpan(), item); + => ArrayExtensions.IndexOf(((ReadOnlySpan)source.AsSpan()), item); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -155,51 +155,51 @@ public ArraySegmentValueEnumerable AsValueEnumerable() [MethodImpl(MethodImplOptions.AggressiveInlining)] public TSource[] ToArray() - => source.AsSpan().ToArray(); + => ((ReadOnlySpan)source.AsSpan()).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.AsSpan().ToArray(memoryPool); + => ((ReadOnlySpan)source.AsSpan()).ToArray(memoryPool); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => source.AsSpan().ToList(); + => ((ReadOnlySpan)source.AsSpan()).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => source.AsSpan().ToDictionary(keySelector, comparer); + => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => source.AsSpan().ToDictionary(keySelector, comparer); + => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) where TKey : notnull - => source.AsSpan().ToDictionary(keySelector, elementSelector, comparer); + => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction where TElementSelector : struct, IFunction - => source.AsSpan().ToDictionary(keySelector, elementSelector, comparer); + => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer); #endregion #region Element public Option ElementAt(int index) - => source.AsSpan().ElementAt(index); + => ((ReadOnlySpan)source.AsSpan()).ElementAt(index); public Option First() - => source.AsSpan().First(); + => ((ReadOnlySpan)source.AsSpan()).First(); public Option Single() - => source.AsSpan().Single(); + => ((ReadOnlySpan)source.AsSpan()).Single(); #endregion @@ -284,7 +284,7 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate predicate) where TPredicate : struct, IFunction - => source.AsSpan().All(predicate); + => ((ReadOnlySpan)source.AsSpan()).All(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -293,11 +293,11 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate predicate) where TPredicate : struct, IFunction - => source.AsSpan().AllAt(predicate); + => ((ReadOnlySpan)source.AsSpan()).AllAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() - => source.AsSpan().Any(); + => ((ReadOnlySpan)source.AsSpan()).Any(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -306,7 +306,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate predicate) where TPredicate : struct, IFunction - => source.AsSpan().Any(predicate); + => ((ReadOnlySpan)source.AsSpan()).Any(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -315,11 +315,11 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate predicate) where TPredicate : struct, IFunction - => source.AsSpan().AnyAt(predicate); + => ((ReadOnlySpan)source.AsSpan()).AnyAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource value, IEqualityComparer? comparer) - => source.AsSpan().Contains(value, comparer); + => ((ReadOnlySpan)source.AsSpan()).Contains(value, comparer); #endregion @@ -338,48 +338,48 @@ public static int Count(this ArraySegmentValueEnumerable sourc [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentValueEnumerable source) - => source.source.AsSpan().Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool ContainsVector(this ArraySegmentValueEnumerable source, TSource value) where TSource : struct - => source.source.AsSpan().ContainsVector(value); + => ((ReadOnlySpan)source.source.AsSpan()).ContainsVector(value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static MemorySelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ArraySegmentValueEnumerable source, Func, Vector> vectorSelector, Func selector) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index 5f2ef5481..4b28f95ca 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -323,13 +323,17 @@ public MemoryDistinctEnumerable Distinct(IEqualityComparer? co #endregion } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemoryValueEnumerable source) + => source.source.Span.Count(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemoryValueEnumerable source) => source.source.Span.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemoryValueEnumerable source) @@ -337,7 +341,7 @@ public static long Sum(this MemoryValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this MemoryValueEnumerable source) @@ -345,7 +349,7 @@ public static float Sum(this MemoryValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this MemoryValueEnumerable source) @@ -353,7 +357,7 @@ public static double Sum(this MemoryValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this MemoryValueEnumerable source) @@ -361,7 +365,7 @@ public static decimal Sum(this MemoryValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool ContainsVector(this MemoryValueEnumerable source, TSource value) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs new file mode 100644 index 000000000..7979c5119 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -0,0 +1,295 @@ +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ArrayExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SpanValueEnumerable AsValueEnumerable(this ReadOnlySpan source) + => new(source); + + [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] + public readonly ref struct SpanValueEnumerable + { + internal readonly ReadOnlySpan source; + + internal SpanValueEnumerable(ReadOnlySpan source) + => this.source = source; + + public readonly int Count + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source.Length; + } + + public readonly TSource this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly SpanEnumerator GetEnumerator() + => new(source); + + #region Aggregation + + #endregion + + #region Conversion + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanValueEnumerable AsEnumerable() + => this; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanValueEnumerable AsValueEnumerable() + => this; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ReadOnlySpan ToArray() + => source.ToArray(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IMemoryOwner ToArray(MemoryPool memoryPool) + => source.ToArray(memoryPool); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => source.ToList(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) + where TKey : notnull + => source.ToDictionary(keySelector, comparer); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) + where TKey : notnull + where TKeySelector : struct, IFunction + => source.ToDictionary(keySelector, comparer); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) + where TKey : notnull + => source.ToDictionary(keySelector, elementSelector, comparer); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) + where TKey : notnull + where TKeySelector : struct, IFunction + where TElementSelector : struct, IFunction + => source.ToDictionary(keySelector, elementSelector, comparer); + + #endregion + + #region Element + + public Option ElementAt(int index) + => source.ElementAt(index); + + public Option First() + => source.First(); + + public Option Single() + => source.Single(); + + #endregion + + #region Filtering + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanWhereEnumerable> Where(Func predicate) + => source.Where(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanWhereEnumerable Where(TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.Where(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanWhereAtEnumerable> Where(Func predicate) + => source.Where(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanWhereAtEnumerable WhereAt(TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.WhereAt(predicate); + + #endregion + + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanValueEnumerable Skip(int count) + => new(source.Skip(count)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanValueEnumerable Take(int count) + => new(source.Take(count)); + + #endregion + + #region Projection + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanSelectEnumerable> Select(Func selector) + => source.Select(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanSelectEnumerable Select(TSelector selector = default) + where TSelector : struct, IFunction + => source.Select(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanSelectAtEnumerable> Select(Func selector) + => source.Select(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanSelectAtEnumerable SelectAt(TSelector selector = default) + where TSelector : struct, IFunction + => source.SelectAt(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanSelectManyEnumerable> SelectMany(Func selector) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + => source.SelectMany(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanSelectManyEnumerable SelectMany(TSelector selector = default) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.SelectMany(selector); + + #endregion + + #region Quantifier + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool All(Func predicate) + => All(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool All(TPredicate predicate) + where TPredicate : struct, IFunction + => source.All(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool All(Func predicate) + => source.All(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool AllAt(TPredicate predicate) + where TPredicate : struct, IFunction + => source.AllAt(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Any() + => source.Any(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Any(Func predicate) + => source.Any(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Any(TPredicate predicate) + where TPredicate : struct, IFunction + => source.Any(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Any(Func predicate) + => source.Any(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool AnyAt(TPredicate predicate) + where TPredicate : struct, IFunction + => source.AnyAt(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TSource value, IEqualityComparer? comparer = null) + => source.Contains(value, comparer); + + #endregion + + #region Set + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanDistinctEnumerable Distinct(IEqualityComparer? comparer = default) + => source.Distinct(comparer); + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SpanValueEnumerable source) + => source.source.Count(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool ContainsVector(this SpanValueEnumerable source, TSource value) + where TSource : struct + => source.source.ContainsVector(value); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this SpanValueEnumerable source, Func, Vector> vectorSelector, Func selector) + where TSource : struct + where TResult : struct + => source.source.SelectVector(vectorSelector, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SpanSelectVectorContext SelectVector(this SpanValueEnumerable source, TVectorSelector vectorSelector = default, TSelector selector = default) + where TVectorSelector : struct, IFunction, Vector> + where TSelector : struct, IFunction + where TSource : struct + where TResult : struct + => source.source.SelectVector(vectorSelector, selector); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs similarity index 51% rename from NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs index f1d3b148b..d35dcce67 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs @@ -1,14 +1,13 @@ using System; -using System.Buffers; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IMemoryOwner ToArray(this Span source, MemoryPool pool) - => ((ReadOnlySpan)source).ToArray(pool); + public static SpanValueEnumerable AsValueEnumerable(this Span source) + => ((ReadOnlySpan)source).AsValueEnumerable(); } -} - +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index bcb11041b..0ffe8c2a9 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -6,11 +6,11 @@ namespace NetFabric.Hyperlinq { - public static partial class ArrayExtensions + static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool) + static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool) { return source switch { diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs new file mode 100644 index 000000000..e6559fa4f --- /dev/null +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs @@ -0,0 +1,220 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ArrayExtensions + { + + [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static SpanSelectManyEnumerable> SelectMany(this ReadOnlySpan source, Func selector) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + => source.SelectMany>(new FunctionWrapper(selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static SpanSelectManyEnumerable SelectMany(this ReadOnlySpan source, TSelector selector = default) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => new(source, selector); + + [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] + public readonly ref struct SpanSelectManyEnumerable + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + { + readonly ReadOnlySpan source; + readonly TSelector selector; + + internal SpanSelectManyEnumerable(ReadOnlySpan source, TSelector selector) + { + this.source = source; + this.selector = selector; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly Enumerator GetEnumerator() + => new(this); + + [StructLayout(LayoutKind.Auto)] + public ref struct Enumerator + { + readonly ReadOnlySpan source; + TSelector selector; + readonly int end; + EnumeratorState state; + int sourceIndex; + [SuppressMessage("Style", "IDE0044:Add readonly modifier")] + TSubEnumerator subEnumerator; // do not make readonly + + internal Enumerator(SpanSelectManyEnumerable enumerable) + { + source = enumerable.source; + selector = enumerable.selector; + state = EnumeratorState.Enumerating; + sourceIndex = -1; + end = sourceIndex + enumerable.source.Length; + subEnumerator = default; + } + + public readonly TResult Current + => subEnumerator.Current; + + public bool MoveNext() + { + switch (state) + { + case EnumeratorState.Enumerating: + if (++sourceIndex >= end) + { + state = EnumeratorState.Complete; + return false; + } + + var enumerable = selector.Invoke(source[sourceIndex]); + subEnumerator = enumerable.GetEnumerator(); + + state = EnumeratorState.EnumeratingSub; + goto case EnumeratorState.EnumeratingSub; + + case EnumeratorState.EnumeratingSub: + if (!subEnumerator.MoveNext()) + { + state = EnumeratorState.Enumerating; + goto case EnumeratorState.Enumerating; + } + return true; + + default: + return false; + } + } + + [ExcludeFromCodeCoverage] + public readonly void Reset() + => throw new NotSupportedException(); + + public void Dispose() + => subEnumerator.Dispose(); + } +/* + #region Aggregation + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly int Count() + => this.Count, Enumerator, TResult>(); + + #endregion + #region Quantifier + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Any() + => this.Any, Enumerator, TResult>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Any(Func predicate) + => this.Any, Enumerator, TResult>(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Any(TPredicate predicate = default) + where TPredicate : struct, IFunction + => this.Any, Enumerator, TResult, TPredicate>(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Any(Func predicate) + => this.Any, Enumerator, TResult>(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool AnyAt(TPredicate predicate = default) + where TPredicate : struct, IFunction + => this.AnyAt, Enumerator, TResult, TPredicate>(predicate); + + #endregion + #region Filtering + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) + where TPredicate : struct, IFunction + => ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(System.Func predicate) + => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) + where TPredicate : struct, IFunction + => ValueEnumerableExtensions.Where, Enumerator, TResult, TPredicate>(this, predicate); + + #endregion + #region Projection + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) + where TSelector2 : struct, IFunction + => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2, TSelector2>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) + where TSelector2 : struct, IFunction + => ValueEnumerableExtensions.SelectAt, Enumerator, TResult, TResult2, TSelector2>(this, selector); + + #endregion + #region Element + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Option ElementAt(int index) + => this.ElementAt, Enumerator, TResult>(index); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Option First() + => this.First, Enumerator, TResult>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Option Single() + => this.Single, Enumerator, TResult>(); + + #endregion + #region Conversion + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.AsyncValueEnumerableWrapper, Enumerator, TResult> AsAsyncValueEnumerable() + => ValueEnumerableExtensions.AsAsyncValueEnumerable, Enumerator, TResult>(this); + + #endregion + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.SkipEnumerable, Enumerator, TResult> Skip(int count) + => ValueEnumerableExtensions.Skip, Enumerator, TResult>(this, count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.TakeEnumerable, Enumerator, TResult> Take(int count) + => ValueEnumerableExtensions.Take, Enumerator, TResult>(this, count); + + #endregion +*/ + } + } +} + From cd74cd237350d6cc7194fbed7d7f6ec57070a3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Tue, 2 Mar 2021 22:07:34 +0000 Subject: [PATCH 07/61] Add missing operator overloads (#339) --- .../Benchmarks/AllBenchmarks.cs | 2 +- .../Benchmarks/ContainsComparerBenchmarks.cs | 2 +- .../Benchmarks/DistinctBenchmarks.cs | 2 +- .../Benchmarks/ElementAtBenchmarks.cs | 2 +- .../Benchmarks/FirstBenchmarks.cs | 2 +- .../Benchmarks/SelectBenchmarks.cs | 4 +- .../Benchmarks/SelectCountBenchmarks.cs | 2 +- .../Benchmarks/SelectSumBenchmarks.cs | 4 +- .../Benchmarks/SelectToArrayBenchmarks.cs | 4 +- .../Benchmarks/SelectToListBenchmarks.cs | 2 +- .../Benchmarks/SingleBenchmarks.cs | 2 +- .../Benchmarks/SkipTakeBenchmarks.cs | 6 +- .../Benchmarks/ToListBenchmarks.cs | 2 +- .../Benchmarks/WhereBenchmarks.cs | 2 +- .../Benchmarks/WhereCountBenchmarks.cs | 2 +- .../Benchmarks/WhereFirstBenchmarks.cs | 2 +- .../Benchmarks/WhereSelectBenchmarks.cs | 2 +- .../Benchmarks/WhereSelectCountBenchmarks.cs | 2 +- .../Benchmarks/WhereSingleBenchmarks.cs | 2 +- .../Benchmarks/WhereToArrayBenchmarks.cs | 2 +- .../Benchmarks/WhereToListBenchmarks.cs | 2 +- .../Utils/TestCollection.cs | 12 +- .../Utils/TestList.cs | 28 +- .../Source/Distinct.ValueEnumerable.cs | 2 +- .../TestData/Source/Where.ArraySegment.cs | 2 +- .../TestData/Source/Where.ValueEnumerable.cs | 2 +- .../Aggregation/Count/Count.Array.Tests.cs | 29 -- .../Count/Count.ArraySegment.Tests.cs | 97 ---- .../Aggregation/Count/Count.Memory.Tests.cs | 70 --- .../Count/Count.ReadOnlyList.Tests.cs | 18 +- .../Count/Count.ReadOnlyMemory.Tests.cs | 70 --- .../Count/Count.ReadOnlySpan.Tests.cs | 21 +- .../Count/Count.ValueEnumerable.Tests.cs | 24 +- .../Count.ValueReadOnlyCollection.Tests.cs | 4 +- .../CountAsync.AsyncValueEnumerable.Tests.cs | 23 +- .../Aggregation/Sum.TestData.cs | 32 ++ .../Aggregation/Sum/Sum.Array.Tests.cs | 66 --- .../Aggregation/Sum/Sum.ReadOnlyList.Tests.cs | 34 +- .../Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs | 47 ++ .../Sum/Sum.ValueEnumerable.Tests.cs | 44 +- .../Sum/Sum.ValueReadOnlyCollection.Tests.cs | 46 ++ ...ncValueEnumerable.ValueEnumerable.Tests.cs | 35 +- .../Conversion/ToArray/ToArray.Array.Tests.cs | 52 -- .../ToArray/ToArray.ArraySegment.Tests.cs | 331 ------------ .../ToArray/ToArray.Memory.Tests.cs | 276 ---------- .../ToArray/ToArray.ReadOnlyList.Tests.cs | 48 +- .../ToArray/ToArray.ReadOnlyMemory.Tests.cs | 276 ---------- .../ToArray/ToArray.ReadOnlySpan.Tests.cs | 77 +-- .../ToArray/ToArray.ValueEnumerable.Tests.cs | 100 ++-- .../ToArray.ValueReadOnlyCollection.Tests.cs | 30 +- ...ToArrayAsync.AsyncValueEnumerable.Tests.cs | 97 ++-- .../Conversion/ToList/ToList.Array.Tests.cs | 32 -- .../ToList/ToList.ArraySegment.Tests.cs | 193 ------- .../ToList/ToList.Enumerable.Tests.cs | 59 --- .../Conversion/ToList/ToList.Memory.Tests.cs | 149 ------ .../ToList/ToList.ReadOnlyCollection.Tests.cs | 59 --- .../ToList/ToList.ReadOnlyList.Tests.cs | 30 +- .../ToList/ToList.ReadOnlyMemory.Tests.cs | 149 ------ .../ToList/ToList.ReadOnlySpan.Tests.cs | 56 ++- .../ToList/ToList.ValueEnumerable.Tests.cs | 52 +- .../ToList.ValueReadOnlyCollection.Tests.cs | 18 +- .../ToListAsync.AsyncEnumerable.Tests.cs | 36 -- .../ToListAsync.AsyncValueEnumerable.Tests.cs | 48 +- .../Element/ElementAt.TestData.cs | 16 +- .../ElementAt/ElementAt.Array.Tests.cs | 52 -- .../ElementAt/ElementAt.ArraySegment.Tests.cs | 374 -------------- .../ElementAt/ElementAt.Memory.Tests.cs | 304 ----------- .../ElementAt.ReadOnlyMemory.Tests.cs | 304 ----------- .../ElementAt/ElementAt.ReadOnlySpan.Tests.cs | 108 ++-- .../Element/First/First.Array.Tests.cs | 45 -- .../Element/First/First.ArraySegment.Tests.cs | 297 ----------- .../Element/First/First.Memory.Tests.cs | 237 --------- .../First/First.ReadOnlyMemory.Tests.cs | 237 --------- .../Element/First/First.ReadOnlySpan.Tests.cs | 60 ++- .../Element/Single/Single.Array.Tests.cs | 60 --- .../Single/Single.ArraySegment.Tests.cs | 471 ------------------ .../Element/Single/Single.Memory.Tests.cs | 333 ------------- .../Single/Single.ReadOnlyMemory.Tests.cs | 333 ------------- .../Single/Single.ReadOnlySpan.Tests.cs | 113 +++-- .../Filtering/Where/Where.Array.Tests.cs | 54 -- .../Where/Where.ArraySegment.Tests.cs | 45 +- .../Where/Where.AsyncValueEnumerable.Tests.cs | 32 +- .../Filtering/Where/Where.Memory.Tests.cs | 29 -- .../Where/Where.ReadOnlyList.Tests.cs | 34 +- .../Where/Where.ReadOnlyMemory.Tests.cs | 32 +- .../Where/Where.ReadOnlySpan.Tests.cs | 9 +- .../Where/Where.ValueEnumerable.Tests.cs | 33 +- .../Where.ValueReadOnlyCollection.Tests.cs | 55 ++ .../Filtering/WhereAt/WhereAt.Array.Tests.cs | 31 -- .../WhereAt/WhereAt.ArraySegment.Tests.cs | 31 +- .../WhereAt.AsyncValueEnumerable.Tests.cs | 32 +- .../Filtering/WhereAt/WhereAt.Memory.Tests.cs | 31 -- .../WhereAt/WhereAt.ReadOnlyList.Tests.cs | 31 +- .../WhereAt/WhereAt.ReadOnlyMemory.Tests.cs | 31 +- .../WhereAt/WhereAt.ReadOnlySpan.Tests.cs | 9 +- .../WhereAt/WhereAt.ValueEnumerable.Tests.cs | 31 +- .../WhereAt.ValueReadOnlyCollection.Tests.cs | 55 ++ .../WhereSelect/WhereSelect.Array.Tests.cs | 33 -- .../WhereSelect.ArraySegment.Tests.cs | 41 +- .../WhereSelect.AsyncValueEnumerable.Tests.cs | 36 +- .../WhereSelect/WhereSelect.Memory.Tests.cs | 32 -- .../WhereSelect.ReadOnlyList.Tests.cs | 32 +- .../WhereSelect.ReadOnlyMemory.Tests.cs | 36 +- .../WhereSelect.ReadOnlySpan.Tests.cs | 36 +- .../WhereSelect.ValueEnumerable.Tests.cs | 35 +- ...ereSelect.ValueReadOnlyCollection.Tests.cs | 57 +++ .../Partitioning/Skip.TestData.cs | 16 +- .../Partitioning/Skip/Skip.Array.Tests.cs | 29 -- .../Skip/Skip.ArraySegment.Tests.cs | 32 -- .../Skip/Skip.AsyncValueEnumerable.Tests.cs | 24 +- .../Partitioning/Skip/Skip.Memory.Tests.cs | 31 -- .../Skip/Skip.ReadOnlyList.Tests.cs | 31 -- .../Skip/Skip.ReadOnlyMemory.Tests.cs | 29 -- .../Skip/Skip.ReadOnlySpan.Tests.cs | 29 -- .../Skip/Skip.ValueEnumerable.Tests.cs | 24 +- .../Skip.ValueReadOnlyCollection.Tests.cs | 4 +- .../Partitioning/SkipTake.TestData.cs | 16 +- .../Partitioning/Take.TestData.cs | 24 +- .../Partitioning/Take/Take.Array.Tests.cs | 29 -- .../Take/Take.ArraySegment.Tests.cs | 32 -- .../Take/Take.AsyncValueEnumerable.Tests.cs | 16 +- .../Partitioning/Take/Take.Memory.Tests.cs | 31 -- .../Take/Take.ReadOnlyList.Tests.cs | 31 -- .../Take/Take.ReadOnlyMemory.Tests.cs | 29 -- .../Take/Take.ReadOnlySpan.Tests.cs | 29 -- .../Take/Take.ValueEnumerable.Tests.cs | 16 +- .../Take.ValueReadOnlyCollection.Tests.cs | 4 +- .../Projection/Select/Select.Array.Tests.cs | 31 -- .../Select/Select.ArraySegment.Tests.cs | 36 +- .../Select.AsyncValueEnumerable.Tests.cs | 32 +- .../Projection/Select/Select.Memory.Tests.cs | 30 -- .../Select/Select.ReadOnlyList.Tests.cs | 34 +- .../Select/Select.ReadOnlyMemory.Tests.cs | 30 +- .../Select/Select.ReadOnlySpan.Tests.cs | 31 +- .../Select/Select.ValueEnumerable.Tests.cs | 31 +- .../Select.ValueReadOnlyCollection.Tests.cs | 30 +- .../SelectAt/SelectAt.Array.Tests.cs | 31 -- .../SelectAt/SelectAt.ArraySegment.Tests.cs | 35 +- .../SelectAt.AsyncValueEnumerable.Tests.cs | 32 +- .../SelectAt/SelectAt.Memory.Tests.cs | 30 -- .../SelectAt/SelectAt.ReadOnlyList.Tests.cs | 31 +- .../SelectAt/SelectAt.ReadOnlyMemory.Tests.cs | 31 +- .../SelectAt/SelectAt.ReadOnlySpan.Tests.cs | 31 +- .../SelectAt.ValueEnumerable.Tests.cs | 32 +- .../SelectAt.ValueReadOnlyCollection.Tests.cs | 27 +- .../Projection/SelectVector.TestData.cs | 26 +- .../SelectVector/SelectVector.ArraySegment.cs | 31 -- .../SelectVector.ReadOnlyMemory.Tests.cs | 31 -- .../SelectVector.ReadOnlySpan.Tests.cs | 7 +- .../Quantifier/All/All.Array.Tests.cs | 49 -- .../Quantifier/All/All.ArraySegment.Tests.cs | 68 --- .../All/All.AsyncValueEnumerable.Tests.cs | 20 +- .../Quantifier/All/All.Memory.Tests.cs | 47 -- .../Quantifier/All/All.ReadOnlyList.Tests.cs | 36 +- .../All/All.ReadOnlyMemory.Tests.cs | 47 -- .../Quantifier/All/All.ReadOnlySpan.Tests.cs | 21 +- .../All/All.ValueEnumerable.Tests.cs | 18 +- .../All/All.ValueReadOnlyCollection.Tests.cs | 14 +- .../Quantifier/Any/Any.Array.Tests.cs | 69 --- .../Quantifier/Any/Any.ArraySegment.Tests.cs | 106 ---- .../Any/Any.AsyncValueEnumerable.Tests.cs | 32 +- .../Quantifier/Any/Any.Memory.Tests.cs | 68 --- .../Quantifier/Any/Any.ReadOnlyList.Tests.cs | 46 +- .../Any/Any.ReadOnlyMemory.Tests.cs | 68 --- .../Quantifier/Any/Any.ReadOnlySpan.Tests.cs | 29 +- .../Any/Any.ValueEnumerable.Tests.cs | 24 +- .../Any/Any.ValueReadOnlyCollection.Tests.cs | 12 +- .../Contains/Contains.Array.Tests.cs | 153 ------ .../Contains/Contains.ArraySegment.Tests.cs | 182 ------- .../Contains.AsyncValueEnumerable.Tests.cs | 56 ++- .../Contains/Contains.Memory.Tests.cs | 153 ------ .../Contains/Contains.ReadOnlyList.Tests.cs | 50 +- .../Contains/Contains.ReadOnlyMemory.Tests.cs | 153 ------ .../Contains/Contains.ReadOnlySpan.Tests.cs | 57 ++- .../Contains.ValueEnumerable.Tests.cs | 56 ++- .../Contains.ValueReadOnlyCollection.Tests.cs | 25 +- .../ContainsVector.ReadOnlySpan.Tests.cs | 12 +- .../Set/Distinct/Distinct.Array.Tests.cs | 121 ----- .../Distinct/Distinct.ArraySegment.Tests.cs | 59 ++- .../Distinct.AsyncValueEnumerable.Tests.cs | 61 ++- .../Set/Distinct/Distinct.Memory.Tests.cs | 97 ---- .../Distinct/Distinct.ReadOnlyList.Tests.cs | 43 +- .../Distinct/Distinct.ReadOnlyMemory.Tests.cs | 62 ++- .../Distinct/Distinct.ReadOnlySpan.Tests.cs | 37 +- .../Distinct.ValueEnumerable.Tests.cs | 54 +- .../Utils/Wrappers/Wrap.AsAsyncEnumerable.cs | 10 +- .../Wrappers/Wrap.AsAsyncValueEnumerable.cs | 12 +- .../Utils/Wrappers/Wrap.AsCollection.cs | 8 +- .../Utils/Wrappers/Wrap.AsEnumerable.cs | 10 +- .../Utils/Wrappers/Wrap.AsList.cs | 8 +- .../Wrappers/Wrap.AsReadOnlyCollection.cs | 8 +- .../Utils/Wrappers/Wrap.AsReadOnlyList.cs | 8 +- .../Utils/Wrappers/Wrap.AsValueCollection.cs | 10 +- .../Utils/Wrappers/Wrap.AsValueEnumerable.cs | 15 +- .../Utils/Wrappers/Wrap.AsValueList.cs | 10 +- .../Wrap.AsValueReadOnlyCollection.cs | 10 +- .../Wrappers/Wrap.AsValueReadOnlyList.cs | 10 +- .../Utils/Wrappers/Wrap.AsyncEnumerator.cs | 2 +- .../Aggregation/Sum/Sum.ValueEnumerable.cs | 2 +- .../Sum/Sum.ValueReadOnlyCollection.cs | 44 ++ .../Sum/SumAsync.AsyncValueEnumerable.cs | 148 ++++++ .../AsAsyncValueEnumerable.AsyncEnumerable.cs | 1 - .../AsValueEnumerable'1.ReadOnlyCollection.cs | 40 ++ .../AsValueEnumerable.ArraySegment.cs | 20 +- .../AsValueEnumerable.ReadOnlyMemory.cs | 15 +- .../AsValueEnumerable.ReadOnlySpan.cs | 7 +- .../ToArray/ToArray.ReadOnlyList.cs | 5 - .../ToDictionary/ToDictionary.ReadOnlySpan.cs | 8 +- .../ToDictionary/ToDictionary.Span.cs | 35 -- .../Conversion/ToList/ToList.ReadOnlySpan.cs | 2 +- .../Conversion/ToList/ToList.Span.cs | 14 - .../ElementAt/ElementAt.ReadOnlyList.cs | 2 +- .../ElementAt/ElementAt.ReadOnlySpan.cs | 2 +- .../Element/ElementAt/ElementAt.Span.cs | 14 - .../Element/First/First.ReadOnlyList.cs | 2 +- .../Element/First/First.ReadOnlySpan.cs | 2 +- .../Element/First/First.Span.cs | 13 - .../Element/Single/Single.ReadOnlyList.cs | 2 +- .../Element/Single/Single.ReadOnlySpan.cs | 2 +- .../Element/Single/Single.Span.cs | 14 - .../Where/Where/Where.ArraySegment.cs | 4 +- .../Where/Where/Where.AsyncValueEnumerable.cs | 74 ++- .../Where/Where/Where.ReadOnlyList.cs | 68 ++- .../Where/Where/Where.ReadOnlyMemory.cs | 4 +- .../Where/Where/Where.ReadOnlySpan.cs | 4 +- .../Filtering/Where/Where/Where.Span.cs | 20 - .../Where/Where/Where.ValueEnumerable.cs | 138 ++--- .../Where/Where.ValueReadOnlyCollection.cs | 138 ++--- .../Where/WhereAt/WhereAt.ArraySegment.cs | 4 +- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 74 ++- .../Where/WhereAt/WhereAt.ReadOnlyList.cs | 68 ++- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 4 +- .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 4 +- .../Filtering/Where/WhereAt/WhereAt.Span.cs | 20 - .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 138 ++--- .../WhereAt.ValueReadOnlyCollection.cs | 138 ++--- .../WhereSelect/WhereSelect.ArraySegment.cs | 2 +- .../WhereSelect.AsyncValueEnumerable.cs | 86 +++- .../WhereSelect/WhereSelect.ReadOnlyList.cs | 80 ++- .../WhereSelect.ValueEnumerable.cs | 86 +++- .../WhereSelect.ValueReadOnlyCollection.cs | 86 +++- .../Generation/AsyncValueEnumerable/Empty.cs | 11 +- .../Generation/ValueEnumerable/Empty.cs | 2 +- .../Partitioning/Skip/Skip.Memory.cs | 16 - .../Partitioning/Skip/Skip.ReadOnlyMemory.cs | 16 - .../Partitioning/Skip/Skip.ReadOnlySpan.cs | 16 - .../Partitioning/Skip/Skip.Span.cs | 16 - .../SkipTake.ValueReadOnlyCollection.cs | 7 +- .../Partitioning/Take/Take.ReadOnlyMemory.cs | 13 - .../Partitioning/Take/Take.ReadOnlySpan.cs | 13 - .../Partitioning/Take/Take.Span.cs | 13 - .../Select/Select/Select.ArraySegment.cs | 4 +- .../Select/Select.AsyncValueEnumerable.cs | 74 ++- .../Select/Select/Select.ReadOnlyList.cs | 69 ++- .../Select/Select/Select.ReadOnlyMemory.cs | 4 +- .../Select/Select/Select.ReadOnlySpan.cs | 4 +- .../Projection/Select/Select/Select.Span.cs | 19 - .../Select/Select/Select.ValueEnumerable.cs | 74 ++- .../Select/Select.ValueReadOnlyCollection.cs | 74 ++- .../Select/SelectAt/SelectAt.ArraySegment.cs | 4 +- .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 74 ++- .../Select/SelectAt/SelectAt.ReadOnlyList.cs | 66 ++- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 4 +- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 4 +- .../Select/SelectAt/SelectAt.Span.cs | 20 - .../SelectAt/SelectAt.ValueEnumerable.cs | 74 ++- .../SelectAt.ValueReadOnlyCollection.cs | 74 ++- .../SelectVector/SelectVector.ArraySegment.cs | 40 -- .../SelectVector/SelectVector.Memory.cs | 36 -- .../SelectVector.ReadOnlyMemory.cs | 135 ----- .../SelectVector/SelectVector.ReadOnlySpan.cs | 6 +- .../Select/SelectVector/SelectVector.Span.cs | 36 -- .../SelectMany/SelectMany.ArraySegment.cs | 74 ++- .../SelectMany/SelectMany.ReadOnlyList.cs | 84 +++- .../SelectMany/SelectMany.ReadOnlyMemory.cs | 74 ++- .../SelectMany/SelectMany.ReadOnlySpan.cs | 75 ++- .../SelectMany/SelectMany.ValueEnumerable.cs | 90 ++++ .../Quantifier/All/All.ReadOnlyList.cs | 23 - .../Quantifier/All/All.ReadOnlySpan.cs | 8 +- .../Quantifier/All/All.Span.cs | 29 -- .../Contains/Contains.Enumerable.cs | 22 +- .../Contains/Contains.ReadOnlyList.cs | 12 +- .../Contains/Contains.ReadOnlySpan.cs | 2 +- .../Quantifier/Contains/Contains.Span.cs | 17 - .../Contains/Contains.ValueEnumerable.cs | 4 +- .../Set/Distinct/Distinct.ArraySegment.cs | 42 +- .../Distinct/Distinct.AsyncValueEnumerable.cs | 60 +++ .../Set/Distinct/Distinct.ReadOnlyList.cs | 52 +- .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 42 +- .../Set/Distinct/Distinct.ReadOnlySpan.cs | 2 +- .../Set/Distinct/Distinct.Span.cs | 15 - .../Set/Distinct/Distinct.ValueEnumerable.cs | 60 +++ NetFabric.Hyperlinq/Set/Distinct/Set.cs | 24 +- NetFabric.Hyperlinq/Utils/GenericsOperator.cs | 4 + NetFabric.Hyperlinq/Utils/ListExtensions.cs | 19 +- .../Utils/Utils.AllocateUninitializedArray.cs | 2 +- 296 files changed, 4815 insertions(+), 9378 deletions(-) delete mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyMemory.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.Array.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Enumerable.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyCollection.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncEnumerable.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/First/First.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/First/First.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/First/First.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Memory.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Memory.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Memory.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlySpan.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlySpan.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ArraySegment.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.Memory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyMemory.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Array.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Memory.Tests.cs create mode 100644 NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.Span.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/ToList/ToList.Span.cs delete mode 100644 NetFabric.Hyperlinq/Element/ElementAt/ElementAt.Span.cs delete mode 100644 NetFabric.Hyperlinq/Element/First/First.Span.cs delete mode 100644 NetFabric.Hyperlinq/Element/Single/Single.Span.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/Where/Where/Where.Span.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.Span.cs delete mode 100644 NetFabric.Hyperlinq/Partitioning/Skip/Skip.Memory.cs delete mode 100644 NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyMemory.cs delete mode 100644 NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlySpan.cs delete mode 100644 NetFabric.Hyperlinq/Partitioning/Skip/Skip.Span.cs delete mode 100644 NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyMemory.cs delete mode 100644 NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlySpan.cs delete mode 100644 NetFabric.Hyperlinq/Partitioning/Take/Take.Span.cs delete mode 100644 NetFabric.Hyperlinq/Projection/Select/Select/Select.Span.cs delete mode 100644 NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.Span.cs delete mode 100644 NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Memory.cs delete mode 100644 NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlyMemory.cs delete mode 100644 NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Span.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/All/All.Span.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/Contains/Contains.Span.cs delete mode 100644 NetFabric.Hyperlinq/Set/Distinct/Distinct.Span.cs diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs index 57aa1d4aa..91f301ab0 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs @@ -65,7 +65,7 @@ public bool Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public bool Hyperlinq_Span() - => array.AsSpan().All(_ => true); + => array.AsSpan().AsValueEnumerable().All(_ => true); [BenchmarkCategory("Array")] [Benchmark] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs index 3b6058aa3..7984aa4f1 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs @@ -66,7 +66,7 @@ public bool Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public bool Hyperlinq_Span() - => array.AsSpan().Contains(Count - 1, this); + => array.AsSpan().AsValueEnumerable().Contains(Count - 1, this); [BenchmarkCategory("Array")] [Benchmark] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs index 6bffda85d..0c5b8a7e5 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs @@ -190,7 +190,7 @@ public int Hyperlinq_Array() public int Hyperlinq_Span() { var sum = 0; - foreach (ref readonly var item in array.AsSpan().Distinct()) + foreach (ref readonly var item in array.AsSpan().AsValueEnumerable().Distinct()) sum += item; return sum; } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs index 6a12cf57f..aaca139ed 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs @@ -65,7 +65,7 @@ public Option Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public Option Hyperlinq_Span() - => array.AsSpan().ElementAt(Count - 1); + => array.AsSpan().AsValueEnumerable().ElementAt(Count - 1); [BenchmarkCategory("Array")] [Benchmark] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs index a414a24c2..3144972a9 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs @@ -65,7 +65,7 @@ public Option Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public Option Hyperlinq_Span() - => array.AsSpan().First(); + => array.AsSpan().AsValueEnumerable().First(); [BenchmarkCategory("Array")] [Benchmark] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs index ff7057fea..333b4d398 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs @@ -181,7 +181,7 @@ public int StructLinq_Array() [Benchmark] public int Hyperlinq_Span_For() { - var source = array.AsSpan().Select(item => item); + var source = array.AsSpan().AsValueEnumerable().Select(item => item); var sum = 0; for (var index = 0; index < source.Count; index++) sum += source[index]; @@ -194,7 +194,7 @@ public int Hyperlinq_Span_For() public int Hyperlinq_Span_Foreach() { var sum = 0; - foreach (var item in array.AsSpan().Select(item => item)) + foreach (var item in array.AsSpan().AsValueEnumerable().Select(item => item)) sum += item; return sum; } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs index 3dafd674d..0f5dacde4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs @@ -135,7 +135,7 @@ public int Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .Select(item => item) .Count(); diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs index b0d70fc17..d97ed313a 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs @@ -135,14 +135,14 @@ public int Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .Select(item => item) .Sum(); [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Span_SIMD() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .SelectVector(item => item, item => item) .Sum(); diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs index 8c80563b4..7b9dc4ba9 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs @@ -125,14 +125,14 @@ public int[] Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public int[] Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .Select(item => item) .ToArray(); [BenchmarkCategory("Array")] [Benchmark] public int[] Hyperlinq_Span_SIMD() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .SelectVector(item => item, item => item) .ToArray(); diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs index f5f3f0b00..c26e8c1af 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs @@ -117,7 +117,7 @@ public List Hyperlinq_List() [BenchmarkCategory("Array")] [Benchmark] public List Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .Select(item => item) .ToList(); diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs index 37f289a4e..7ebee45e4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs @@ -70,7 +70,7 @@ public Option Hyperlinq_Array() => [BenchmarkCategory("Array")] [Benchmark] public Option Hyperlinq_Span() => - array.AsSpan().Single(); + array.AsSpan().AsValueEnumerable().Single(); [BenchmarkCategory("Array")] [Benchmark] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs index 8164ffcd7..418f6167d 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs @@ -207,9 +207,9 @@ public int Hyperlinq_Array_Foreach() [Benchmark] public int Hyperlinq_Span_For() { - var source = array.AsSpan().Skip(Skip).Take(Count); + var source = array.AsSpan().AsValueEnumerable().Skip(Skip).Take(Count); var sum = 0; - for (var index = 0; index < source.Length; index++) + for (var index = 0; index < source.Count; index++) { var item = source[index]; sum += item; @@ -223,7 +223,7 @@ public int Hyperlinq_Span_For() public int Hyperlinq_Span_Foreach() { var sum = 0; - foreach (var item in array.AsSpan().Skip(Skip).Take(Count)) + foreach (var item in array.AsSpan().AsValueEnumerable().Skip(Skip).Take(Count)) sum += item; return sum; } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs index 40f4d1cc5..15c53fed8 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs @@ -109,7 +109,7 @@ public List Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public List Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .ToList(); [BenchmarkCategory("Array")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs index 91318d825..14a4becd7 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs @@ -169,7 +169,7 @@ public int Hyperlinq_Array() public int Hyperlinq_Span() { var sum = 0; - foreach (var item in array.AsSpan().Where(item => (item & 0x01) == 0)) + foreach (var item in array.AsSpan().AsValueEnumerable().Where(item => (item & 0x01) == 0)) sum += item; return sum; } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs index 4bcd791c3..b0d949950 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs @@ -126,7 +126,7 @@ public int Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .Where(item => (item & 0x01) == 0) .Count(); diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs index cb35b385d..73196c7ea 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs @@ -68,7 +68,7 @@ public Option Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public Option Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .Where(item => item == Count - 1) .First(); diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs index e78f79b0b..9be5c7fa5 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs @@ -169,7 +169,7 @@ public int Hyperlinq_Array() public int Hyperlinq_Span() { var sum = 0; - foreach (var item in array.AsSpan().Where(item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in array.AsSpan().AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item)) sum += item; return sum; } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs index 32c13291e..26b3d2736 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs @@ -68,7 +68,7 @@ public int Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Span() - => array.AsSpan().Where(item => (item & 0x01) == 0).Select(item => item).Count(); + => array.AsSpan().AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item).Count(); [BenchmarkCategory("Array")] [Benchmark] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs index a1453a9f4..ab8e704c2 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs @@ -68,7 +68,7 @@ public Option Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public Option Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .Where(item => item == Count - 1) .Single(); diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs index 6232152bf..ef2ba134b 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs @@ -135,7 +135,7 @@ public int[] Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public int[] Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .Where(item => (item & 0x01) == 0) .ToArray(); diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs index 27db6f63e..bea4a1859 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs @@ -136,7 +136,7 @@ public List Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] public List Hyperlinq_Span() - => array.AsSpan() + => array.AsSpan().AsValueEnumerable() .Where(item => (item & 0x01) == 0) .ToList(); diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs index 4d7637a40..c155c947f 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs @@ -23,9 +23,9 @@ public Enumerable(int[] array) public bool IsReadOnly => true; - public void Add(int item) => throw new NotImplementedException(); - public bool Remove(int item) => throw new NotImplementedException(); - public void Clear() => throw new NotImplementedException(); + public void Add(int item) => throw new NotSupportedException(); + public bool Remove(int item) => throw new NotSupportedException(); + public void Clear() => throw new NotSupportedException(); public bool Contains(int item) => ((IList)array).Contains(item); @@ -75,9 +75,9 @@ public EnumerableReferenceType(int[] array) public bool IsReadOnly => true; - public void Add(int item) => throw new NotImplementedException(); - public bool Remove(int item) => throw new NotImplementedException(); - public void Clear() => throw new NotImplementedException(); + public void Add(int item) => throw new NotSupportedException(); + public bool Remove(int item) => throw new NotSupportedException(); + public void Clear() => throw new NotSupportedException(); public bool Contains(int item) => ((IList)array).Contains(item); diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs index fefd2efa1..5e5f5f3a9 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs @@ -26,17 +26,17 @@ public Enumerable(int[] array) int IList.this[int index] { get => array[index]; - set => throw new NotImplementedException(); + set => throw new NotSupportedException(); } public bool IsReadOnly => true; - public void Add(int item) => throw new NotImplementedException(); - public bool Remove(int item) => throw new NotImplementedException(); - public void Clear() => throw new NotImplementedException(); - public int IndexOf(int item) => throw new NotImplementedException(); - public void Insert(int index, int item) => throw new NotImplementedException(); - public void RemoveAt(int index) => throw new NotImplementedException(); + public void Add(int item) => throw new NotSupportedException(); + public bool Remove(int item) => throw new NotSupportedException(); + public void Clear() => throw new NotSupportedException(); + public int IndexOf(int item) => throw new NotSupportedException(); + public void Insert(int index, int item) => throw new NotSupportedException(); + public void RemoveAt(int index) => throw new NotSupportedException(); public bool Contains(int item) => ((IList)array).Contains(item); @@ -89,17 +89,17 @@ public EnumerableReferenceType(int[] array) int IList.this[int index] { get => array[index]; - set => throw new NotImplementedException(); + set => throw new NotSupportedException(); } public bool IsReadOnly => true; - public void Add(int item) => throw new NotImplementedException(); - public bool Remove(int item) => throw new NotImplementedException(); - public void Clear() => throw new NotImplementedException(); - public int IndexOf(int item) => throw new NotImplementedException(); - public void Insert(int index, int item) => throw new NotImplementedException(); - public void RemoveAt(int index) => throw new NotImplementedException(); + public void Add(int item) => throw new NotSupportedException(); + public bool Remove(int item) => throw new NotSupportedException(); + public void Clear() => throw new NotSupportedException(); + public int IndexOf(int item) => throw new NotSupportedException(); + public void Insert(int index, int item) => throw new NotSupportedException(); + public void RemoveAt(int index) => throw new NotSupportedException(); public bool Contains(int item) => ((IList)array).Contains(item); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs index b13db620f..c4991b161 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs @@ -39,7 +39,7 @@ public struct DisposableEnumerator { public readonly TSource Current => default!; readonly TSource IEnumerator.Current => default!; - readonly object IEnumerator.Current => default; + readonly object? IEnumerator.Current => default; public bool MoveNext() => false; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs index 412d7ea1c..cbd69ba77 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs @@ -42,7 +42,7 @@ public struct DisposableEnumerator { public readonly TSource Current => default!; readonly TSource IEnumerator.Current => default!; - readonly object IEnumerator.Current => default; + readonly object? IEnumerator.Current => default; public bool MoveNext() => false; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs index 276648358..2db759a15 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs @@ -50,7 +50,7 @@ public struct DisposableEnumerator { public readonly TSource Current => default!; readonly TSource IEnumerator.Current => default!; - readonly object IEnumerator.Current => default; + readonly object? IEnumerator.Current => default; public bool MoveNext() => false; diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Array.Tests.cs deleted file mode 100644 index d63b48434..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Array.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Count -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Count_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = source - .Count(); - - // Act - var result = source.AsValueEnumerable() - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ArraySegment.Tests.cs deleted file mode 100644 index 401403a5f..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ArraySegment.Tests.cs +++ /dev/null @@ -1,97 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Count -{ - public class ArraySegmentTests - { - [Fact] - public void Count_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - - // Act - var result = source.AsValueEnumerable() - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(0); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Count_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Count(wrapped); - - // Act - var result = wrapped.AsValueEnumerable() - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Count(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Where(predicate) - .Count(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Memory.Tests.cs deleted file mode 100644 index c98625c28..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.Memory.Tests.cs +++ /dev/null @@ -1,70 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Count -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Count_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Count(source); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Count(source, predicate); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Count(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyList.Tests.cs index 05af30d92..2281b873c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyList.Tests.cs @@ -16,11 +16,11 @@ public void Count_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Count(source); + var expected = source + .Count(); // Act - var result = wrapped + var result = wrapped.AsValueEnumerable() .Count(); // Assert @@ -37,13 +37,13 @@ public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, int skip, // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Count(predicate); // Act - var result = wrapped + var result = wrapped.AsValueEnumerable() .Skip(skip) .Take(take) .Where(predicate) @@ -63,14 +63,14 @@ public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skip // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .Count(); // Act - var result = wrapped + var result = wrapped.AsValueEnumerable() .Skip(skip) .Take(take) .Where(predicate) diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyMemory.Tests.cs deleted file mode 100644 index d823342a3..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,70 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Count -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Count_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Count(source); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Count(source, predicate); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Count(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs index 496cb38b1..6d121cf48 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs @@ -14,11 +14,12 @@ public class ReadOnlySpanTests public void Count_With_ValidData_Must_Succeed(int[] source) { // Arrange - var expected = Enumerable - .Count(source); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Count(); // Act - var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + var result = wrapped.AsValueEnumerable() .Count(); // Assert @@ -33,12 +34,13 @@ public void Count_With_ValidData_Must_Succeed(int[] source) public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .Count(); // Act - var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + var result = wrapped.AsValueEnumerable() .Where(predicate) .Count(); @@ -54,12 +56,13 @@ public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .Count(); // Act - var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + var result = wrapped.AsValueEnumerable() .Where(predicate) .Count(); diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueEnumerable.Tests.cs index f2af69211..7c097e6ed 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueEnumerable.Tests.cs @@ -16,12 +16,12 @@ public void Count_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Count(source); + var expected = source + .Count(); // Act - var result = ValueEnumerableExtensions - .Count, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .Count, Wrap.Enumerator, int>(); // Assert _ = result.Must() @@ -37,12 +37,12 @@ public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Count(); // Assert @@ -59,13 +59,13 @@ public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Count(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs index a603b9077..c47749114 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs @@ -16,8 +16,8 @@ public void Count_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .Count(source); + var expected = source + .Count(); // Act var result = ValueReadOnlyCollectionExtensions diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs index ab051f465..6314766a4 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs @@ -17,12 +17,12 @@ public async ValueTask CountAsync_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Count(source); + var expected = source + .Count(); // Act - var result = await AsyncValueEnumerableExtensions - .CountAsync, Wrap.AsyncEnumerator, int>(wrapped); + var result = await wrapped + .CountAsync, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Must() @@ -38,12 +38,12 @@ public async ValueTask CountAsync_Predicate_With_ValidData_Must_Succeed(int[] so // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Count(source, predicate); + var expected = source + .Count(predicate); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .CountAsync(); // Assert @@ -60,12 +60,13 @@ public async ValueTask CountAsync_PredicateAt_With_ValidData_Must_Succeed(int[] // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable.Where(source, predicate) + var expected = source + .Where(predicate) .Count(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .CountAsync(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs new file mode 100644 index 000000000..dc7ab01f9 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs @@ -0,0 +1,32 @@ +using System; +using Xunit; + +namespace NetFabric.Hyperlinq +{ + public static partial class TestData + { + public static TheoryData Sum + => new() + { + { new int[] { } }, + { new[] { 1 } }, + { new[] { 1, 2, 3, 4, 5, 6, 7 } }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8 } }, // size of Vector + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 } }, + }; + + public static TheoryData NullableSum + => new() + { + { new int?[] { } }, + { new int?[] { null } }, + { new int?[] { 1 } }, + { new int?[] { null, null, null } }, + { new int?[] { null, 2, 3, 4, null } }, + { new int?[] { 1, 2, null, 4, 5 } }, + { new int?[] { 1, 2, 3, 4, 5 } }, + }; + + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.Array.Tests.cs deleted file mode 100644 index bfa15a431..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.Array.Tests.cs +++ /dev/null @@ -1,66 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum -{ - public class ArrayTests - { - public static TheoryData Sum => - new TheoryData - { - { new int[] { 1, 2, 3, 4, 5, 6, 7 } }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8 } }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 } }, - }; - - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - [MemberData(nameof(Sum))] - public void Sum_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Sum(source); - - // Act - var result = source.AsValueEnumerable() - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - public static TheoryData NullableSum => - new TheoryData - { - { new int?[] { null } }, - { new int?[] { null, null, null } }, - { new int?[] { null, 2, 3, 4, null } }, - { new int?[] { 1, 2, null, 4, 5 } }, - }; - - [Theory] - [MemberData(nameof(NullableSum))] - public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) - { - // Arrange - var expected = Enumerable - .Sum(source); - - // Act - var result = source.AsValueEnumerable() - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected.Value); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs index 10583cbbc..cdadb2af4 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs @@ -7,27 +7,14 @@ namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum { public class ReadOnlyListTests { - public static TheoryData Sum => - new TheoryData - { - { new int[] { 1, 2, 3, 4, 5, 6, 7 } }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8 } }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 } }, - }; - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - [MemberData(nameof(Sum))] + [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] public void Sum_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsList(source); - var expected = Enumerable - .Sum(source); + var expected = source + .Sum(); // Act var result = wrapped.AsValueEnumerable() @@ -38,23 +25,14 @@ public void Sum_With_ValidData_Must_Succeed(int[] source) .BeEqualTo(expected); } - public static TheoryData NullableSum => - new TheoryData - { - { new int?[] { null } }, - { new int?[] { null, null, null } }, - { new int?[] { null, 2, 3, 4, null } }, - { new int?[] { 1, 2, null, 4, 5 } }, - }; - [Theory] - [MemberData(nameof(NullableSum))] + [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) { // Arrange var wrapped = Wrap.AsList(source); - var expected = Enumerable - .Sum(source); + var expected = source + .Sum(); // Act var result = wrapped.AsValueEnumerable() diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs new file mode 100644 index 000000000..f9e885fbb --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs @@ -0,0 +1,47 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum +{ + public class ArrayTests + { + + [Theory] + [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] + public void Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] + public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected.Value); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs index 080b7a0b0..711a4b286 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs @@ -7,58 +7,36 @@ namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum { public class ValueEnumerableTests { - public static TheoryData Sum => - new TheoryData - { - { new int[] { 1, 2, 3, 4, 5, 6, 7 } }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8 } }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 } }, - }; - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - [MemberData(nameof(Sum))] + [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] public void Sum_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); - var expected = Enumerable - .Sum(source); + var expected = source + .Sum(); // Act - var result = wrapped.AsValueEnumerable() - .Sum(); + var result = wrapped + .Sum, Wrap.Enumerator, int, int>(); // Assert _ = result.Must() .BeEqualTo(expected); } - public static TheoryData NullableSum => - new TheoryData - { - { new int?[] { null } }, - { new int?[] { null, null, null } }, - { new int?[] { null, 2, 3, 4, null } }, - { new int?[] { 1, 2, null, 4, 5 } }, - }; - [Theory] - [MemberData(nameof(NullableSum))] + [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) { // Arrange - var wrapped = Wrap.AsList(source); - var expected = Enumerable - .Sum(source); + var wrapped = Wrap.AsValueEnumerable(source); + var expected = source + .Sum(); // Act - var result = wrapped.AsValueEnumerable() - .Sum(); + var result = wrapped + .Sum, Wrap.Enumerator, int?, int>(); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs new file mode 100644 index 000000000..5cffbe591 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs @@ -0,0 +1,46 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum +{ + public class ValueReadOnlyCollectionTests + { + [Theory] + [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] + public void Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyCollection(source); + var expected = source + .Sum(); + + // Act + var result = wrapped + .Sum, Wrap.Enumerator, int, int>(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] + public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyCollection(source); + var expected = source + .Sum(); + + // Act + var result = wrapped + .Sum, Wrap.Enumerator, int?, int>(); + + // Assert + _ = result.Must() + .BeEqualTo(expected.Value); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs index 8a94affd6..3d621bc3b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs @@ -20,38 +20,13 @@ public async ValueTask AsAsyncValueEnumerable_With_ValidData_Must_Succeed(int[] .AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .AsAsyncValueEnumerable, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .AsAsyncValueEnumerable, Wrap.Enumerator, int>(); // Assert - var enumerator = result.GetAsyncEnumerator(); - await using (enumerator.ConfigureAwait(false)) - { - var index = 0; - while (true) - { - var isResultCompleted = !await enumerator.MoveNextAsync(); - var isSourceCompleted = index == source.Length; - - if (isResultCompleted && isSourceCompleted) - return; - - if (isResultCompleted) - throw new Exception("'result' is shorter."); - - if (isSourceCompleted) - throw new Exception("'result' is longer."); - - if (!EqualityComparer.Default.Equals(enumerator.Current, source[index])) - throw new Exception($"Items are not equal at index '{index}'."); - - index++; - } - } - // TODO: figure out why this doesn't work... - //_ = result.Must() - // .BeAsyncEnumerableOf() - // .BeEqualTo(source); + _ = result.Must() + .BeAsyncEnumerableOf() + .BeEqualTo(source); } [Theory] diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Array.Tests.cs deleted file mode 100644 index 03ea53857..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Array.Tests.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Buffers; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToArray -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToArray_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .ToArray(source); - - // Act - var result = source.AsValueEnumerable() - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToArray_MemoryPool_Must_Succeed(int[] source) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .ToArray(source); - - // Act - using var result = source.AsValueEnumerable() - .ToArray(pool); - - // Assert - _ = result.Memory - .SequenceEqual(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ArraySegment.Tests.cs deleted file mode 100644 index cc1be5719..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ArraySegment.Tests.cs +++ /dev/null @@ -1,331 +0,0 @@ -using System; -using System.Buffers; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToArray -{ - public class ArraySegmentTests - { - [Fact] - public void ToArray_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - - // Act - var result = source.AsValueEnumerable() - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(Array.Empty()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void ToArray_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .ToArray(wrapped); - - // Act - var result = wrapped.AsValueEnumerable() - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void ToArray_MemoryPool_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var pool = MemoryPool.Shared; - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .ToArray(wrapped); - - // Act - var result = wrapped.AsValueEnumerable() - .ToArray(pool); - - // Assert - _ = result.Memory - .SequenceEqual(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Where(predicate) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var pool = MemoryPool.Shared; - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Where(predicate) - .ToArray(pool); - - // Assert - _ = result.Memory - .SequenceEqual(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void ToArray_PredicateAt_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Where(predicate) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var pool = MemoryPool.Shared; - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Where(predicate) - .ToArray(pool); - - // Assert - _ = result.Memory - .SequenceEqual(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Selector_Must_Succeed(int[] source, int skip, int take, Func selector) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Select(wrapped, selector) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Select(selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Select(wrapped, selector) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Select(selector) - .ToArray(pool); - - // Assert - _ = result.Memory - .SequenceEqual(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void ToArray_SelectorAt_Must_Succeed(int[] source, int skip, int take, Func selector) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Select(wrapped, selector) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Select(selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Select(wrapped, selector) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Select(selector) - .ToArray(pool); - - // Assert - _ = result.Memory - .SequenceEqual(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Selector_Must_Succeed(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate) - .Select(selector) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Where(predicate) - .Select(selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate) - .Select(selector) - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Where(predicate) - .Select(selector) - .ToArray(pool); - - // Assert - _ = result.Memory - .SequenceEqual(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Memory.Tests.cs deleted file mode 100644 index c4388323f..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.Memory.Tests.cs +++ /dev/null @@ -1,276 +0,0 @@ -using System; -using System.Buffers; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToArray -{ - public class MemoryTests - { - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToArray_MemoryPool_Must_Succeed(int[] source) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .ToArray(source); - - // Act - using var result = source.AsMemory().AsValueEnumerable() - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - using var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ToArray_PredicateAt_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - using var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Selector_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - using var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ToArray_SelectorAt_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - using var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Selector_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToArray(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToArray(); - - // Act - using var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs index 0f754527c..6c2071738 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs @@ -17,8 +17,8 @@ public void ToArray_Must_Succeed(int[] source, int skip, int take) { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .ToArray(); @@ -44,8 +44,8 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source, int skip, int take) // Arrange var pool = MemoryPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .ToArray(); @@ -71,8 +71,8 @@ public void ToArray_Predicate_Must_Succeed(int[] source, int skip, int take, Fun { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .ToArray(); @@ -100,8 +100,8 @@ public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, int skip, in // Arrange var pool = MemoryPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .ToArray(); @@ -129,8 +129,8 @@ public void ToArray_PredicateAt_Must_Succeed(int[] source, int skip, int take, F { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .ToArray(); @@ -158,8 +158,8 @@ public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, int skip, // Arrange var pool = MemoryPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .ToArray(); @@ -187,8 +187,8 @@ public void ToArray_Selector_Must_Succeed(int[] source, int skip, int take, Func { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .ToArray(); @@ -216,8 +216,8 @@ public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, int skip, int // Arrange var pool = MemoryPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .ToArray(); @@ -245,8 +245,8 @@ public void ToArray_SelectorAt_Must_Succeed(int[] source, int skip, int take, Fu { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .ToArray(); @@ -274,8 +274,8 @@ public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, int skip, i // Arrange var pool = MemoryPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .ToArray(); @@ -303,8 +303,8 @@ public void ToArray_Predicate_Selector_Must_Succeed(int[] source, int skip, int { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .Select(selector) @@ -334,8 +334,8 @@ public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, int // Arrange var pool = MemoryPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .Select(selector) diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyMemory.Tests.cs deleted file mode 100644 index 5dde4d3d0..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,276 +0,0 @@ -using System; -using System.Buffers; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToArray -{ - public class ReadOnlyMemoryTests - { - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToArray_MemoryPool_Must_Succeed(int[] source) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .ToArray(source); - - // Act - using var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ToArray_PredicateAt_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Selector_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ToArray_SelectorAt_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Selector_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToArray(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeNotSameAs(source) - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToArray(); - - // Act - using var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .ToArray(pool); - - // Assert - _ = result.Memory.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs index c10f90461..d3b71673c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs @@ -16,12 +16,13 @@ public class ReadOnlySpanTests public void ToArray_MemoryPool_Must_Succeed(int[] source) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var pool = MemoryPool.Shared; - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act - using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + using var result = wrapped.AsValueEnumerable() .ToArray(pool); // Assert @@ -39,12 +40,13 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source) public void ToArray_Predicate_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .ToArray(); // Act - var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + var result = wrapped.AsValueEnumerable() .Where(predicate) .ToArray(); @@ -62,13 +64,14 @@ public void ToArray_Predicate_Must_Succeed(int[] source, Func predica public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToArray(); // Act - using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + using var result = wrapped.AsValueEnumerable() .Where(predicate) .ToArray(pool); @@ -87,12 +90,13 @@ public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .ToArray(); // Act - var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + var result = wrapped.AsValueEnumerable() .Where(predicate) .ToArray(); @@ -110,13 +114,14 @@ public void ToArray_PredicateAt_Must_Succeed(int[] source, Func public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToArray(); // Act - using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + using var result = wrapped.AsValueEnumerable() .Where(predicate) .ToArray(pool); @@ -135,12 +140,13 @@ public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func selector) { // Arrange - var expected = Enumerable - .Select(source, selector) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector) .ToArray(); // Act - var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + var result = wrapped.AsValueEnumerable() .Select(selector) .ToArray(); @@ -158,13 +164,14 @@ public void ToArray_Selector_Must_Succeed(int[] source, Func select public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var pool = MemoryPool.Shared; - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act - using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + using var result = wrapped.AsValueEnumerable() .Select(selector) .ToArray(pool); @@ -183,12 +190,13 @@ public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, Func selector) { // Arrange - var expected = Enumerable - .Select(source, selector) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector) .ToArray(); // Act - var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + var result = wrapped.AsValueEnumerable() .Select(selector) .ToArray(); @@ -206,13 +214,14 @@ public void ToArray_SelectorAt_Must_Succeed(int[] source, Func public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var pool = MemoryPool.Shared; - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act - using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + using var result = wrapped.AsValueEnumerable() .Select(selector) .ToArray(pool); @@ -231,13 +240,14 @@ public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .Select(selector) .ToArray(); // Act - var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + var result = wrapped.AsValueEnumerable() .Where(predicate) .Select(selector) .ToArray(); @@ -256,14 +266,15 @@ public void ToArray_Predicate_Selector_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var pool = MemoryPool.Shared; - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToArray(); // Act - using var result = ((ReadOnlySpan)source.AsSpan()).AsValueEnumerable() + using var result = wrapped.AsValueEnumerable() .Where(predicate) .Select(selector) .ToArray(pool); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs index 085fc927b..ba3dd60ed 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs @@ -17,12 +17,12 @@ public void ToArray_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act - var result = ValueEnumerableExtensions - .ToArray, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .ToArray, Wrap.Enumerator, int>(); // Assert _ = result.Must() @@ -39,8 +39,8 @@ public void ToArray_With_ValidData_Collections_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueCollection(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act var result = ValueEnumerableExtensions @@ -62,12 +62,12 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source) var pool = MemoryPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act - using var result = ValueEnumerableExtensions - .ToArray, Wrap.Enumerator, int>(wrapped, pool); + using var result = wrapped + .ToArray, Wrap.Enumerator, int>(pool); // Assert _ = result.Memory @@ -85,13 +85,13 @@ public void ToArray_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ToArray(); // Assert @@ -110,13 +110,13 @@ public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func.Shared; var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToArray(); // Act - using var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + using var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ToArray(pool); // Assert @@ -135,13 +135,13 @@ public void ToArray_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ToArray(); // Assert @@ -160,13 +160,13 @@ public void ToArray_PredicateAt_MemoryPool_With_ValidData_Must_Succeed(int[] sou var pool = MemoryPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToArray(); // Act - using var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + using var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ToArray(pool); // Assert @@ -185,13 +185,13 @@ public void ToArray_Selector_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ToArray(); // Assert @@ -210,13 +210,13 @@ public void ToArray_Selector_MemoryPool_With_ValidData_Must_Succeed(int[] source var pool = MemoryPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act - using var result = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + using var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ToArray(pool); // Assert @@ -235,13 +235,13 @@ public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ToArray(); // Assert @@ -260,13 +260,13 @@ public void ToArray_SelectorAt_MemoryPool_With_ValidData_Must_Succeed(int[] sour var pool = MemoryPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act - using var result = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + using var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ToArray(pool); // Assert @@ -285,14 +285,14 @@ public void ToArray_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToArray(); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .ToArray(); @@ -312,14 +312,14 @@ public void ToArray_Predicate_Selector_MemoryPool_With_ValidData_Must_Succeed(in var pool = MemoryPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToArray(); // Act - using var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + using var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .ToArray(pool); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs index 9f984928a..75ffc4796 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs @@ -1,7 +1,7 @@ +using NetFabric.Assertive; using System; using System.Buffers; using System.Linq; -using NetFabric.Assertive; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToArray @@ -17,8 +17,8 @@ public void ToArray_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .ToArray(wrapped); + var expected = source + .ToArray(); // Act var result = ValueReadOnlyCollectionExtensions @@ -39,8 +39,8 @@ public void ToArray_With_ValidData_Collections_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueCollection(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act var result = ValueReadOnlyCollectionExtensions @@ -62,8 +62,8 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source) var pool = MemoryPool.Shared; var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act using var result = ValueEnumerableExtensions @@ -85,8 +85,8 @@ public void ToArray_Predicate_With_ValidData_Must_Succeed(int[] source, Func.Shared; var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act @@ -135,8 +135,8 @@ public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func.Shared; var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs index 2f2d08914..ae70e3d12 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs @@ -2,7 +2,6 @@ using System; using System.Buffers; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Xunit; @@ -19,12 +18,12 @@ public async ValueTask ToArrayAsync_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .ToArrayAsync, Wrap.AsyncEnumerator, int>(wrapped); + var result = await wrapped + .ToArrayAsync, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Must() @@ -42,12 +41,12 @@ public async ValueTask ToArrayAsync_MemoryPool_Must_Succeed(int[] source) var pool = MemoryPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .ToArrayAsync, Wrap.AsyncEnumerator, int>(wrapped, pool); + var result = await wrapped + .ToArrayAsync, Wrap.AsyncEnumerator, int>(pool); // Assert _ = result.Memory @@ -65,13 +64,13 @@ public async ValueTask ToArrayAsync_Predicate_With_ValidData_Must_Succeed(int[] // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ToArrayAsync(); // Assert @@ -90,13 +89,13 @@ public async ValueTask ToArrayAsync_Predicate_MemoryPool_Must_Succeed(int[] sour var pool = MemoryPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ToArrayAsync(pool); // Assert @@ -115,13 +114,13 @@ public async ValueTask ToArrayAsync_PredicateAt_With_ValidData_Must_Succeed(int[ // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ToArrayAsync(); // Assert @@ -140,13 +139,13 @@ public async ValueTask ToArrayAsync_PredicateAt_MemoryPool_Must_Succeed(int[] so var pool = MemoryPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ToArrayAsync(pool); // Assert @@ -165,13 +164,13 @@ public async ValueTask ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] s // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ToArrayAsync(); // Assert @@ -190,13 +189,13 @@ public async ValueTask ToArrayAsync_Selector_MemoryPool_Must_Succeed(int[] sourc var pool = MemoryPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ToArrayAsync(pool); // Assert @@ -215,13 +214,13 @@ public async ValueTask ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[] // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ToArrayAsync(); // Assert @@ -240,13 +239,13 @@ public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] sou var pool = MemoryPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ToArrayAsync(pool); // Assert @@ -266,14 +265,14 @@ public async ValueTask ToArrayAsync_Predicate_Selector_With_ValidData_Must_Succe // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .ToArrayAsync(); @@ -293,14 +292,14 @@ public async ValueTask ToArrayAsync_Predicate_Selector_MemoryPool_Must_Succeed(i var pool = MemoryPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .ToArrayAsync(pool); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Array.Tests.cs deleted file mode 100644 index 5126f6d87..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Array.Tests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToList_With_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .ToList(source); - - // Act - var result = source.AsValueEnumerable() - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ArraySegment.Tests.cs deleted file mode 100644 index f4957b024..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ArraySegment.Tests.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList -{ - public class ArraySegmentTests - { - [Fact] - public void ToList_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - - // Act - var result = source.AsValueEnumerable() - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(new List()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void ToList_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .ToList(wrapped); - - // Act - var result = wrapped.AsValueEnumerable() - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void ToList_Predicate_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(wrapped, skip) - .Take(take) - .Where(predicate) - .ToList(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void ToList_PredicateAt_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(wrapped, skip) - .Take(take) - .Where(predicate) - .ToList(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void ToList_Selector_Must_Succeed(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(wrapped, skip) - .Take(take) - .Select(selector) - .ToList(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void ToList_SelectorAt_Must_Succeed(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(wrapped, skip) - .Take(take) - .Select(selector) - .ToList(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToList_Predicate_Selector_Must_Succeed(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(wrapped, skip) - .Take(take) - .Where(predicate) - .Select(selector) - .ToList(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Enumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Enumerable.Tests.cs deleted file mode 100644 index 50a35132f..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Enumerable.Tests.cs +++ /dev/null @@ -1,59 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList -{ - public class EnumerableTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToList_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsEnumerable(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = EnumerableExtensions - .AsValueEnumerable(wrapped) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToList_With_ValidData_Collections_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsCollection(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = EnumerableExtensions - .AsValueEnumerable(wrapped) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Memory.Tests.cs deleted file mode 100644 index 1e126ba7c..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.Memory.Tests.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToList_With_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .ToList(source); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ToList_With_Predicate_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ToList_With_PredicateAt_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ToList_With_Selector_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ToList_With_SelectorAt_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToList_With_Predicate_Selector_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToList(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyCollection.Tests.cs deleted file mode 100644 index 9c3dddf18..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyCollection.Tests.cs +++ /dev/null @@ -1,59 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList -{ - public class ReadOnlyCollectionTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToList_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyCollection(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable(wrapped) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToList_With_ValidData_Collections_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsCollection(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable(wrapped) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyList.Tests.cs index 7f80d609f..024a5131e 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyList.Tests.cs @@ -1,7 +1,7 @@ +using NetFabric.Assertive; using System; using System.Collections.Generic; using System.Linq; -using NetFabric.Assertive; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList @@ -16,8 +16,8 @@ public void ToList_Skip_Take_With_ReadOnlyList_ValidData_Must_Succeed(int[] sour { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .ToList(); @@ -42,8 +42,8 @@ public void ToList_Skip_Take_With_List_ValidData_Must_Succeed(int[] source, int { // Arrange var wrapped = Wrap.AsList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .ToList(); @@ -68,8 +68,8 @@ public void ToList_Skip_Take_Predicate_With_ValidData_Must_Succeed(int[] source, { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .ToList(); @@ -97,8 +97,8 @@ public void ToList_Skip_Take_PredicateAt_With_ValidData_Must_Succeed(int[] sourc // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .ToList(); @@ -125,8 +125,8 @@ public void ToList_Skip_Take_Selector_With_ValidData_Must_Succeed(int[] source, { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .ToList(); @@ -153,8 +153,8 @@ public void ToList_Skip_Take_SelectorAt_With_ValidData_Must_Succeed(int[] source { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .ToList(); @@ -181,8 +181,8 @@ public void ToList_Skip_Take_Predicate_Selector_With_ValidData_Must_Succeed(int[ { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .Select(selector) diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyMemory.Tests.cs deleted file mode 100644 index 783ba325e..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ToList_With_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .ToList(source); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ToList_With_Predicate_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ToList_With_PredicateAt_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ToList_With_Selector_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ToList_With_SelectorAt_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ToList_With_Predicate_Selector_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToList(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlySpan.Tests.cs index 599dd8fc6..61d34ec74 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlySpan.Tests.cs @@ -1,7 +1,7 @@ +using NetFabric.Assertive; using System; using System.Collections.Generic; using System.Linq; -using NetFabric.Assertive; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList @@ -15,12 +15,13 @@ public class ReadOnlySpanTests public void ToList_With_Must_Succeed(int[] source) { // Arrange - var expected = Enumerable - .ToList(source); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .ToList(); // Act - var result = ArrayExtensions - .ToList((ReadOnlySpan)source.AsSpan()); + var result = wrapped.AsValueEnumerable() + .ToList(); // Assert _ = result.Must() @@ -36,13 +37,14 @@ public void ToList_With_Must_Succeed(int[] source) public void ToList_With_Predicate_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .ToList(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .ToList(); // Assert @@ -59,13 +61,14 @@ public void ToList_With_Predicate_Must_Succeed(int[] source, Func pre public void ToList_With_PredicateAt_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .ToList(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .ToList(); // Assert @@ -82,13 +85,14 @@ public void ToList_With_PredicateAt_Must_Succeed(int[] source, Func selector) { // Arrange - var expected = Enumerable - .Select(source, selector) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector) .ToList(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ToList(); // Assert @@ -105,13 +109,14 @@ public void ToList_With_Selector_Must_Succeed(int[] source, Func se public void ToList_With_SelectorAt_Must_Succeed(int[] source, Func selector) { // Arrange - var expected = Enumerable - .Select(source, selector) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector) .ToList(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ToList(); // Assert @@ -128,14 +133,15 @@ public void ToList_With_SelectorAt_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .Select(selector) .ToList(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector) .ToList(); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueEnumerable.Tests.cs index 5904ed0cf..2f243f2f0 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueEnumerable.Tests.cs @@ -17,12 +17,12 @@ public void ToList_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .ToList(source); + var expected = source + .ToList(); // Act - var result = ValueEnumerableExtensions - .ToList, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .ToList, Wrap.Enumerator, int>(); // Assert _ = result.Must() @@ -40,8 +40,8 @@ public void ToList_With_ValidData_Collections_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueCollection(source); - var expected = Enumerable - .ToList(source); + var expected = source + .ToList(); // Act var result = ValueEnumerableExtensions @@ -63,13 +63,13 @@ public void ToList_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ToList(); // Assert @@ -88,13 +88,13 @@ public void ToList_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ToList(); // Assert @@ -113,13 +113,13 @@ public void ToList_Selector_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ToList(); // Assert @@ -138,13 +138,13 @@ public void ToList_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ToList(); // Assert @@ -164,14 +164,14 @@ public void ToList_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToList(); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .ToList(); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs index df4f94d2e..c47d409d2 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs @@ -1,7 +1,7 @@ +using NetFabric.Assertive; using System; using System.Collections.Generic; using System.Linq; -using NetFabric.Assertive; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.ToList @@ -17,8 +17,8 @@ public void ToList_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .ToList(wrapped); + var expected = wrapped + .ToList(); // Act var result = ValueReadOnlyCollectionExtensions @@ -40,8 +40,8 @@ public void ToList_With_ValidData_Collections_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsValueCollection(source); - var expected = Enumerable - .ToList(source); + var expected = source + .ToList(); // Act var result = ValueReadOnlyCollectionExtensions @@ -63,8 +63,8 @@ public void ToList_Predicate_With_ValidData_Must_Succeed(int[] source, Func>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs index 5e6ce887d..53e5e64a5 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs @@ -18,12 +18,12 @@ public async ValueTask ToListAsync_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .ToList(source); + var expected = source + .ToList(); // Act - var result = await AsyncValueEnumerableExtensions - .ToListAsync, Wrap.AsyncEnumerator, int>(wrapped); + var result = await wrapped + .ToListAsync, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Must() @@ -41,13 +41,13 @@ public async ValueTask ToListAsync_Predicate_With_ValidData_Must_Succeed(int[] s // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToList(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ToListAsync(); // Assert @@ -66,13 +66,13 @@ public async ValueTask ToListAsync_PredicateAt_With_ValidData_Must_Succeed(int[] // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToList(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ToListAsync(); // Assert @@ -91,13 +91,13 @@ public async ValueTask ToListAsync_Selector_With_ValidData_Must_Succeed(int[] so // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ToListAsync(); // Assert @@ -116,13 +116,13 @@ public async ValueTask ToListAsync_SelectorAt_With_ValidData_Must_Succeed(int[] // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ToListAsync(); // Assert @@ -142,14 +142,14 @@ public async ValueTask ToListAsync_Predicate_Selector_With_ValidData_Must_Succee // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToList(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .ToListAsync(); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs index ba7230b05..12579d778 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs @@ -12,19 +12,19 @@ public static partial class TestData { new int[] { }, -1 }, { new int[] { }, 0 }, { new int[] { }, 1 }, - { new int[] { 1 }, -1 }, - { new int[] { 1 }, 1 }, - { new int[] { 1, 2, 3, 4, 5 }, -1 }, - { new int[] { 1, 2, 3, 4, 5 }, 5 }, + { new[] { 1 }, -1 }, + { new[] { 1 }, 1 }, + { new[] { 1, 2, 3, 4, 5 }, -1 }, + { new[] { 1, 2, 3, 4, 5 }, 5 }, }; public static TheoryData ElementAt => new TheoryData { - { new int[] { 1 }, 0}, - { new int[] { 1, 2, 3, 4, 5 }, 0 }, - { new int[] { 1, 2, 3, 4, 5 }, 2 }, - { new int[] { 1, 2, 3, 4, 5 }, 4 }, + { new[] { 1 }, 0}, + { new[] { 1, 2, 3, 4, 5 }, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 2 }, + { new[] { 1, 2, 3, 4, 5 }, 4 }, }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Array.Tests.cs deleted file mode 100644 index 179e89d4d..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Array.Tests.cs +++ /dev/null @@ -1,52 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.ElementAt -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_OutOfRange_Must_Return_None(int[] source) - { - // Arrange - - // Act - var optionTooSmall = source.AsValueEnumerable() - .ElementAt(-1); - var optionTooLarge = source.AsValueEnumerable() - .ElementAt(source.Length); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_ValidData_Must_Return_Some(int[] source) - { - // Arrange - for (var index = 0; index < source.Length; index++) - { - // Act - var result = source.AsValueEnumerable() - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(source[index]), - () => throw new Exception()); - } - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ArraySegment.Tests.cs deleted file mode 100644 index 33155aba1..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ArraySegment.Tests.cs +++ /dev/null @@ -1,374 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.ElementAt -{ - public class ArraySegmentTests - { - [Fact] - public void ElementAt_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - - // Act - var result = source.AsValueEnumerable() - .ElementAt(0); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void ElementAt_With_OutOfRange_Must_Return_None(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .ElementAt(take); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void ElementAt_With_ValidData_Must_Return_Some(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .ToList(wrapped); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .ElementAt(take); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Where(predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_PredicateAt_With_OutOfRange_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .ElementAt(take); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_PredicateAt_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Where(predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .ElementAt(take); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Select(selector) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .ElementAt(take); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Select(selector) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .ElementAt(take); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Where(predicate) - .Select(selector) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Memory.Tests.cs deleted file mode 100644 index 4d6a0efe0..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.Memory.Tests.cs +++ /dev/null @@ -1,304 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.ElementAt -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_OutOfRange_Must_Return_None(int[] source) - { - // Arrange - - // Act - var optionNegative = source.AsMemory().AsValueEnumerable() - .ElementAt(-1); - var optionTooLarge = source.AsMemory().AsValueEnumerable() - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_ValidData_Must_Return_Some(int[] source) - { - for (var index = 0; index < source.Length; index++) - { - // Arrange - var expected = Enumerable - .ElementAt(source, index); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var optionNegative = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ElementAt(-1); - var optionTooLarge = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_PredicateAt_With_OutOfRange_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var optionNegative = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ElementAt(-1); - var optionTooLarge = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var optionNegative = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ElementAt(-1); - var optionTooLarge = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - for (var index = 0; index < source.Length; index++) - { - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var optionNegative = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ElementAt(-1); - var optionTooLarge = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - for (var index = 0; index < source.Length; index++) - { - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var optionNegative = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .ElementAt(-1); - var optionTooLarge = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyMemory.Tests.cs deleted file mode 100644 index 4cc19ab1b..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,304 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.ElementAt -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_OutOfRange_Must_Return_None(int[] source) - { - // Arrange - - // Act - var optionNegative = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .ElementAt(-1); - var optionTooLarge = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_ValidData_Must_Return_Some(int[] source) - { - for (var index = 0; index < source.Length; index++) - { - // Arrange - var expected = Enumerable - .ElementAt(source, index); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_PredicateAt_With_OutOfRange_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - for (var index = 0; index < source.Length; index++) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ElementAt(index); - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToList(); - - for (var index = 0; index < source.Length; index++) - { - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var optionNegative = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .ElementAt(source.Length); - - // Assert - _ = optionNegative.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlySpan.Tests.cs index 3fd03aaa4..07da1cf48 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlySpan.Tests.cs @@ -14,12 +14,13 @@ public class ReadOnlySpanTests public void ElementAt_With_OutOfRange_Must_Return_None(int[] source) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var optionNegative = ArrayExtensions - .ElementAt((ReadOnlySpan)source.AsSpan(), -1); - var optionTooLarge = ArrayExtensions - .ElementAt((ReadOnlySpan)source.AsSpan(), source.Length); + var optionNegative = wrapped.AsValueEnumerable() + .ElementAt(-1); + var optionTooLarge = wrapped.AsValueEnumerable() + .ElementAt(source.Length); // Assert _ = optionNegative.Must() @@ -38,12 +39,13 @@ public void ElementAt_With_ValidData_Must_Return_Some(int[] source) for (var index = 0; index < source.Length; index++) { // Arrange - var expected = Enumerable - .ElementAt(source, index); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .ElementAt(index); // Act - var result = ArrayExtensions - .ElementAt((ReadOnlySpan)source.AsSpan(), index); + var result = wrapped.AsValueEnumerable() + .ElementAt(index); // Assert _ = result.Match( @@ -59,13 +61,14 @@ public void ElementAt_With_ValidData_Must_Return_Some(int[] source) public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var optionNegative = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var optionNegative = wrapped.AsValueEnumerable() + .Where(predicate) .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var optionTooLarge = wrapped.AsValueEnumerable() + .Where(predicate) .ElementAt(source.Length); // Assert @@ -83,15 +86,16 @@ public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, F public void ElementAt_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .ElementAt(index); // Assert @@ -108,13 +112,14 @@ public void ElementAt_Predicate_With_ValidData_Must_Return_Some(int[] source, Fu public void ElementAt_PredicateAt_With_OutOfRange_Must_Return_None(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var optionNegative = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var optionNegative = wrapped.AsValueEnumerable() + .Where(predicate) .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var optionTooLarge = wrapped.AsValueEnumerable() + .Where(predicate) .ElementAt(source.Length); // Assert @@ -132,15 +137,16 @@ public void ElementAt_PredicateAt_With_OutOfRange_Must_Return_None(int[] source, public void ElementAt_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .ElementAt(index); // Assert @@ -157,13 +163,14 @@ public void ElementAt_PredicateAt_With_ValidData_Must_Return_Some(int[] source, public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var optionNegative = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var optionNegative = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var optionTooLarge = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(source.Length); // Assert @@ -181,15 +188,16 @@ public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, Fu public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) { // Arrange - var expected = Enumerable - .Select(source, selector) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(index); // Assert @@ -206,13 +214,14 @@ public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Fun public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var optionNegative = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var optionNegative = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var optionTooLarge = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(source.Length); // Assert @@ -230,15 +239,16 @@ public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) { // Arrange - var expected = Enumerable - .Select(source, selector) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(index); // Assert @@ -255,14 +265,15 @@ public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, F public void ElementAt_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] source, Func predicate, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var optionNegative = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var optionNegative = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector) .ElementAt(-1); - var optionTooLarge = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var optionTooLarge = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector) .ElementAt(source.Length); @@ -281,16 +292,17 @@ public void ElementAt_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] public void ElementAt_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .Select(selector) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector) .ElementAt(index); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.Array.Tests.cs deleted file mode 100644 index 3aa434eb9..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.Array.Tests.cs +++ /dev/null @@ -1,45 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.First -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void First_With_Empty_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = source.AsValueEnumerable() - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void First_With_ValidData_Must_Return_Some(int[] source) - { - // Arrange - var expected = Enumerable - .First(source); - - // Act - var result = source.AsValueEnumerable() - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ArraySegment.Tests.cs deleted file mode 100644 index a6defd14a..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ArraySegment.Tests.cs +++ /dev/null @@ -1,297 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.First -{ - public class ArraySegmentTests - { - [Fact] - public void First_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - - // Act - var result = source.AsValueEnumerable() - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - public void First_With_Empty_Must_Return_None(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - - // Act - var result = wrapped.AsValueEnumerable() - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void First_With_ValidData_Must_Return_Some(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .First(wrapped); - - // Act - var result = wrapped.AsValueEnumerable() - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - public void First_Predicate_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .First(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - public void First_PredicateAt_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(wrapped, skip) - .Take(take) - .Where(predicate) - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - public void First_Selector_With_Empty_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void First_Selector_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Select(selector) - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtEmpty), MemberType = typeof(TestData))] - public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Select(selector) - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Where(predicate) - .Select(selector) - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.Memory.Tests.cs deleted file mode 100644 index 9e0ee7f4e..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.Memory.Tests.cs +++ /dev/null @@ -1,237 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.First -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void First_With_Empty_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void First_With_ValidData_Must_Return_Some(int[] source) - { - // Arrange - var expected = Enumerable - .First(source); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - public void First_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .First(source, predicate); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - public void First_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where (predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .First(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - public void First_Selector_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .First(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .First(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .First(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyMemory.Tests.cs deleted file mode 100644 index fd8d7ab06..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,237 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.First -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void First_With_Empty_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void First_With_ValidData_Must_Return_Some(int[] source) - { - // Arrange - var expected = Enumerable - .First(source); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - public void First_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .First(source, predicate); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - public void First_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .First(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - public void First_Selector_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .First(); - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .First(); - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .First(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs index 78502a04d..636bf0061 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs @@ -12,10 +12,11 @@ public class ReadOnlySpanTests public void First_With_Empty_Must_Return_None(int[] source) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .First((ReadOnlySpan)source.AsSpan()); + var result = wrapped.AsValueEnumerable() + .First(); // Assert _ = result.Must() @@ -29,12 +30,13 @@ public void First_With_Empty_Must_Return_None(int[] source) public void First_With_ValidData_Must_Return_Some(int[] source) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = Enumerable .First(source); // Act - var result = ArrayExtensions - .First((ReadOnlySpan)source.AsSpan()); + var result = wrapped.AsValueEnumerable() + .First(); // Assert _ = result.Match( @@ -47,10 +49,11 @@ public void First_With_ValidData_Must_Return_Some(int[] source) public void First_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .First(); // Assert @@ -65,12 +68,13 @@ public void First_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = Enumerable .First(source, predicate); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .First(); // Assert @@ -84,10 +88,11 @@ public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .First(); // Assert @@ -102,13 +107,14 @@ public void First_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = Enumerable .Where(source, predicate) .First(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .First(); // Assert @@ -122,10 +128,11 @@ public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func public void First_Selector_With_Empty_Must_Return_None(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .First(); // Assert @@ -140,13 +147,14 @@ public void First_Selector_With_Empty_Must_Return_None(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = Enumerable .Select(source, selector) .First(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .First(); // Assert @@ -160,10 +168,11 @@ public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .First(); // Assert @@ -178,13 +187,14 @@ public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = Enumerable .Select(source, selector) .First(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .First(); // Assert @@ -198,10 +208,11 @@ public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func< public void First_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector) .First(); @@ -217,14 +228,15 @@ public void First_Predicate_Selector_With_Empty_Must_Return_None(int[] source, F public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = Enumerable .Where(source, predicate) .Select(selector) .First(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector) .First(); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Array.Tests.cs deleted file mode 100644 index 68c8e1114..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Array.Tests.cs +++ /dev/null @@ -1,60 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.Single -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void Single_With_Empty_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = source.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - public void Single_With_Single_Must_Return_Some(int[] source) - { - // Arrange - var expected = Enumerable - .Single(source); - - // Act - var result = source.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Single_With_Multiple_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = source.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ArraySegment.Tests.cs deleted file mode 100644 index 3af0b7f13..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ArraySegment.Tests.cs +++ /dev/null @@ -1,471 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.Single -{ - public class ArraySegmentTests - { - [Fact] - public void Single_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - - // Act - var result = source.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - public void Single_With_Empty_Must_Return_None(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - - // Act - var result = wrapped.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - public void Single_With_Single_Must_Return_Some(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Single(wrapped); - - // Act - var result = wrapped.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Single_With_Multiple_Must_Return_None(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - - // Act - var result = wrapped.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - public void Single_SkipTake_With_Empty_Must_Return_None(int[] source, int skip, int take) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - public void Single_SkipTake_With_Single_Must_Return_Some(int[] source, int skip, int take) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Single_SkipTake_With_Multiple_Must_Return_None(int[] source, int skip, int take) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - public void Single_Predicate_With_Single_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Single(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Where(predicate) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - public void Single_Selector_With_Empty_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - public void Single_Selector_With_Single_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Select(selector) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void Single_Selector_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtEmpty), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Empty_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Select(selector) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, skip) - .Take(take) - .Where(predicate) - .Select(selector) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = new ArraySegment(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Memory.Tests.cs deleted file mode 100644 index 5c62f071f..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.Memory.Tests.cs +++ /dev/null @@ -1,333 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.Single -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void Single_With_Empty_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - public void Single_With_Single_Must_Return_Some(int[] source) - { - // Arrange - var expected = Enumerable - .Single(source); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Single_With_Multiple_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - public void Single_Predicate_With_Single_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = - Enumerable.Single(source, predicate); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_With_Multiple_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Single(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Multiple_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - public void Single_Selector_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - public void Single_Selector_With_Single_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = - Enumerable.Single( - Enumerable.Select(source, selector)); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void Single_Selector_With_Multiple_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .Single(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .Single(); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Multiple_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyMemory.Tests.cs deleted file mode 100644 index 978650f35..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,333 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.Single -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void Single_With_Empty_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - public void Single_With_Single_Must_Return_Some(int[] source) - { - // Arrange - var expected = Enumerable - .Single(source); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Single_With_Multiple_Must_Return_None(int[] source) - { - // Arrange - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - public void Single_Predicate_With_Single_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = - Enumerable.Single(source, predicate); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_With_Multiple_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Single(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Multiple_Must_Return_None(int[] source, Func predicate) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - public void Single_Selector_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - public void Single_Selector_With_Single_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = - Enumerable.Single( - Enumerable.Select(source, selector)); - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void Single_Selector_With_Multiple_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .Single(); - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Select((ReadOnlyMemory)source.AsMemory(), selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector) - .Single(); - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Multiple_Must_Return_None(int[] source, Func predicate, Func selector) - { - // Arrange - - // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlySpan.Tests.cs index e19ad21e1..34414f590 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlySpan.Tests.cs @@ -12,10 +12,11 @@ public class ReadOnlySpanTests public void Single_With_Empty_Must_Return_None(int[] source) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Single((ReadOnlySpan)source.AsSpan()); + var result = wrapped.AsValueEnumerable() + .Single(); // Assert _ = result.Must() @@ -28,12 +29,13 @@ public void Single_With_Empty_Must_Return_None(int[] source) public void Single_With_Single_Must_Return_Some(int[] source) { // Arrange - var expected = Enumerable - .Single(source); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Single(); // Act - var result = ArrayExtensions - .Single((ReadOnlySpan)source.AsSpan()); + var result = wrapped.AsValueEnumerable() + .Single(); // Assert _ = result.Match( @@ -46,10 +48,11 @@ public void Single_With_Single_Must_Return_Some(int[] source) public void Single_With_Multiple_Must_Return_None(int[] source) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Single((ReadOnlySpan)source.AsSpan()); + var result = wrapped.AsValueEnumerable() + .Single(); // Assert _ = result.Must() @@ -62,10 +65,11 @@ public void Single_With_Multiple_Must_Return_None(int[] source) public void Single_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Single(); // Assert @@ -79,12 +83,13 @@ public void Single_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) { // Arrange - var expected = - Enumerable.Single(source, predicate); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Single(predicate); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Single(); // Assert @@ -98,10 +103,11 @@ public void Single_Predicate_With_Single_Must_Return_Some(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Single(); // Assert @@ -115,10 +121,11 @@ public void Single_Predicate_With_Multiple_Must_Return_None(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Single(); // Assert @@ -132,13 +139,14 @@ public void Single_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .Single(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Single(); // Assert @@ -152,10 +160,11 @@ public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, Func predicate) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Single(); // Assert @@ -169,10 +178,11 @@ public void Single_PredicateAt_With_Multiple_Must_Return_None(int[] source, Func public void Single_Selector_With_Empty_Must_Return_None(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -186,13 +196,13 @@ public void Single_Selector_With_Empty_Must_Return_None(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = - Enumerable.Single( - Enumerable.Select(source, selector)); + source.Select(selector).Single(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -206,10 +216,11 @@ public void Single_Selector_With_Single_Must_Return_Some(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -223,10 +234,11 @@ public void Single_Selector_With_Multiple_Must_Return_None(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -240,13 +252,14 @@ public void Single_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) { // Arrange - var expected = Enumerable - .Select(source, selector) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector) .Single(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -260,10 +273,11 @@ public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Select((ReadOnlySpan)source.AsSpan(), selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -277,10 +291,11 @@ public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, Func< public void Single_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector) .Single(); @@ -295,14 +310,15 @@ public void Single_Predicate_Selector_With_Empty_Must_Return_None(int[] source, public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, Func predicate, Func selector) { // Arrange - var expected = Enumerable - .Where(source, predicate) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) .Select(selector) .Single(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector) .Single(); @@ -317,10 +333,11 @@ public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, public void Single_Predicate_Selector_With_Multiple_Must_Return_None(int[] source, Func predicate, Func selector) { // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector) .Single(); diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Array.Tests.cs deleted file mode 100644 index cb90b84a9..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Array.Tests.cs +++ /dev/null @@ -1,54 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.Where -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = source.AsValueEnumerable() - .Where(predicate); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.PredicatePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicatePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicatePredicateMultiple), MemberType = typeof(TestData))] - public void Where_Where_With_ValidData_Must_Succeed(int[] source, Func predicate0, Func predicate1) - { - // Arrange - var expected = Enumerable - .Where(source, predicate0) - .Where(predicate1); - - // Act - var result = source.AsValueEnumerable() - .Where(predicate0) - .Where(predicate1); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs index 6a3f7dc4e..3573542ee 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs @@ -15,8 +15,8 @@ public void Where_With_NullArray_Must_Succeed() var expected = Enumerable.Empty(); // Act - var result = ArrayExtensions - .Where(source, _ => true); + var result = source.AsValueEnumerable() + .Where(_ => true); // Assert _ = result.Must() @@ -34,18 +34,18 @@ public void Where_With_ValidData_Must_Succeed(int[] source, int skip, int take, // Arrange var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate); + var expected = wrapped + .Where(predicate); // Act - var result = ArrayExtensions - .Where(wrapped, predicate); + var result = wrapped.AsValueEnumerable() + .Where(predicate); // Assert _ = result.Must() .BeEnumerableOf() .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); + _ = Enumerable.SequenceEqual(result, expected).Must().BeTrue(); } [Theory] @@ -57,13 +57,13 @@ public void Where_Where_With_ValidData_Must_Succeed(int[] source, int skip, int // Arrange var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate0) + var expected = wrapped + .Where(predicate0) .Where(predicate1); // Act - var result = ArrayExtensions - .Where(wrapped, predicate0) + var result = wrapped.AsValueEnumerable() + .Where(predicate0) .Where(predicate1); // Assert @@ -72,5 +72,28 @@ public void Where_Where_With_ValidData_Must_Succeed(int[] source, int skip, int .BeEqualTo(expected, testRefStructs: false); _ = result.SequenceEqual(expected).Must().BeTrue(); } + + [Theory] + [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] + public void Where_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) + { + // Arrange + var (offset, count) = Utils.SkipTake(source.Length, skip, take); + var wrapped = new ArraySegment(source, offset, count); + var expected = wrapped + .Where(predicate) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs index cf9890c54..61c0066e4 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs @@ -1,7 +1,6 @@ using NetFabric.Assertive; using System; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Xunit; @@ -18,17 +17,40 @@ public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()); + var result = wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); // Assert _ = result.Must() .BeAsyncEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public async ValueTask Where_Sum_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsAsyncValueEnumerable(source); + var expected = source + .Where(predicate) + .Sum(); + + // Act + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + .SumAsync().ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Memory.Tests.cs deleted file mode 100644 index 1f3c862e2..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.Memory.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.Where -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = System.Linq.Enumerable.Where(source, predicate); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyList.Tests.cs index 033f08ebb..d151cd185 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyList.Tests.cs @@ -11,13 +11,13 @@ public class ReadOnlyListTests [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) + public void Where_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) { // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate); @@ -33,5 +33,33 @@ public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, int skip, .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] + public void Where_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyList(source); + var expected = source + .Skip(skip) + .Take(take) + .Where(predicate) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(skip) + .Take(take) + .Where(predicate) + .Sum(); + + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyMemory.Tests.cs index 54c8796e2..8ac2bf608 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyMemory.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyMemory.Tests.cs @@ -11,14 +11,16 @@ public class ReadOnlyMemoryTests [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable.Where(source, predicate); + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Where(predicate); // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate); + var result = wrapped.AsValueEnumerable() + .Where(predicate); // Assert _ = result.Must() @@ -26,5 +28,27 @@ public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Where(predicate) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlySpan.Tests.cs index 27cd440f0..79edcd106 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlySpan.Tests.cs @@ -14,12 +14,13 @@ public class ReadOnlySpanTests public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate); + var result = wrapped.AsValueEnumerable() + .Where(predicate); // Assert _ = result.SequenceEqual(expected).Must().BeTrue(); diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueEnumerable.Tests.cs index 99d324935..f0049e1bc 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueEnumerable.Tests.cs @@ -11,22 +11,45 @@ public class ValueEnumerableTests [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate); + var expected = source + .Where(predicate); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate); // Assert _ = result.Must() .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void Where_Sum_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueEnumerable(source); + var expected = source + .Where(predicate) + .Sum(); + + // Act + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs new file mode 100644 index 000000000..98296b29f --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs @@ -0,0 +1,55 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Filtering.Where +{ + public class ValueReadOnlyCollectionTests + { + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Where(predicate); + + // Act + var result = ValueReadOnlyCollectionExtensions + .Where, Wrap.Enumerator, int>(wrapped, predicate); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void Where_Sum_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Where(predicate) + .Sum(); + + // Act + var result = ValueReadOnlyCollectionExtensions + .Where, Wrap.Enumerator, int>(wrapped, predicate) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Array.Tests.cs deleted file mode 100644 index 13d36d94b..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Array.Tests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereAt -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = source.AsValueEnumerable() - .Where(predicate); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ArraySegment.Tests.cs index 738b3c16e..405191291 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ArraySegment.Tests.cs @@ -15,8 +15,8 @@ public void Where_With_NullArray_Must_Succeed() var expected = Enumerable.Empty(); // Act - var result = ArrayExtensions - .Where(source, (_, __) => true); + var result = source.AsValueEnumerable() + .Where((_, __) => true); // Assert _ = result.Must() @@ -38,8 +38,8 @@ public void Where_With_ValidData_Must_Succeed(int[] source, int skip, int take, .Where(wrapped, predicate); // Act - var result = ArrayExtensions - .Where(wrapped, predicate); + var result = wrapped.AsValueEnumerable() + .Where(predicate); // Assert _ = result.Must() @@ -47,5 +47,28 @@ public void Where_With_ValidData_Must_Succeed(int[] source, int skip, int take, .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); _ = result.SequenceEqual(expected).Must().BeTrue(); } + + [Theory] + [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] + public void Where_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) + { + // Arrange + var (offset, count) = Utils.SkipTake(source.Length, skip, take); + var wrapped = new ArraySegment(source, offset, count); + var expected = Enumerable + .Where(wrapped, predicate) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs index 67296c8a8..6a2fff1d6 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs @@ -1,7 +1,6 @@ using NetFabric.Assertive; using System; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Xunit; @@ -18,17 +17,40 @@ public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()); + var result = wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); // Assert _ = result.Must() .BeAsyncEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] + public async ValueTask Where_Sum_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsAsyncValueEnumerable(source); + var expected = source + .Where(predicate) + .Sum(); + + // Act + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + .SumAsync(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Memory.Tests.cs deleted file mode 100644 index c7a94e6cc..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.Memory.Tests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereIndex -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyList.Tests.cs index e12d9ec96..cf5603d14 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyList.Tests.cs @@ -16,8 +16,8 @@ public void Where_With_ValidData_Must_Succeed(int[] source, int skip, int take, // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate); @@ -32,5 +32,32 @@ public void Where_With_ValidData_Must_Succeed(int[] source, int skip, int take, .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] + public void Where_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyList(source); + var expected = source + .Skip(skip) + .Take(take) + .Where(predicate) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(skip) + .Take(take) + .Where(predicate) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyMemory.Tests.cs index 0d39eaa94..1c4ccbb49 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyMemory.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyMemory.Tests.cs @@ -14,12 +14,13 @@ public class ReadOnlyMemoryTests public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate); + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Where(predicate); // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate); + var result = wrapped.AsValueEnumerable() + .Where(predicate); // Assert _ = result.Must() @@ -27,5 +28,27 @@ public void Where_With_ValidData_Must_Succeed(int[] source, Func .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); _ = result.SequenceEqual(expected).Must().BeTrue(); } + + [Theory] + [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] + public void Where_Sum_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Where(predicate) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlySpan.Tests.cs index a981f0bf8..f6dcaad0f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlySpan.Tests.cs @@ -14,12 +14,13 @@ public class ReadOnlySpanTests public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = Enumerable - .Where(source, predicate); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate); + var result = wrapped.AsValueEnumerable() + .Where(predicate); // Assert _ = result.SequenceEqual(expected).Must().BeTrue(); diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueEnumerable.Tests.cs index b399db06e..aa293157f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueEnumerable.Tests.cs @@ -16,17 +16,40 @@ public void Where_With_ValidData_Must_Succeed(int[] source, Func // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(wrapped, predicate); + var expected = source + .Where(predicate); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate); // Assert _ = result.Must() .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] + public void Where_Sum_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueEnumerable(source); + var expected = source + .Where(predicate) + .Sum(); + + // Act + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs new file mode 100644 index 000000000..6e9b8be68 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs @@ -0,0 +1,55 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereAt +{ + public class ValueReadOnlyCollectionTests + { + [Theory] + [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] + public void Where_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Where(predicate); + + // Act + var result = ValueReadOnlyCollectionExtensions + .Where, Wrap.Enumerator, int>(wrapped, predicate); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] + public void Where_Sum_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Where(predicate) + .Sum(); + + // Act + var result = ValueReadOnlyCollectionExtensions + .Where, Wrap.Enumerator, int>(wrapped, predicate) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Array.Tests.cs deleted file mode 100644 index dac06a3b9..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Array.Tests.cs +++ /dev/null @@ -1,33 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereSelect -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Select(selector); - - // Act - var result = source.AsValueEnumerable() - .Where(predicate) - .Select(selector); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ArraySegment.Tests.cs index 0815d4163..da4512a1c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ArraySegment.Tests.cs @@ -8,15 +8,15 @@ namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereSelect public class ArraySegmentTests { [Fact] - public void WhereRef_With_NullArray_Must_Succeed() + public void WhereSelect_With_NullArray_Must_Succeed() { // Arrange var source = default(ArraySegment); var expected = Enumerable.Empty(); // Act - var result = ArrayExtensions - .Where(source, _ => true) + var result = source.AsValueEnumerable() + .Where(_ => true) .Select(item => item.ToString()); // Assert @@ -35,20 +35,45 @@ public void WhereSelect_With_ValidData_Must_Succeed(int[] source, int skip, int // Arrange var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate) + var expected = wrapped + .Where(predicate) .Select(selector); // Act - var result = ArrayExtensions - .Where(wrapped, predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector); // Assert _ = result.Must() .BeEnumerableOf() .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); + _ = Enumerable.SequenceEqual(result, expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] + public void WhereSelect_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) + { + // Arrange + var (offset, count) = Utils.SkipTake(source.Length, skip, take); + var wrapped = new ArraySegment(source, offset, count); + var expected = Enumerable + .Where(wrapped, predicate) + .Select(item => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs index 74a45afc2..05f2cd04d 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs @@ -1,6 +1,6 @@ using NetFabric.Assertive; using System; -using System.Threading; +using System.Linq; using System.Threading.Tasks; using Xunit; @@ -16,13 +16,13 @@ public void WhereSelect_Predicate_With_ValidData_Must_Succeed(int[] source, Func { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(source, predicate), selector); + var expected = source + .Where(predicate) + .Select(selector); // Act - var result = AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()); // Assert @@ -30,5 +30,29 @@ public void WhereSelect_Predicate_With_ValidData_Must_Succeed(int[] source, Func .BeAsyncEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public async ValueTask WhereSelect_Sum_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap.AsAsyncValueEnumerable(source); + var expected = source + .Where(predicate) + .Select(item => item) + .Sum(); + + // Act + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + .Select((item, _) => new ValueTask(item)) + .SumAsync().ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Memory.Tests.cs deleted file mode 100644 index 0d2571f6e..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.Memory.Tests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereSelect -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) - { - // Arrange - var expected = - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(source, predicate), selector); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Where(predicate) - .Select(selector); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyList.Tests.cs index 0553fc018..595c687a7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyList.Tests.cs @@ -15,8 +15,8 @@ public void WhereSelect_With_ValidData_Must_Succeed(int[] source, int skip, int { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .Select(selector); @@ -33,5 +33,33 @@ public void WhereSelect_With_ValidData_Must_Succeed(int[] source, int skip, int .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] + public void WhereSelect_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) + { + // Arrange + var wrapped = Wrap.AsReadOnlyList(source); + var expected = source + .Skip(skip) + .Take(take) + .Where(predicate) + .Select(item => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(skip) + .Take(take) + .Where(predicate) + .Select(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.Tests.cs index 83f8cc644..52e2035c5 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereSelect @@ -13,13 +14,14 @@ public class ReadOnlyMemoryTests public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange - var expected = - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(source, predicate), selector); + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Where(predicate) + .Select(selector); // Act - var result = ArrayExtensions - .Where((ReadOnlyMemory)source.AsMemory(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector); // Assert @@ -28,5 +30,29 @@ public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Where(predicate) + .Select(item => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.Tests.cs index 5b61db349..bb6c336a0 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereSelect @@ -13,17 +14,42 @@ public class ReadOnlySpanTests public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange - var expected = - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(source, predicate), selector); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) + .Select(selector); // Act - var result = ArrayExtensions - .Where((ReadOnlySpan)source.AsSpan(), predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector); // Assert _ = result.SequenceEqual(expected).Must().BeTrue(); } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void WhereSelect_Sum_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate) + .Select(item => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueEnumerable.Tests.cs index fa504c24a..a1b1f39f7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueEnumerable.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereSelect @@ -14,13 +15,13 @@ public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector); // Assert @@ -28,5 +29,29 @@ public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void WhereSelect_Sum_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap.AsValueEnumerable(source); + var expected = source + .Where(predicate) + .Select(item => item) + .Count(); + + // Act + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) + .Select(item => item) + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs new file mode 100644 index 000000000..85e45646b --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs @@ -0,0 +1,57 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereSelect +{ + public class ValueReadOnlyCollectionTests + { + [Theory] + [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] + public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyCollection(source); + var expected = source + .Where(predicate) + .Select(selector); + + // Act + var result = ValueEnumerableExtensions + .Where, Wrap.Enumerator, int>(wrapped, predicate) + .Select(selector); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void WhereSelect_Sum_With_ValidData_Must_Succeed(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyCollection(source); + var expected = source + .Where(predicate) + .Select(item => item) + .Count(); + + // Act + var result = ValueEnumerableExtensions + .Where, Wrap.Enumerator, int>(wrapped, predicate) + .Select(item => item) + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs index a0359620f..64214a382 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData Skip_Skip => - new TheoryData + new() { { new int[] { }, -1, -1 }, { new int[] { }, 0, -1 }, @@ -16,14 +16,14 @@ public static partial class TestData { new int[] { }, 0, 0 }, { new int[] { }, 1, 0 }, - { new int[] { 1 }, -1, -1 }, - { new int[] { 1 }, 0, 0 }, - { new int[] { 1 }, 1, 1 }, - { new int[] { 1 }, 5, 5 }, + { new[] { 1 }, -1, -1 }, + { new[] { 1 }, 0, 0 }, + { new[] { 1 }, 1, 1 }, + { new[] { 1 }, 5, 5 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, -1 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 0 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, -1 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 0 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2 }, }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Array.Tests.cs deleted file mode 100644 index 4eb816ac4..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Array.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Skip -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Skip(source, count); - - // Act - var result = source.AsValueEnumerable() - .Skip(count); - - // Assert - _ = result - .SequenceEqual(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ArraySegment.Tests.cs deleted file mode 100644 index 4bce8af2b..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ArraySegment.Tests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Skip -{ - public class ArraySegmentTests - { - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Skip(source, count); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(count); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs index 0d2435c77..8a8d402c6 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs @@ -15,12 +15,12 @@ public void Skip_With_ValidData_Must_Succeed(int[] source, int count) // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Skip(source, count); + var expected = source + .Skip(count); // Act - var result = AsyncValueEnumerableExtensions - .Skip, Wrap.AsyncEnumerator, int>(wrapped, count); + var result = wrapped + .Skip, Wrap.AsyncEnumerator, int>(count); // Assert _ = result.Must() @@ -35,13 +35,13 @@ public void Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Skip(source, count0) + var expected = source + .Skip(count0) .Skip(count1); // Act - var result = AsyncValueEnumerableExtensions - .Skip, Wrap.AsyncEnumerator, int>(wrapped, count0) + var result = wrapped + .Skip, Wrap.AsyncEnumerator, int>(count0) .Skip(count1); // Assert @@ -59,13 +59,13 @@ public void Skip_Take_With_ValidData_Must_Succeed(int[] source, int skip, int ta // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take); // Act - var result = AsyncValueEnumerableExtensions - .Skip, Wrap.AsyncEnumerator, int>(wrapped, skip) + var result = wrapped + .Skip, Wrap.AsyncEnumerator, int>(skip) .Take(take); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Memory.Tests.cs deleted file mode 100644 index a4224d574..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.Memory.Tests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Skip -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Skip(source, count); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Skip(count); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlyList.Tests.cs deleted file mode 100644 index 9d62edb75..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Skip -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = Enumerable - .Skip(source, count); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(count); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlyMemory.Tests.cs deleted file mode 100644 index 74082c480..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Skip -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Skip(source, count); - - // Act - var result = ArrayExtensions - .Skip((ReadOnlyMemory)source.AsMemory(), count); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlySpan.Tests.cs deleted file mode 100644 index 0483482b1..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ReadOnlySpan.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Skip -{ - public class ReadOnlySpanTests - { - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Skip(source, count); - - // Act - var result = ArrayExtensions - .Skip((ReadOnlySpan)source.AsSpan(), count); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs index 62f9019da..763235721 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs @@ -15,12 +15,12 @@ public void Skip_With_ValidData_Must_Succeed(int[] source, int count) // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Skip(source, count); + var expected = source + .Skip(count); // Act - var result = ValueEnumerableExtensions - .Skip, Wrap.Enumerator, int>(wrapped, count); + var result = wrapped + .Skip, Wrap.Enumerator, int>(count); // Assert _ = result.Must() @@ -35,13 +35,13 @@ public void Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Skip(source, count0) + var expected = source + .Skip(count0) .Skip( count1); // Act - var result = ValueEnumerableExtensions - .Skip, Wrap.Enumerator, int>(wrapped, count0) + var result = wrapped + .Skip, Wrap.Enumerator, int>(count0) .Skip(count1); // Assert @@ -59,13 +59,13 @@ public void Skip_Take_With_ValidData_Must_Succeed(int[] source, int skip, int ta // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take); // Act - var result = ValueEnumerableExtensions - .Skip, Wrap.Enumerator, int>(wrapped, skip) + var result = wrapped + .Skip, Wrap.Enumerator, int>(skip) .Take(take); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs index fcaeb6cbb..9c77d46a1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs @@ -15,8 +15,8 @@ public void Skip_With_ValidData_Must_Succeed(int[] source, int count) // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .Skip(wrapped, count); + var expected = source + .Skip(count); // Act var result = ValueReadOnlyCollectionExtensions.Skip, Wrap.Enumerator, int>(wrapped, count); diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs index 125ce3184..aa2c0ab43 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs @@ -6,20 +6,20 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData SkipTake_Take => - new TheoryData + new() { { new int[] { }, 0, 0, -1 }, { new int[] { }, 0, 0, 0 }, { new int[] { }, 0, 0, 1 }, - { new int[] { 1 }, 0, 1, -1 }, - { new int[] { 1 }, 0, 1, 0 }, - { new int[] { 1 }, 0, 1, 1 }, - { new int[] { 1 }, 0, 1, 5 }, + { new[] { 1 }, 0, 1, -1 }, + { new[] { 1 }, 0, 1, 0 }, + { new[] { 1 }, 0, 1, 1 }, + { new[] { 1 }, 0, 1, 5 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, -1 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, 0 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, 5 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, -1 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, 0 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, 5 }, }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs index 47afbaedc..059e79536 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData Take_Take => - new TheoryData + new() { { new int[] { }, -1, -1 }, { new int[] { }, 0, -1 }, @@ -16,18 +16,18 @@ public static partial class TestData { new int[] { }, 0, 0 }, { new int[] { }, 1, 0 }, - { new int[] { 1 }, -1, -1 }, - { new int[] { 1 }, 0, 0 }, - { new int[] { 1 }, 0, 1 }, - { new int[] { 1 }, 1, 1 }, - { new int[] { 1 }, 5, 2 }, - { new int[] { 1 }, 5, 5 }, + { new[] { 1 }, -1, -1 }, + { new[] { 1 }, 0, 0 }, + { new[] { 1 }, 0, 1 }, + { new[] { 1 }, 1, 1 }, + { new[] { 1 }, 5, 2 }, + { new[] { 1 }, 5, 5 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, -1 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 2 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 0 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 1 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, -1 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 0 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 1 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4 }, }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Array.Tests.cs deleted file mode 100644 index ae3ea43a5..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Array.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Take -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void Take_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Take(source, count); - - // Act - var result = source.AsValueEnumerable() - .Take(count); - - // Assert - _ = result - .SequenceEqual(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ArraySegment.Tests.cs deleted file mode 100644 index 5389c5d69..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ArraySegment.Tests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Take -{ - public class ArraySegmentTests - { - [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void Take_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = Enumerable - .Take(source, count); - - // Act - var result = wrapped.AsValueEnumerable() - .Take(count); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs index 2b36c02ac..cf8160b94 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs @@ -15,12 +15,12 @@ public void Take_With_ValidData_Must_Succeed(int[] source, int count) // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Take(source, count); + var expected = source + .Take(count); // Act - var result = AsyncValueEnumerableExtensions - .Take, Wrap.AsyncEnumerator, int>(wrapped, count); + var result = wrapped + .Take, Wrap.AsyncEnumerator, int>(count); // Assert _ = result.Must() @@ -35,13 +35,13 @@ public void Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Take(source, count0) + var expected = source + .Take(count0) .Take(count1); // Act - var result = AsyncValueEnumerableExtensions - .Take, Wrap.AsyncEnumerator, int>(wrapped, count0) + var result = wrapped + .Take, Wrap.AsyncEnumerator, int>(count0) .Take(count1); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Memory.Tests.cs deleted file mode 100644 index ac2ea89bc..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.Memory.Tests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Take -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void Take_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Take(source, count); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Take(count); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlyList.Tests.cs deleted file mode 100644 index 22d468008..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Take -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void Take_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = Enumerable - .Take(source, count); - - // Act - var result = wrapped.AsValueEnumerable() - .Take(count); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlyMemory.Tests.cs deleted file mode 100644 index ec8c4a20d..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Take -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void Take_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Take(source, count); - - // Act - var result = ArrayExtensions - .Take((ReadOnlyMemory)source.AsMemory(), count); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlySpan.Tests.cs deleted file mode 100644 index f42e9530e..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ReadOnlySpan.Tests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Take -{ - public class ReadOnlySpanTests - { - [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void Take_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var expected = Enumerable - .Take(source, count); - - // Act - var result = ArrayExtensions - .Take((ReadOnlySpan)source.AsSpan(), count); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs index a8dee9d58..7ebaa007f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs @@ -15,12 +15,12 @@ public void Take_With_ValidData_Must_Succeed(int[] source, int count) // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Take(wrapped, count); + var expected = source + .Take(count); // Act - var result = ValueEnumerableExtensions - .Take, Wrap.Enumerator, int>(wrapped, count); + var result = wrapped + .Take, Wrap.Enumerator, int>(count); // Assert _ = result.Must() @@ -34,13 +34,13 @@ public void Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int { // Arrange var wrapped = Wrap.AsValueEnumerable(source); - var expected = Enumerable - .Take(wrapped, count0) + var expected = source + .Take(count0) .Take(count1); // Act - var result = ValueEnumerableExtensions - .Take, Wrap.Enumerator, int>(wrapped, count0) + var result = wrapped + .Take, Wrap.Enumerator, int>(count0) .Take(count1); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs index 8a71e4553..b448bceb9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs @@ -15,8 +15,8 @@ public void Take_With_ValidData_Must_Succeed(int[] source, int count) // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .Take(wrapped, count); + var expected = source + .Take(count); // Act var result = ValueReadOnlyCollectionExtensions diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Array.Tests.cs deleted file mode 100644 index 354d87a18..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Array.Tests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.Select -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector); - - // Act - var result = source.AsValueEnumerable() - .Select(selector); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs index bd62a9833..1903fbbce 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs @@ -15,8 +15,8 @@ public void Select_With_NullArray_Must_Succeed() var expected = Enumerable.Empty(); // Act - var result = ArrayExtensions - .Select(source, item => item.ToString()); + var result = source.AsValueEnumerable() + .Select(item => item.ToString()); // Assert _ = result.Must() @@ -34,12 +34,12 @@ public void Select_With_ValidData_Must_Succeed(int[] source, int skip, int take, // Arrange var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Select(wrapped, selector); + var expected = wrapped + .Select(selector); // Act - var result = ArrayExtensions - .Select(wrapped, selector); + var result = wrapped.AsValueEnumerable() + .Select(selector); // Assert _ = result.Must() @@ -47,5 +47,29 @@ public void Select_With_ValidData_Must_Succeed(int[] source, int skip, int take, .BeEqualTo(expected, testRefStructs: false); _ = result.SequenceEqual(expected).Must().BeTrue(); } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take) + { + // Arrange + var (offset, count) = Utils.SkipTake(source.Length, skip, take); + var wrapped = new ArraySegment(source, offset, count); + var expected = wrapped + .Select(item => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs index a8fe74aef..768d49dff 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs @@ -1,6 +1,6 @@ using NetFabric.Assertive; using System; -using System.Threading; +using System.Linq; using System.Threading.Tasks; using Xunit; @@ -16,17 +16,39 @@ public void Select_Selector_With_ValidData_Must_Succeed(int[] source, Func, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()); + var result = wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()); // Assert _ = result.Must() .BeAsyncEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public async ValueTask Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsAsyncValueEnumerable(source); + var expected = source + .Select(item => item) + .Sum(); + + // Act + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, int>((item, _) => new ValueTask(item)) + .SumAsync().ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Memory.Tests.cs deleted file mode 100644 index 408522984..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.Memory.Tests.cs +++ /dev/null @@ -1,30 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.Select -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = - System.Linq.Enumerable.Select(source, selector); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyList.Tests.cs index 89416a7ad..bb420e89a 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyList.Tests.cs @@ -1,8 +1,6 @@ +using NetFabric.Assertive; using System; -using System.Collections.Generic; -using System.ComponentModel; using System.Linq; -using NetFabric.Assertive; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Projection.Select @@ -17,8 +15,8 @@ public void Select_With_ValidData_Must_Succeed(int[] source, int skip, int take, { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector); @@ -33,5 +31,31 @@ public void Select_With_ValidData_Must_Succeed(int[] source, int skip, int take, .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take) + { + // Arrange + var wrapped = Wrap.AsReadOnlyList(source); + var expected = source + .Skip(skip) + .Take(take) + .Select(item => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(skip) + .Take(take) + .Select(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyMemory.Tests.cs index 31d08aaa6..7d68c66ec 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyMemory.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyMemory.Tests.cs @@ -14,11 +14,13 @@ public class ReadOnlyMemoryTests public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange - var expected = - System.Linq.Enumerable.Select(source, selector); + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Select(selector); // Act - var result = ArrayExtensions.Select((ReadOnlyMemory)source.AsMemory(), selector); + var result = wrapped.AsValueEnumerable() + .Select(selector); // Assert _ = result.Must() @@ -26,5 +28,27 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func s .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); _ = result.SequenceEqual(expected).Must().BeTrue(); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Select(item => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlySpan.Tests.cs index f127cfabf..24fcf71a2 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlySpan.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Projection.Select @@ -13,14 +14,38 @@ public class ReadOnlySpanTests public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange - var expected = - System.Linq.Enumerable.Select(source, selector); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector); // Act - var result = ArrayExtensions.Select((ReadOnlySpan)source.AsSpan(), selector); + var result = wrapped.AsValueEnumerable() + .Select(selector); // Assert _ = result.SequenceEqual(expected).Must().BeTrue(); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(item => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueEnumerable.Tests.cs index c6e8b6bb6..c0319c5a0 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueEnumerable.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Projection.Select @@ -14,17 +15,39 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func s { // Arrange var wrapped = Wrap.AsValueEnumerable(source); - var expected = - System.Linq.Enumerable.Select(wrapped, selector); + var expected = source + .Select(selector); // Act - var result = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector); + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector); // Assert _ = result.Must() .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsValueEnumerable(source); + var expected = source + .Select(item => item) + .Sum(); + + // Act + var result = wrapped + .Select, Wrap.Enumerator, int, int>(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs index 308d3dfd3..60dafc5f5 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs @@ -1,6 +1,6 @@ -using System; -using System.Collections.Generic; using NetFabric.Assertive; +using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Projection.Select @@ -15,8 +15,8 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func s { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); - var expected = - System.Linq.Enumerable.Select(wrapped, selector); + var expected = source + .Select(selector); // Act var result = ValueReadOnlyCollectionExtensions @@ -27,5 +27,27 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func s .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyCollection(source); + var expected = source + .Select(item => item) + .Sum(); + + // Act + var result = ValueReadOnlyCollectionExtensions + .Select, Wrap.Enumerator, int, int>(wrapped, item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Array.Tests.cs deleted file mode 100644 index 9005acd6f..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Array.Tests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectAt -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector); - - // Act - var result = source.AsValueEnumerable() - .Select(selector); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ArraySegment.Tests.cs index 8b159f017..c6f2db9b6 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ArraySegment.Tests.cs @@ -15,8 +15,8 @@ public void Select_With_NullArray_Must_Succeed() var expected = Enumerable.Empty(); // Act - var result = ArrayExtensions - .Select(source, (item, _) => item.ToString()); + var result = source.AsValueEnumerable() + .Select((item, _) => item.ToString()); // Assert _ = result.Must() @@ -34,12 +34,12 @@ public void Select_With_ValidData_Must_Succeed(int[] source, int skip, int take, // Arrange var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Select(wrapped, selector); + var expected = wrapped + .Select(selector); // Act - var result = ArrayExtensions - .Select(wrapped, selector); + var result = wrapped.AsValueEnumerable() + .Select(selector); // Assert _ = result.Must() @@ -47,5 +47,28 @@ public void Select_With_ValidData_Must_Succeed(int[] source, int skip, int take, .BeEqualTo(expected, testRefStructs: false); _ = result.SequenceEqual(expected).Must().BeTrue(); } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take) + { + // Arrange + var (offset, count) = Utils.SkipTake(source.Length, skip, take); + var wrapped = new ArraySegment(source, offset, count); + var expected = wrapped + .Select((item, _) => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select((item, _) => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs index 112ade684..43d36eb60 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs @@ -1,6 +1,6 @@ using NetFabric.Assertive; using System; -using System.Threading; +using System.Linq; using System.Threading.Tasks; using Xunit; @@ -16,17 +16,39 @@ public void Select_Selector_With_ValidData_Must_Succeed(int[] source, Func, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()); + var result = wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()); // Assert _ = result.Must() .BeAsyncEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public async ValueTask Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsAsyncValueEnumerable(source); + var expected = source + .Select((item, _) => item) + .Sum(); + + // Act + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, int>((item, _, _) => new ValueTask(item)) + .SumAsync().ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Memory.Tests.cs deleted file mode 100644 index dd17239d0..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.Memory.Tests.cs +++ /dev/null @@ -1,30 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectIndex -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) - { - // Arrange - var expected = - System.Linq.Enumerable.Select(source, selector); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Select(selector); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyList.Tests.cs index 441888732..5c0b31a75 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyList.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectAt @@ -14,8 +15,8 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take) + { + // Arrange + var wrapped = Wrap.AsReadOnlyList(source); + var expected = source + .Skip(skip) + .Take(take) + .Select((item, _) => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(skip) + .Take(take) + .Select((item, _) => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyMemory.Tests.cs index 1b4fff20d..3150a7fb9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyMemory.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyMemory.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectIndex @@ -13,11 +14,13 @@ public class ReadOnlyMemoryTests public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange - var expected = - System.Linq.Enumerable.Select(source, selector); + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Select(selector); // Act - var result = ArrayExtensions.Select((ReadOnlyMemory)source.AsMemory(), selector); + var result = wrapped.AsValueEnumerable() + .Select(selector); // Assert _ = result.Must() @@ -25,5 +28,27 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func)source.AsMemory(); + var expected = source + .Select((item, _) => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select((item, _) => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlySpan.Tests.cs index 5d2752085..c2f51760c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlySpan.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectIndex @@ -13,15 +14,39 @@ public class ReadOnlySpanTests public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange - var expected = - System.Linq.Enumerable.Select(source, selector); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector); // Act - var result = ArrayExtensions.Select((ReadOnlySpan)source.AsSpan(), selector); + var result = wrapped.AsValueEnumerable() + .Select(selector); // Assert _ = result.SequenceEqual(expected).Must().BeTrue(); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select((item, _) => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select((item, _) => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueEnumerable.Tests.cs index 68cfc0ce2..e7cf789af 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueEnumerable.Tests.cs @@ -1,6 +1,6 @@ using NetFabric.Assertive; using System; -using System.Net.Security; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectAt @@ -15,17 +15,39 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector); + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector); // Assert _ = result.Must() .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsValueEnumerable(source); + var expected = source + .Select((item, _) => item) + .Sum(); + + // Act + var result = wrapped + .Select, Wrap.Enumerator, int, int>((item, _) => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs index 045d4fc12..6f4d98c52 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectAt @@ -14,8 +15,8 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyCollection(source); + var expected = source + .Select((item, _) => item) + .Sum(); + + // Act + var result = ValueReadOnlyCollectionExtensions + .Select, Wrap.Enumerator, int, int>(wrapped, (item, _) => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs index 2d7d70d6b..88d7804b2 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs @@ -8,21 +8,21 @@ public static partial class TestData { public static TheoryData, Vector>, Func> SelectVector => - new TheoryData, Vector>, Func> + new() { { new int[] { }, item => item * 2, item => item * 2 }, - { new int[] { 0, }, item => item * 2, item => item * 2 }, - { new int[] { 0, 1}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2, 3}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2, 3, 4}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2, 3, 4, 5}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, item => item * 2, item => item * 2 }, - { new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, item => item * 2, item => item * 2 }, + { new[] { 0, }, item => item * 2, item => item * 2 }, + { new[] { 0, 1}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3, 4}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3, 4, 5}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, item => item * 2, item => item * 2 }, }; } diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ArraySegment.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ArraySegment.cs deleted file mode 100644 index 9740944fa..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ArraySegment.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using System.Numerics; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectVector -{ - public class ArraySegmentTests - { - [Theory] - [MemberData(nameof(TestData.SelectVector), MemberType = typeof(TestData))] - public void SelectVector_ToArray_With_ValidData_Must_Succeed(int[] source, Func, Vector> vectorSelector, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - var result = new ArraySegment(source).AsValueEnumerable() - .SelectVector(vectorSelector, selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlyMemory.Tests.cs deleted file mode 100644 index a029130b6..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using System.Numerics; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectVector -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.SelectVector), MemberType = typeof(TestData))] - public void SelectVector_ToArray_With_ValidData_Must_Succeed(int[] source, Func, Vector> vectorSelector, Func selector) - { - // Arrange - var expected = Enumerable - .Select(source, selector) - .ToArray(); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .SelectVector(vectorSelector, selector) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlySpan.Tests.cs index 2ce26dede..e671b28b6 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlySpan.Tests.cs @@ -14,12 +14,13 @@ public class ReadOnlySpanTests public void SelectVector_ToArray_With_ValidData_Must_Succeed(int[] source, Func, Vector> vectorSelector, Func selector) { // Arrange - var expected = Enumerable - .Select(source, selector) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Select(selector) .ToArray(); // Act - var result = ((ReadOnlySpan)source.AsSpan()) + var result = wrapped.AsValueEnumerable() .SelectVector(vectorSelector, selector) .ToArray(); diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Array.Tests.cs deleted file mode 100644 index 2311f7a20..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Array.Tests.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.All -{ - public class ArrayTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void All_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .All(source, predicate); - - // Act - var result = source.AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Count() == source.Length; - - // Act - var result = source.AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ArraySegment.Tests.cs deleted file mode 100644 index 7db8bac47..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ArraySegment.Tests.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.All -{ - public class ArraySegmentTests - { - [Fact] - public void All_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - - // Act - var result = source.AsValueEnumerable() - .All(_ => true); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void All_Predicate_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .All(wrapped, predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void All_Skip_Take_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate) - .Count() == count; - - // Act - var result = wrapped.AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs index f33a59e38..f5caa098c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs @@ -1,6 +1,6 @@ using NetFabric.Assertive; using System; -using System.Threading; +using System.Linq; using System.Threading.Tasks; using Xunit; @@ -16,12 +16,12 @@ public async ValueTask AllAsync_With_ValidData_Must_Succeed(int[] source, Func, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()); + var result = await wrapped + .AllAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); // Assert _ = result.Must() @@ -36,13 +36,13 @@ public async ValueTask AllAsync_PredicateAt_With_ValidData_Must_Succeed(int[] so { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) == source.Length; + var expected = source + .Where(predicate) + .Count() == source.Length; // Act - var result = await AsyncValueEnumerableExtensions - .AllAsync, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()); + var result = await wrapped + .AllAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Memory.Tests.cs deleted file mode 100644 index c9447bfe1..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.Memory.Tests.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.All -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void All_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = System.Linq.Enumerable.All(source, predicate); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) == source.Length; - - // Act - var result = source.AsMemory().AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlyList.Tests.cs index efb8ce228..b42b71781 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlyList.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.All @@ -14,8 +15,8 @@ public void All_With_ValidData_Must_Succeed(int[] source, Func predic { // Arrange var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = - System.Linq.Enumerable.All(wrapped, predicate); + var expected = source + .All(predicate); // Act var result = wrapped.AsValueEnumerable() @@ -34,10 +35,10 @@ public void All_Skip_Take_Predicate_With_ValidData_Must_Succeed(int[] source, in { // Arrange var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = - System.Linq.Enumerable.All( - System.Linq.Enumerable.Take( - System.Linq.Enumerable.Skip(source, skip), take), predicate); + var expected = source + .Skip(skip) + .Take(take) + .All(predicate); // Act var result = wrapped.AsValueEnumerable() @@ -58,9 +59,8 @@ public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = System.Linq.Enumerable.All(source, predicate); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) == source.Length; - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlySpan.Tests.cs index 73a039f37..140c004fc 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlySpan.Tests.cs @@ -1,5 +1,6 @@ -using System; using NetFabric.Assertive; +using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.All @@ -13,11 +14,13 @@ public class ReadOnlySpanTests public void All_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = System.Linq.Enumerable.All(source, predicate); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .All(predicate); // Act - var result = ArrayExtensions - .All((ReadOnlySpan)source.AsSpan(), predicate); + var result = wrapped.AsValueEnumerable() + .All(predicate); // Assert _ = result.Must() @@ -31,13 +34,13 @@ public void All_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) == source.Length; + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate).Count() == source.Length; // Act - var result = ArrayExtensions - .All((ReadOnlySpan)source.AsSpan(), predicate); + var result = wrapped.AsValueEnumerable() + .All(predicate); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueEnumerable.Tests.cs index 28f926a97..b8f0211eb 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueEnumerable.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.All @@ -14,12 +15,12 @@ public void All_With_ValidData_Must_Succeed(int[] source, Func predic { // Arrange var wrapped = Wrap.AsValueEnumerable(source); - var expected = - System.Linq.Enumerable.All(wrapped, predicate); + var expected = source + .All(predicate); // Act - var result = ValueEnumerableExtensions - .All, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped + .All, Wrap.Enumerator, int>(predicate); // Assert _ = result.Must() @@ -34,13 +35,12 @@ public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped + .All, Wrap.Enumerator, int>(predicate); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs index 38dde2cb7..defae1ba0 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs @@ -1,7 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; using NetFabric.Assertive; +using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.All @@ -16,8 +15,8 @@ public void All_With_ValidData_Must_Succeed(int[] source, Func predic { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); - var expected = - System.Linq.Enumerable.All(wrapped, predicate); + var expected = source + .All(predicate); // Act var result = ValueReadOnlyCollectionExtensions @@ -36,9 +35,8 @@ public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Any(source, predicate); - - // Act - var result = source.AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = Enumerable - .Where(source, predicate) - .Count() != 0; - - // Act - var result = source.AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ArraySegment.Tests.cs deleted file mode 100644 index ef7ee42bf..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ArraySegment.Tests.cs +++ /dev/null @@ -1,106 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Any -{ - public class ArraySegmentTests - { - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Any_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Any(wrapped); - - // Act - var result = wrapped.AsValueEnumerable() - .Any(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Fact] - public void Any_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - - // Act - var result = source.AsValueEnumerable() - .Any(); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Fact] - public void Any_Predicate_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - var expected = Enumerable.Empty(); - - // Act - var result = source.AsValueEnumerable() - .Any(_ => true); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Any(wrapped, predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Where(wrapped, predicate) - .Count() != 0; - - // Act - var result = wrapped.AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs index 7214fb810..30d04f623 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs @@ -1,9 +1,7 @@ +using NetFabric.Assertive; using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Threading; +using System.Linq; using System.Threading.Tasks; -using NetFabric.Assertive; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Any @@ -18,12 +16,12 @@ public async ValueTask AnyAsync_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = - System.Linq.Enumerable.Any(source); + var expected = source + .Any(); // Act - var result = await AsyncValueEnumerableExtensions - .AnyAsync, Wrap.AsyncEnumerator, int>(wrapped); + var result = await wrapped + .AnyAsync, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Must() @@ -38,12 +36,12 @@ public async ValueTask AnyAsync_Predicate_With_ValidData_Must_Succeed(int[] sour { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = - System.Linq.Enumerable.Any(source, predicate); + var expected = source + .Any(predicate); // Act - var result = await AsyncValueEnumerableExtensions - .AnyAsync, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()); + var result = await wrapped + .AnyAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); // Assert _ = result.Must() @@ -58,13 +56,13 @@ public async ValueTask AnyAsync_PredicateAt_With_ValidData_Must_Succeed(int[] so { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) != 0; + var expected = source + .Where(predicate) + .Count() != 0; // Act - var result = await AsyncValueEnumerableExtensions - .AnyAsync, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()); + var result = await wrapped + .AnyAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.Memory.Tests.cs deleted file mode 100644 index e5adff14b..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.Memory.Tests.cs +++ /dev/null @@ -1,68 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Any -{ - public class MemoryTests - { - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Any_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = - System.Linq.Enumerable.Any(source); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Any(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = - System.Linq.Enumerable.Any(source, predicate); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) != 0; - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlyList.Tests.cs index 22c1993b3..361c00493 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlyList.Tests.cs @@ -1,7 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; using NetFabric.Assertive; +using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Any @@ -16,8 +15,8 @@ public void Any_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = - System.Linq.Enumerable.Any(source); + var expected = source + .Any(); // Act var result = wrapped.AsValueEnumerable() @@ -36,10 +35,10 @@ public void Any_Skip_Take_With_ValidData_Must_Succeed(int[] source, int skip, in { // Arrange var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = - System.Linq.Enumerable.Any( - System.Linq.Enumerable.Take( - System.Linq.Enumerable.Skip(source, skip), take)); + var expected = source + .Skip(skip) + .Take(take) + .Any(); // Act var result = wrapped.AsValueEnumerable() @@ -60,8 +59,8 @@ public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func)source.AsMemory()).AsValueEnumerable() - .Any(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = - System.Linq.Enumerable.Any(source, predicate); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) != 0; - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlySpan.Tests.cs index 475da4dbf..4a126ae32 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlySpan.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Any @@ -14,12 +15,13 @@ public class ReadOnlySpanTests public void Any_With_ValidData_Must_Succeed(int[] source) { // Arrange - var expected = - System.Linq.Enumerable.Any(source); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Any(); // Act - var result = ArrayExtensions - .Any((ReadOnlySpan)source.AsSpan()); + var result = wrapped.AsValueEnumerable() + .Any(); // Assert _ = result.Must() @@ -33,12 +35,13 @@ public void Any_With_ValidData_Must_Succeed(int[] source) public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = - System.Linq.Enumerable.Any(source, predicate); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Any(predicate); // Act - var result = ArrayExtensions - .Any((ReadOnlySpan)source.AsSpan(), predicate); + var result = wrapped.AsValueEnumerable() + .Any(predicate); // Assert _ = result.Must() @@ -52,13 +55,13 @@ public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var expected = - System.Linq.Enumerable.Count( - System.Linq.Enumerable.Where(source, predicate)) != 0; + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Where(predicate).Count() != 0; // Act - var result = ArrayExtensions - .Any((ReadOnlySpan)source.AsSpan(), predicate); + var result = wrapped.AsValueEnumerable() + .Any(predicate); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueEnumerable.Tests.cs index 7d0a2daa1..6beda5330 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueEnumerable.Tests.cs @@ -1,7 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; using NetFabric.Assertive; +using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Any @@ -17,11 +16,11 @@ public void Any_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap.AsValueEnumerable(source); var expected = - System.Linq.Enumerable.Any(source); + source.Any(); // Act - var result = ValueEnumerableExtensions - .Any, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .Any, Wrap.Enumerator, int>(); // Assert _ = result.Must() @@ -37,11 +36,11 @@ public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped + .Any, Wrap.Enumerator, int>(predicate); // Assert _ = result.Must() @@ -57,12 +56,11 @@ public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped + .Any, Wrap.Enumerator, int>(predicate); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs index f8952ed3c..4c3ea433b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs @@ -1,7 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; using NetFabric.Assertive; +using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Any @@ -17,7 +16,7 @@ public void Any_With_ValidData_Must_Succeed(int[] source) // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); var expected = - System.Linq.Enumerable.Any(source); + source.Any(); // Act var result = ValueReadOnlyCollectionExtensions @@ -37,7 +36,7 @@ public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func item.ToString()).ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = source.Last(); - - // Act - var result = source.AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = source.Last().ToString(); - var wrapped = source.Select(item => item.ToString()).ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = source.AsValueEnumerable() - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = source.Last(); - - // Act - var result = source.AsValueEnumerable() - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = source.AsValueEnumerable() - .Contains(value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = source.Last(); - - // Act - var result = source.AsValueEnumerable() - .Contains(value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ArraySegment.Tests.cs deleted file mode 100644 index 7438f65f1..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ArraySegment.Tests.cs +++ /dev/null @@ -1,182 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Contains -{ - public class ArraySegmentTests - { - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var value = int.MaxValue; - - // Act - var result = ArrayExtensions - .Contains(wrapped, value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Fact] - public void Contains_With_NullArray_Must_Succeed() - { - // Arrange - var source = default(ArraySegment); - - // Act - var result = ArrayExtensions - .Contains(source, 0); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source.Select(item => item.ToString()).ToArray(), offset, count); - var value = default(string); - - // Act - var result = ArrayExtensions - .Contains(wrapped, value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var value = wrapped.Last(); - - // Act - var result = ArrayExtensions - .Contains(wrapped, value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source.Select(item => item.ToString()).ToArray(), offset, count); - var value = wrapped.Last().ToString(); - - // Act - var result = ArrayExtensions - .Contains(wrapped, value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var value = int.MaxValue; - - // Act - var result = ArrayExtensions - .Contains(wrapped, value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var value = wrapped.Last(); - - // Act - var result = ArrayExtensions - .Contains(wrapped, value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var value = int.MaxValue; - - // Act - var result = ArrayExtensions - .Contains(wrapped, value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) - { - // Arrange - var (offset, count) = Utils.SkipTake(source.Length, skip, take); - var wrapped = new ArraySegment(source, offset, count); - var value = wrapped.Last(); - - // Act - var result = ArrayExtensions - .Contains(wrapped, value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs index 89bf1b66d..3b481a9f9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs @@ -1,8 +1,7 @@ -using System; +using NetFabric.Assertive; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using NetFabric.Assertive; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.ContainsAsync @@ -16,12 +15,12 @@ public class AsyncValueEnumerableTests public async ValueTask ContainsAsync_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .ContainsAsync, Wrap.AsyncEnumerator, int>(wrapped, value); + var result = await wrapped + .ContainsAsync, Wrap.AsyncEnumerator, int>(value); // Assert _ = result.Must() @@ -35,12 +34,12 @@ public async ValueTask ContainsAsync_ValueType_With_Null_And_NotContains_Must_Re public async ValueTask ContainsAsync_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = default(string); + const string value = default; var wrapped = Wrap.AsAsyncValueEnumerable(source.Select(item => item.ToString()).ToArray()); // Act - var result = await AsyncValueEnumerableExtensions - .ContainsAsync, Wrap.AsyncEnumerator, string>(wrapped, value); + var result = await wrapped + .ContainsAsync, Wrap.AsyncEnumerator, string>(value); // Assert _ = result.Must() @@ -53,12 +52,13 @@ public async ValueTask ContainsAsync_ReferenceType_With_Null_And_NotContains_Mus public async ValueTask ContainsAsync_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .ContainsAsync, Wrap.AsyncEnumerator, int>(wrapped, value); + var result = await wrapped + .ContainsAsync, Wrap.AsyncEnumerator, int>(value); // Assert _ = result.Must() @@ -71,12 +71,14 @@ public async ValueTask ContainsAsync_ValueType_With_Null_And_Contains_Must_Retur public async ValueTask ContainsAsync_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = Enumerable.Last(source).ToString(); + var value = source + .Last() + .ToString(); var wrapped = Wrap.AsAsyncValueEnumerable(source.Select(item => item.ToString()).ToArray()); // Act - var result = await AsyncValueEnumerableExtensions - .ContainsAsync, Wrap.AsyncEnumerator, string>(wrapped, value); + var result = await wrapped + .ContainsAsync, Wrap.AsyncEnumerator, string>(value); // Assert _ = result.Must() @@ -90,12 +92,12 @@ public async ValueTask ContainsAsync_ReferenceType_With_Null_And_Contains_Must_R public async ValueTask ContainsAsync_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .ContainsAsync, Wrap.AsyncEnumerator, int>(wrapped, value, EqualityComparer.Default); + var result = await wrapped + .ContainsAsync, Wrap.AsyncEnumerator, int>(value, EqualityComparer.Default); // Assert _ = result.Must() @@ -108,12 +110,13 @@ public async ValueTask ContainsAsync_With_DefaultComparer_And_NotContains_Must_R public async ValueTask ContainsAsync_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .ContainsAsync, Wrap.AsyncEnumerator, int>(wrapped, value, EqualityComparer.Default); + var result = await wrapped + .ContainsAsync, Wrap.AsyncEnumerator, int>(value, EqualityComparer.Default); // Assert _ = result.Must() @@ -128,12 +131,12 @@ public async ValueTask ContainsAsync_With_DefaultComparer_And_Contains_Must_Retu public async ValueTask ContainsAsync_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .ContainsAsync, Wrap.AsyncEnumerator, int>(wrapped, value, TestComparer.Instance); + var result = await wrapped + .ContainsAsync, Wrap.AsyncEnumerator, int>(value, TestComparer.Instance); // Assert _ = result.Must() @@ -146,12 +149,13 @@ public async ValueTask ContainsAsync_With_Comparer_And_NotContains_Must_ReturnFa public async ValueTask ContainsAsync_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .ContainsAsync, Wrap.AsyncEnumerator, int>(wrapped, value, TestComparer.Instance); + var result = await wrapped + .ContainsAsync, Wrap.AsyncEnumerator, int>(value, TestComparer.Instance); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.Memory.Tests.cs deleted file mode 100644 index b55634b1f..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.Memory.Tests.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Contains -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = default(string); - var referenceSource = source.Select(item => item.ToString()).ToArray(); - - // Act - var result = referenceSource.AsMemory().AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = Enumerable.Last(source); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = Enumerable.Last(source).ToString(); - var referenceSource = source.Select(item => item.ToString()).ToArray(); - - // Act - var result = referenceSource.AsMemory().AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = Enumerable.Last(source); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Contains(value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = Enumerable.Last(source); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Contains(value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs index 319bfad44..b3daaa1b0 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs @@ -1,6 +1,6 @@ -using System; -using System.Collections.Generic; using NetFabric.Assertive; +using System.Collections.Generic; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Contains @@ -14,7 +14,7 @@ public class ReadOnlyListTests public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueReadOnlyList(source); // Act @@ -33,7 +33,7 @@ public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = default(string); + const string value = default; var wrapped = Wrap.AsValueReadOnlyList(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); // Act @@ -51,7 +51,8 @@ public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(in public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsValueReadOnlyList(source); // Act @@ -69,7 +70,9 @@ public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] sour public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source).ToString(); + var value = source + .Last() + .ToString(); var wrapped = Wrap.AsValueReadOnlyList(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); // Act @@ -88,7 +91,7 @@ public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueReadOnlyList(source); // Act @@ -106,7 +109,8 @@ public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsValueReadOnlyList(source); // Act @@ -128,7 +132,7 @@ public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) public void Contains_Skip_Take_With_Null_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueReadOnlyList(source); // Act @@ -148,10 +152,10 @@ public void Contains_Skip_Take_With_Null_And_NotContains_Must_ReturnFalse(int[] public void Contains_Skip_Take_With_Null_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) { // Arrange - var value = - System.Linq.Enumerable.Last( - System.Linq.Enumerable.Take( - System.Linq.Enumerable.Skip(source, skip), take)); + var value = source + .Skip(skip) + .Take(take) + .Last(); var wrapped = Wrap.AsValueReadOnlyList(source); // Act @@ -172,7 +176,7 @@ public void Contains_Skip_Take_With_Null_And_Contains_Must_ReturnTrue(int[] sour public void Contains_Skip_Take_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueReadOnlyList(source); // Act @@ -192,10 +196,10 @@ public void Contains_Skip_Take_With_DefaultComparer_And_NotContains_Must_ReturnF public void Contains_Skip_Take_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) { // Arrange - var value = - System.Linq.Enumerable.Last( - System.Linq.Enumerable.Take( - System.Linq.Enumerable.Skip(source, skip), take)); + var value = source + .Skip(skip) + .Take(take) + .Last(); var wrapped = Wrap.AsValueReadOnlyList(source); // Act @@ -216,7 +220,7 @@ public void Contains_Skip_Take_With_DefaultComparer_And_Contains_Must_ReturnTrue public void Contains_Skip_Take_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueReadOnlyList(source); // Act @@ -236,10 +240,10 @@ public void Contains_Skip_Take_With_Comparer_And_NotContains_Must_ReturnFalse(in public void Contains_Skip_Take_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) { // Arrange - var value = - System.Linq.Enumerable.Last( - System.Linq.Enumerable.Take( - System.Linq.Enumerable.Skip(source, skip), take)); + var value = source + .Skip(skip) + .Take(take) + .Last(); var wrapped = Wrap.AsValueReadOnlyList(source); // Act diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyMemory.Tests.cs deleted file mode 100644 index 3504a5239..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyMemory.Tests.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Contains -{ - public class ReadOnlyMemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = default(string); - var wrapped = source.Select(item => item.ToString()).ToArray(); - - // Act - var result = ((ReadOnlyMemory)wrapped.AsMemory()).AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = Enumerable.Last(source); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = Enumerable.Last(source).ToString(); - var wrapped = source.Select(item => item.ToString()).ToArray(); - - // Act - var result = ((ReadOnlyMemory)wrapped.AsMemory()).AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = Enumerable.Last(source); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - var value = int.MaxValue; - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Contains(value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = Enumerable.Last(source); - - // Act - var result = ((ReadOnlyMemory)source.AsMemory()).AsValueEnumerable() - .Contains(value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs index 6530a8896..0cf850180 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs @@ -1,6 +1,7 @@ +using NetFabric.Assertive; using System; using System.Collections.Generic; -using NetFabric.Assertive; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Contains @@ -14,11 +15,12 @@ public class ReadOnlySpanTests public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Contains((ReadOnlySpan)source.AsSpan(), value); + var result = wrapped.AsValueEnumerable() + .Contains(value); // Assert _ = result.Must() @@ -32,12 +34,12 @@ public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = default(string); + const string value = default; var wrapped = source.AsValueEnumerable().Select(item => item.ToString()).ToArray(); // Act - var result = ArrayExtensions - .Contains((ReadOnlySpan)wrapped.AsSpan(), value); + var result = wrapped.AsValueEnumerable() + .Contains(value); // Assert _ = result.Must() @@ -50,11 +52,12 @@ public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(in public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source); + var value = source.Last(); + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Contains((ReadOnlySpan)source.AsSpan(), value); + var result = wrapped.AsValueEnumerable() + .Contains(value); // Assert _ = result.Must() @@ -67,12 +70,12 @@ public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] sour public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source).ToString(); + var value = source.Last().ToString(); var wrapped = source.AsValueEnumerable().Select(item => item.ToString()).ToArray(); // Act - var result = ArrayExtensions - .Contains((ReadOnlySpan)wrapped.AsSpan(), value); + var result = wrapped.AsValueEnumerable() + .Contains(value); // Assert _ = result.Must() @@ -86,11 +89,12 @@ public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Contains((ReadOnlySpan)source.AsSpan(), value, EqualityComparer.Default); + var result = wrapped.AsValueEnumerable() + .Contains(value, EqualityComparer.Default); // Assert _ = result.Must() @@ -103,11 +107,12 @@ public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source); + var value = source.Last(); + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Contains((ReadOnlySpan)source.AsSpan(), value, EqualityComparer.Default); + var result = wrapped.AsValueEnumerable() + .Contains(value, EqualityComparer.Default); // Assert _ = result.Must() @@ -121,11 +126,12 @@ public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] sou public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Contains((ReadOnlySpan)source.AsSpan(), value, TestComparer.Instance); + var result = wrapped.AsValueEnumerable() + .Contains(value, TestComparer.Instance); // Assert _ = result.Must() @@ -138,11 +144,12 @@ public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source); + var value = source.Last(); + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ArrayExtensions - .Contains((ReadOnlySpan)source.AsSpan(), value, TestComparer.Instance); + var result = wrapped.AsValueEnumerable() + .Contains(value, TestComparer.Instance); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs index b4a85bd10..892a045e1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs @@ -1,7 +1,6 @@ -using System; +using NetFabric.Assertive; using System.Collections.Generic; using System.Linq; -using NetFabric.Assertive; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Contains @@ -15,12 +14,12 @@ public class ValueEnumerableTests public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value); + var result = wrapped + .Contains, Wrap.Enumerator, int>(value); // Assert _ = result.Must() @@ -34,12 +33,12 @@ public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = default(string); + const string value = default; var wrapped = Wrap.AsValueEnumerable(source.Select(item => item.ToString()).ToArray()); // Act - var result = ValueEnumerableExtensions - .Contains, Wrap.Enumerator, string>(wrapped, value); + var result = wrapped + .Contains, Wrap.Enumerator, string>(value); // Assert _ = result.Must() @@ -52,12 +51,13 @@ public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(in public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value); + var result = wrapped + .Contains, Wrap.Enumerator, int>(value); // Assert _ = result.Must() @@ -70,12 +70,14 @@ public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] sour public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = Enumerable.Last(source).ToString(); + var value = source + .Last() + .ToString(); var wrapped = Wrap.AsValueEnumerable(source.Select(item => item.ToString()).ToArray()); // Act - var result = ValueEnumerableExtensions - .Contains, Wrap.Enumerator, string>(wrapped, value); + var result = wrapped + .Contains, Wrap.Enumerator, string>(value); // Assert _ = result.Must() @@ -89,12 +91,12 @@ public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value, EqualityComparer.Default); + var result = wrapped + .Contains, Wrap.Enumerator, int>(value, EqualityComparer.Default); // Assert _ = result.Must() @@ -107,12 +109,13 @@ public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value, EqualityComparer.Default); + var result = wrapped + .Contains, Wrap.Enumerator, int>(value, EqualityComparer.Default); // Assert _ = result.Must() @@ -126,12 +129,12 @@ public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] sou public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value, TestComparer.Instance); + var result = wrapped + .Contains, Wrap.Enumerator, int>(value, TestComparer.Instance); // Assert _ = result.Must() @@ -144,12 +147,13 @@ public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value, TestComparer.Instance); + var result = wrapped + .Contains, Wrap.Enumerator, int>(value, TestComparer.Instance); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs index 4b0bfc620..53919e908 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs @@ -1,6 +1,6 @@ -using System; -using System.Collections.Generic; using NetFabric.Assertive; +using System.Collections.Generic; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Contains @@ -14,7 +14,7 @@ public class ValueReadOnlyCollectionTests public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act @@ -33,7 +33,7 @@ public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = default(string); + const string value = default; var wrapped = Wrap.AsValueReadOnlyCollection(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); // Act @@ -51,7 +51,8 @@ public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(in public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act @@ -69,7 +70,9 @@ public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] sour public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source).ToString(); + var value = source + .Last() + .ToString(); var wrapped = Wrap.AsValueReadOnlyCollection(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); // Act @@ -88,7 +91,7 @@ public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act @@ -106,7 +109,8 @@ public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act @@ -125,7 +129,7 @@ public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] sou public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act @@ -143,7 +147,8 @@ public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source); + var value = source + .Last(); var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.Tests.cs index 7b1465500..f78d79f91 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Quantifier.ContainsVector @@ -14,10 +15,11 @@ public class ReadOnlySpanTests public void ContainsVector_With_NotContains_Must_ReturnFalse(int[] source) { // Arrange - var value = int.MaxValue; + const int value = int.MaxValue; + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ((ReadOnlySpan)source.AsSpan()) + var result = wrapped.AsValueEnumerable() .ContainsVector(value); // Assert @@ -31,10 +33,12 @@ public void ContainsVector_With_NotContains_Must_ReturnFalse(int[] source) public void ContainsVector_With_Contains_Must_ReturnTrue(int[] source) { // Arrange - var value = System.Linq.Enumerable.Last(source); + var value = source + .Last(); + var wrapped = (ReadOnlySpan)source.AsSpan(); // Act - var result = ((ReadOnlySpan)source.AsSpan()) + var result = wrapped.AsValueEnumerable() .ContainsVector(value); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Array.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Array.Tests.cs deleted file mode 100644 index 052cf32d6..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Array.Tests.cs +++ /dev/null @@ -1,121 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Set.Distinct -{ - public class ArrayTests - { - [Theory] - [InlineData(200)] - public void Distinct_With_LargeData_Must_Succeed(int count) - { - // Arrange - var source = ValueEnumerable.Range(0, count).ToArray(); - var expected = Enumerable - .Distinct(source); - - // Act - var result = source.AsValueEnumerable() - .Distinct(); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Distinct(source); - - // Act - var result = source.AsValueEnumerable() - .Distinct(); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Distinct(source) - .ToArray(); - - // Act - var result = source.AsValueEnumerable() - .Distinct() - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = Enumerable - .Distinct(source) - .ToArray(); - - // Act - using var result = source.AsValueEnumerable() - .Distinct() - .ToArray(pool); - - // Assert - _ = result - .SequenceEqual(expected) - .Must().BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = Enumerable - .Distinct(source) - .ToList(); - - // Act - var result = source.AsValueEnumerable() - .Distinct() - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs index e2afa1218..64a448b3d 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs @@ -16,8 +16,8 @@ public void Distinct_With_NullArray_Must_Succeed() var expected = Enumerable.Empty(); // Act - var result = ArrayExtensions - .Distinct(source); + var result = source.AsValueEnumerable() + .Distinct(); // Assert _ = result.Must() @@ -35,12 +35,12 @@ public void Distinct_With_ValidData_Must_Succeed(int[] source, int skip, int tak // Arrange var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Distinct(wrapped); + var expected = wrapped + .Distinct(); // Act - var result = ArrayExtensions - .Distinct(wrapped); + var result = wrapped.AsValueEnumerable() + .Distinct(); // Assert _ = result.Must() @@ -58,13 +58,13 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source, int skip, // Arrange var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Distinct(wrapped) + var expected = wrapped + .Distinct() .ToArray(); // Act - var result = ArrayExtensions - .Distinct(wrapped) + var result = wrapped.AsValueEnumerable() + .Distinct() .ToArray(); // Assert @@ -83,13 +83,13 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source var pool = MemoryPool.Shared; var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Distinct(wrapped) + var expected = wrapped + .Distinct() .ToArray(); // Act - using var result = ArrayExtensions - .Distinct(wrapped) + using var result = wrapped.AsValueEnumerable() + .Distinct() .ToArray(pool); // Assert @@ -106,13 +106,13 @@ public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source, int skip, // Arrange var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = Enumerable - .Distinct(wrapped) + var expected = wrapped + .Distinct() .ToList(); // Act - var result = ArrayExtensions - .Distinct(wrapped) + var result = wrapped.AsValueEnumerable() + .Distinct() .ToList(); // Assert @@ -120,5 +120,28 @@ public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source, int skip, .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void Distinct_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take) + { + // Arrange + var (offset, count) = Utils.SkipTake(source.Length, skip, take); + var wrapped = new ArraySegment(source, offset, count); + var expected = wrapped + .Distinct() + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Distinct() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs index e693720cc..acd226fa8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System.Buffers; +using System.Linq; using System.Threading.Tasks; using Xunit; @@ -15,12 +16,12 @@ public void Distinct_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = - System.Linq.Enumerable.Distinct(source); + var expected = source + .Distinct(); // Act - var result = AsyncValueEnumerableExtensions - .Distinct, Wrap.AsyncEnumerator, int>(wrapped); + var result = wrapped + .Distinct, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Must() @@ -36,13 +37,13 @@ public async ValueTask Distinct_ToArrayAsync_With_ValidData_Must_Succeed(int[] s { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = - System.Linq.Enumerable.ToArray( - System.Linq.Enumerable.Distinct(source)); + var expected = source + .Distinct() + .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Distinct, Wrap.AsyncEnumerator, int>(wrapped) + var result = await wrapped + .Distinct, Wrap.AsyncEnumerator, int>() .ToArrayAsync(); // Assert @@ -60,13 +61,13 @@ public async ValueTask Distinct_ToArrayAsync_MemoryPool_With_ValidData_Must_Succ // Arrange var pool = MemoryPool.Shared; var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = - System.Linq.Enumerable.ToArray( - System.Linq.Enumerable.Distinct(source)); + var expected = source + .Distinct() + .ToArray(); // Act - var result = await AsyncValueEnumerableExtensions - .Distinct, Wrap.AsyncEnumerator, int>(wrapped) + var result = await wrapped + .Distinct, Wrap.AsyncEnumerator, int>() .ToArrayAsync(pool); // Assert @@ -82,13 +83,13 @@ public async ValueTask Distinct_ToListAsync_With_ValidData_Must_Succeed(int[] so { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = - System.Linq.Enumerable.ToList( - System.Linq.Enumerable.Distinct(source)); + var expected = source + .Distinct() + .ToList(); // Act - var result = await AsyncValueEnumerableExtensions - .Distinct, Wrap.AsyncEnumerator, int>(wrapped) + var result = await wrapped + .Distinct, Wrap.AsyncEnumerator, int>() .ToListAsync(); // Assert @@ -96,5 +97,27 @@ public async ValueTask Distinct_ToListAsync_With_ValidData_Must_Succeed(int[] so .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public async ValueTask Distinct_SumAsync_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsAsyncValueEnumerable(source); + var expected = source + .Distinct() + .Sum(); + + // Act + var result = await wrapped + .Distinct, Wrap.AsyncEnumerator, int>() + .SumAsync().ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Memory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Memory.Tests.cs deleted file mode 100644 index 3c2e8d81b..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.Memory.Tests.cs +++ /dev/null @@ -1,97 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Buffers; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Set.Distinct -{ - public class MemoryTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = - System.Linq.Enumerable.Distinct(source); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Distinct(); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false, testRefReturns: false); - _ = result.SequenceEqual(expected).Must().BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = - System.Linq.Enumerable.ToArray( - System.Linq.Enumerable.Distinct(source)); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Distinct() - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var pool = MemoryPool.Shared; - var expected = - System.Linq.Enumerable.ToArray( - System.Linq.Enumerable.Distinct(source)); - - // Act - using var result = source.AsMemory().AsValueEnumerable() - .Distinct() - .ToArray(pool); - - // Assert - _ = result - .SequenceEqual(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var expected = - System.Linq.Enumerable.ToList( - System.Linq.Enumerable.Distinct(source)); - - // Act - var result = source.AsMemory().AsValueEnumerable() - .Distinct() - .ToList(); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs index d2d1c4d25..ecd8f4315 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs @@ -1,6 +1,5 @@ using NetFabric.Assertive; using System.Buffers; -using System.ComponentModel; using System.Linq; using Xunit; @@ -16,8 +15,8 @@ public void Distinct_With_ValidData_Must_Succeed(int[] source, int skip, int tak { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Distinct(); @@ -41,8 +40,8 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source, int skip, { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Distinct() .ToArray(); @@ -69,8 +68,8 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source // Arrange var pool = MemoryPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Distinct() .ToArray(); @@ -95,8 +94,8 @@ public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source, int skip, { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Distinct() .ToList(); @@ -113,5 +112,31 @@ public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source, int skip, .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void Distinct_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take) + { + // Arrange + var wrapped = Wrap.AsReadOnlyList(source); + var expected = source + .Skip(skip) + .Take(take) + .Distinct() + .Sum(); + + // Act + var result = wrapped + .Skip(skip) + .Take(take) + .Distinct() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs index 7172f9f44..aec1fa52f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs @@ -1,6 +1,7 @@ using NetFabric.Assertive; using System; using System.Buffers; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Set.Distinct @@ -14,12 +15,13 @@ public class ReadOnlyMemoryTests public void Distinct_With_ValidData_Must_Succeed(int[] source) { // Arrange - var expected = - System.Linq.Enumerable.Distinct(source); + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Distinct(); // Act - var result = ArrayExtensions - .Distinct((ReadOnlyMemory)source.AsMemory()); + var result = wrapped.AsValueEnumerable() + .Distinct(); // Assert _ = result.Must() @@ -35,13 +37,13 @@ public void Distinct_With_ValidData_Must_Succeed(int[] source) public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) { // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); var expected = - System.Linq.Enumerable.ToArray( - System.Linq.Enumerable.Distinct(source)); + source.Distinct().ToArray(); // Act - var result = ArrayExtensions - .Distinct((ReadOnlyMemory)source.AsMemory()) + var result = wrapped.AsValueEnumerable() + .Distinct() .ToArray(); // Assert @@ -58,13 +60,14 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source { // Arrange var pool = MemoryPool.Shared; - var expected = - System.Linq.Enumerable.ToArray( - System.Linq.Enumerable.Distinct(source)); + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Distinct() + .ToArray(); // Act - using var result = ArrayExtensions - .Distinct((ReadOnlyMemory)source.AsMemory()) + using var result = wrapped.AsValueEnumerable() + .Distinct() .ToArray(pool); // Assert @@ -79,13 +82,14 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) { // Arrange - var expected = - System.Linq.Enumerable.ToList( - System.Linq.Enumerable.Distinct(source)); + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Distinct() + .ToList(); // Act - var result = ArrayExtensions - .Distinct((ReadOnlyMemory)source.AsMemory()) + var result = wrapped.AsValueEnumerable() + .Distinct() .ToList(); // Assert @@ -93,5 +97,27 @@ public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Distinct_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Distinct() + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Distinct() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs index 1b6b18661..69814c95b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs @@ -15,12 +15,13 @@ public class ReadOnlySpanTests public void Distinct_With_ValidData_Must_Succeed(int[] source) { // Arrange - var expected = Enumerable - .Distinct(source); + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Distinct(); // Act - var result = ArrayExtensions - .Distinct((ReadOnlySpan)source.AsSpan()); + var result = wrapped.AsValueEnumerable() + .Distinct(); // Assert _ = result.SequenceEqual(expected).Must().BeTrue(); @@ -33,13 +34,14 @@ public void Distinct_With_ValidData_Must_Succeed(int[] source) public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) { // Arrange - var expected = Enumerable - .Distinct(source) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Distinct() .ToArray(); // Act - var result = ArrayExtensions - .Distinct((ReadOnlySpan)source.AsSpan()) + var result = wrapped.AsValueEnumerable() + .Distinct() .ToArray(); // Assert @@ -55,13 +57,14 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source) { // Arrange - var expected = Enumerable - .Distinct(source) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Distinct() .ToArray(); // Act - using var result = ArrayExtensions - .Distinct((ReadOnlySpan)source.AsSpan()) + using var result = wrapped.AsValueEnumerable() + .Distinct() .ToArray(MemoryPool.Shared); // Assert @@ -76,13 +79,14 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) { // Arrange - var expected = Enumerable - .Distinct(source) + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Distinct() .ToList(); // Act - var result = ArrayExtensions - .Distinct((ReadOnlySpan)source.AsSpan()) + var result = wrapped.AsValueEnumerable() + .Distinct() .ToList(); // Assert @@ -90,5 +94,6 @@ public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) .BeEnumerableOf() .BeEqualTo(expected); } + } } diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs index 9e67dfb2a..226016257 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs @@ -15,12 +15,12 @@ public void Distinct_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); - var expected = Enumerable - .Distinct(wrapped); + var expected = source + .Distinct(); // Act - var result = ValueEnumerableExtensions - .Distinct, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .Distinct, Wrap.Enumerator, int>(); // Assert _ = result.Must() @@ -36,13 +36,13 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); - var expected = Enumerable - .Distinct(source) + var expected = source + .Distinct() .ToArray(); // Act - var result = ValueEnumerableExtensions - .Distinct, Wrap.Enumerator, int>(wrapped) + var result = wrapped + .Distinct, Wrap.Enumerator, int>() .ToArray(); // Assert @@ -60,13 +60,13 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source // Arrange var pool = MemoryPool.Shared; var wrapped = Wrap.AsValueEnumerable(source); - var expected = Enumerable - .Distinct(source) + var expected = source + .Distinct() .ToArray(); // Act - using var result = ValueEnumerableExtensions - .Distinct, Wrap.Enumerator, int>(wrapped) + using var result = wrapped + .Distinct, Wrap.Enumerator, int>() .ToArray(pool); // Assert @@ -82,13 +82,13 @@ public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); - var expected = Enumerable - .Distinct(source) + var expected = source + .Distinct() .ToList(); // Act - var result = ValueEnumerableExtensions - .Distinct, Wrap.Enumerator, int>(wrapped) + var result = wrapped + .Distinct, Wrap.Enumerator, int>() .ToList(); // Assert @@ -96,5 +96,27 @@ public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Distinct_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsValueEnumerable(source); + var expected = source + .Distinct() + .Sum(); + + // Act + var result = wrapped + .Distinct, Wrap.Enumerator, int>() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs index 4f57418de..63f6670c4 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs @@ -8,9 +8,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static AsyncEnumerableWrapper AsAsyncEnumerable(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new AsyncEnumerableWrapper(source) + }; public readonly struct AsyncEnumerableWrapper : IAsyncEnumerable @@ -21,7 +23,7 @@ internal AsyncEnumerableWrapper(T[] source) => this.source = source; public readonly AsyncEnumerator GetAsyncEnumerator() - => new AsyncEnumerator(source); + => new(source); readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) => new AsyncEnumerator(source); } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs index 3e4f5ece8..663592227 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs @@ -8,9 +8,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static AsyncValueEnumerableWrapper AsAsyncValueEnumerable(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new AsyncValueEnumerableWrapper(source) + }; public readonly struct AsyncValueEnumerableWrapper : IAsyncValueEnumerable> @@ -21,9 +23,9 @@ internal AsyncValueEnumerableWrapper(T[] source) => this.source = source; public readonly AsyncEnumerator GetAsyncEnumerator() - => new AsyncEnumerator(source); + => new(source); readonly AsyncEnumerator IAsyncValueEnumerable>.GetAsyncEnumerator(CancellationToken _) - => new AsyncEnumerator(source); + => new(source); readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) => new AsyncEnumerator(source); } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs index 35c83b075..cda9174a7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs @@ -7,9 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static CollectionWrapper AsCollection(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new CollectionWrapper(source) + }; public class CollectionWrapper : ReadOnlyCollectionWrapper diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs index f210e7316..f8f28551d 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs @@ -7,9 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static EnumerableWrapper AsEnumerable(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new EnumerableWrapper(source) + }; public class EnumerableWrapper : IEnumerable @@ -20,7 +22,7 @@ internal EnumerableWrapper(T[] source) => this.source = source; public Enumerator GetEnumerator() - => new Enumerator(source); + => new(source); IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); IEnumerator IEnumerable.GetEnumerator() diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs index 9b6d8fdc5..d7dd17d0e 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs @@ -7,9 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static ListWrapper AsList(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new ListWrapper(source) + }; public class ListWrapper : ReadOnlyListWrapper diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs index 6c6762bc4..ea287ddbd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs @@ -7,9 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static ReadOnlyCollectionWrapper AsReadOnlyCollection(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new ReadOnlyCollectionWrapper(source) + }; public class ReadOnlyCollectionWrapper : EnumerableWrapper diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs index f7e7b019e..d4e4e5621 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs @@ -7,9 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static ReadOnlyListWrapper AsReadOnlyList(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new ReadOnlyListWrapper(source) + }; public class ReadOnlyListWrapper : ReadOnlyCollectionWrapper diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs index 948033e83..f9c8c6706 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs @@ -7,9 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static ValueCollectionWrapper AsValueCollection(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new ValueCollectionWrapper(source) + }; public readonly struct ValueCollectionWrapper : IValueReadOnlyCollection> @@ -24,7 +26,7 @@ public readonly int Count => source.Length; public readonly Enumerator GetEnumerator() - => new Enumerator(source); + => new(source); readonly IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs index 07d94b57a..8b9660465 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs @@ -7,10 +7,12 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static ValueEnumerableWrapper AsValueEnumerable(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); - + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new ValueEnumerableWrapper(source) + }; + public readonly struct ValueEnumerableWrapper : IValueEnumerable> { @@ -20,11 +22,14 @@ internal ValueEnumerableWrapper(T[] source) => this.source = source; public readonly Enumerator GetEnumerator() - => new Enumerator(source); + => new(source); readonly IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); + + public ValueEnumerableWrapper AsValueEnumerable() + => this.AsValueEnumerable, Enumerator, T>(); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs index f731165b2..2a5a9c285 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs @@ -7,9 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static ValueListWrapper AsValueList(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new ValueListWrapper(source) + }; public readonly struct ValueListWrapper : IValueReadOnlyList> @@ -33,7 +35,7 @@ T IList.this[int index] } public readonly Enumerator GetEnumerator() - => new Enumerator(source); + => new(source); readonly IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs index 79225b9e3..aef6a4fc5 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs @@ -7,9 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static ValueReadOnlyCollectionWrapper AsValueReadOnlyCollection(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new ValueReadOnlyCollectionWrapper(source) + }; public readonly struct ValueReadOnlyCollectionWrapper : IValueReadOnlyCollection> @@ -23,7 +25,7 @@ public readonly int Count => source.Length; public readonly Enumerator GetEnumerator() - => new Enumerator(source); + => new(source); readonly IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs index 709add857..02098845c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs @@ -7,9 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class Wrap { public static ValueReadOnlyListWrapper AsValueReadOnlyList(T[] source) - => source is null - ? throw new ArgumentNullException(nameof(source)) - : new(source); + => source switch + { + null => throw new ArgumentNullException(nameof(source)), + _ => new ValueReadOnlyListWrapper(source) + }; public readonly struct ValueReadOnlyListWrapper : IValueReadOnlyList> @@ -26,7 +28,7 @@ public readonly T this[int index] => source[index]; public readonly Enumerator GetEnumerator() - => new Enumerator(source); + => new(source); readonly IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs index 2ead5fcf6..f933d6fdd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs @@ -23,7 +23,7 @@ public readonly T Current => source[index]; public ValueTask MoveNextAsync() - => new ValueTask(++index < source.Length); + => new(++index < source.Length); public readonly ValueTask DisposeAsync() => default; } diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs index febb91e25..676997d87 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs @@ -68,7 +68,7 @@ internal static TSum Sum(this TEnumerable source, TSelector selector) + internal static TSum SumAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs index b25ab7ee9..c4612eb8f 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs @@ -4,6 +4,16 @@ namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyCollectionExtensions { + static TSum Sum(this TEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSum : struct + => source switch + { + {Count: 0} => default, + _ => ValueEnumerableExtensions.Sum(source) + }; + static TSum Sum(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -25,6 +35,40 @@ static TSum SumAt(this TEnu {Count: 0} => default, _ => ValueEnumerableExtensions.SumAt(source, predicate) }; + + static TSum Sum(this TEnumerable source, TSelector selector) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector: struct, IFunction + where TSum : struct + => source switch + { + {Count: 0} => default, + _ => ValueEnumerableExtensions.Sum(source, selector) + }; + + static TSum SumAt(this TEnumerable source, TSelector selector) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + where TSum : struct + => source switch + { + {Count: 0} => default, + _ => ValueEnumerableExtensions.SumAt(source, selector) + }; + + static TSum Sum(this TEnumerable source, TPredicate predicate, TSelector selector) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate: struct, IFunction + where TSelector: struct, IFunction + where TSum : struct + => source switch + { + {Count: 0} => default, + _ => ValueEnumerableExtensions.Sum(source, predicate, selector) + }; } } diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs new file mode 100644 index 000000000..5a7398494 --- /dev/null +++ b/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs @@ -0,0 +1,148 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace NetFabric.Hyperlinq +{ + public static partial class AsyncValueEnumerableExtensions + { + public static async ValueTask SumAsync(this TEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSum : struct + { + var sum = default(TSum); + var enumerator = source.GetAsyncEnumerator(cancellationToken); + try + { + while (await enumerator.MoveNextAsync().ConfigureAwait(false)) + sum = GenericsOperator.AddNullable(enumerator.Current, sum); + } + finally + { + await enumerator.DisposeAsync().ConfigureAwait(false); + } + return sum; + } + + internal static async ValueTask SumAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSum : struct + { + var sum = default(TSum); + var enumerator = source.GetAsyncEnumerator(cancellationToken); + try + { + while (await enumerator.MoveNextAsync().ConfigureAwait(false)) + { + var item = enumerator.Current; + if (await predicate.InvokeAsync(item, cancellationToken).ConfigureAwait(false)) + sum = GenericsOperator.AddNullable(item, sum); + } + } + finally + { + await enumerator.DisposeAsync().ConfigureAwait(false); + } + return sum; + } + + internal static async ValueTask SumAtAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSum : struct + { + var sum = default(TSum); + var enumerator = source.GetAsyncEnumerator(cancellationToken); + try + { + for (var index = 0; await enumerator.MoveNextAsync().ConfigureAwait(false); index++) + { + var item = enumerator.Current; + if (await predicate.InvokeAsync(item, index, cancellationToken).ConfigureAwait(false)) + sum = GenericsOperator.AddNullable(item, sum); + } + } + finally + { + await enumerator.DisposeAsync().ConfigureAwait(false); + } + return sum; + } + + internal static async ValueTask SumAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + where TSum : struct + { + var sum = default(TSum); + var enumerator = source.GetAsyncEnumerator(cancellationToken); + try + { + while (await enumerator.MoveNextAsync().ConfigureAwait(false)) + { + var item = enumerator.Current; + sum = GenericsOperator.AddNullable(await selector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), sum); + } + } + finally + { + await enumerator.DisposeAsync().ConfigureAwait(false); + } + return sum; + } + + internal static async ValueTask SumAtAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + where TSum : struct + { + var sum = default(TSum); + var enumerator = source.GetAsyncEnumerator(cancellationToken); + try + { + for (var index = 0; await enumerator.MoveNextAsync().ConfigureAwait(false); index++) + { + var item = enumerator.Current; + sum = GenericsOperator.AddNullable(await selector.InvokeAsync(item, index, cancellationToken).ConfigureAwait(false), sum); + } + } + finally + { + await enumerator.DisposeAsync().ConfigureAwait(false); + } + return sum; + } + + internal static async ValueTask SumAsync(this TEnumerable source, TPredicate predicate, TSelector selector, CancellationToken cancellationToken) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + where TSum : struct + { + var sum = default(TSum); + var enumerator = source.GetAsyncEnumerator(cancellationToken); + try + { + while (await enumerator.MoveNextAsync().ConfigureAwait(false)) + { + var item = enumerator.Current; + if (await predicate.InvokeAsync(item, cancellationToken).ConfigureAwait(false)) + sum = GenericsOperator.AddNullable(await selector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), sum); + } + } + finally + { + await enumerator.DisposeAsync().ConfigureAwait(false); + } + return sum; + } + } +} + diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs index 0cf1fc697..74942f074 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs @@ -15,7 +15,6 @@ public static AsyncValueEnumerableWrapper AsAsyncValueEnumerable new(source); [GeneratorIgnore] // TODO: to be removed - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerableWrapper AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator) where TEnumerable : IAsyncEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index 96de369c3..3ea24f837 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -84,5 +84,45 @@ public bool Contains(TSource value, IEqualityComparer? comparer) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this ValueEnumerable source) => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, decimal?, decimal>(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index c90e6643b..4d24ff86e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -80,11 +80,15 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - => ((ICollection)source).Contains(item); + => source.Count switch + { + 0 => false, + _ => Array.IndexOf(source.Array!, item, source.Offset, source.Count) >= 0 + }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int IndexOf(TSource item) - => ArrayExtensions.IndexOf(((ReadOnlySpan)source.AsSpan()), item); + => ArrayExtensions.IndexOf(source.AsSpan(), item); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -382,24 +386,24 @@ public static bool ContainsVector(this ArraySegmentValueEnumerable ((ReadOnlySpan)source.source.AsSpan()).ContainsVector(value); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static MemorySelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ArraySegmentValueEnumerable source, Func, Vector> vectorSelector, Func selector) + public static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ArraySegmentValueEnumerable source, Func, Vector> vectorSelector, Func selector) where TSource : struct where TResult : struct - => source.source.SelectVector(vectorSelector, selector); + => ((ReadOnlySpan)source.source.AsSpan()).SelectVector(vectorSelector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static MemorySelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TSelector selector = default) + public static SpanSelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TSelector selector = default) where TSelector : struct, IFunction, Vector>, IFunction where TSource : struct where TResult : struct - => source.source.SelectVector(selector, selector); + => ((ReadOnlySpan)source.source.AsSpan()).SelectVector(selector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static MemorySelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TVectorSelector vectorSelector = default, TSelector selector = default) + public static SpanSelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TVectorSelector vectorSelector = default, TSelector selector = default) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct where TResult : struct - => source.source.SelectVector(vectorSelector, selector); + => ((ReadOnlySpan)source.source.AsSpan()).SelectVector(vectorSelector, selector); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index 4b28f95ca..a33b43fda 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -223,11 +223,14 @@ public MemoryWhereAtEnumerable WhereAt(TPredica [MethodImpl(MethodImplOptions.AggressiveInlining)] public MemoryValueEnumerable Skip(int count) - => new(source.Skip(count)); + { + var (skipCount, takeCount) = Utils.Skip(source.Length, count); + return new MemoryValueEnumerable(source.Slice(skipCount, takeCount)); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public MemoryValueEnumerable Take(int count) - => new(source.Take(count)); + => new(source.Slice(0, Utils.Take(source.Length, count))); #endregion @@ -373,17 +376,17 @@ public static bool ContainsVector(this MemoryValueEnumerable s => source.source.Span.ContainsVector(value); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static MemorySelectVectorContext, Vector>, FunctionWrapper> SelectVector(this MemoryValueEnumerable source, Func, Vector> vectorSelector, Func selector) + public static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this MemoryValueEnumerable source, Func, Vector> vectorSelector, Func selector) where TSource : struct where TResult : struct - => source.source.SelectVector(vectorSelector, selector); + => source.source.Span.SelectVector(vectorSelector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static MemorySelectVectorContext SelectVector(this MemoryValueEnumerable source, TVectorSelector vectorSelector = default, TSelector selector = default) + public static SpanSelectVectorContext SelectVector(this MemoryValueEnumerable source, TVectorSelector vectorSelector = default, TSelector selector = default) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct where TResult : struct - => source.source.SelectVector(vectorSelector, selector); + => source.source.Span.SelectVector(vectorSelector, selector); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index 7979c5119..9e04b1678 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -129,11 +129,14 @@ public SpanWhereAtEnumerable WhereAt(TPredicate [MethodImpl(MethodImplOptions.AggressiveInlining)] public SpanValueEnumerable Skip(int count) - => new(source.Skip(count)); + { + var (skipCount, takeCount) = Utils.Skip(source.Length, count); + return new SpanValueEnumerable(source.Slice(skipCount, takeCount)); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SpanValueEnumerable Take(int count) - => new(source.Take(count)); + => new(source.Slice(0, Utils.Take(source.Length, count))); #endregion diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs index 4fb246a66..f4d5bb954 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs @@ -7,11 +7,6 @@ namespace NetFabric.Hyperlinq { public static partial class ReadOnlyListExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TSource[] ToArray(this TList source) - where TList : struct, IReadOnlyList - => source.ToArray(0, source.Count); - [MethodImpl(MethodImplOptions.AggressiveInlining)] static TSource[] ToArray(this TList source, int offset, int count) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs index 9c195512f..c83d06289 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs @@ -7,11 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this ReadOnlySpan source, Func keySelector, IEqualityComparer? comparer = null) + static Dictionary ToDictionary(this ReadOnlySpan source, Func keySelector, IEqualityComparer? comparer = null) where TKey : notnull => source.ToDictionary(new FunctionWrapper(keySelector), comparer); - public static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer = null) + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer = null) where TKey : notnull where TKeySelector : struct, IFunction { @@ -75,11 +75,11 @@ static Dictionary ToDictionary ToDictionary(this ReadOnlySpan source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = null) + static Dictionary ToDictionary(this ReadOnlySpan source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = null) where TKey : notnull => source.ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - public static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = null) + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = null) where TKey : notnull where TKeySelector : struct, IFunction where TElementSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.Span.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.Span.cs deleted file mode 100644 index adf7d9a86..000000000 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.Span.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this Span source, Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ((ReadOnlySpan)source).ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this Span source, TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - => ((ReadOnlySpan)source).ToDictionary(keySelector, comparer); - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this Span source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ((ReadOnlySpan)source).ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this Span source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => ((ReadOnlySpan)source).ToDictionary(keySelector, elementSelector, comparer); - } -} - diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs index df32dcba2..57f85e4a6 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs @@ -11,7 +11,7 @@ public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static List ToList(this ReadOnlySpan source) + static List ToList(this ReadOnlySpan source) => source switch { { Length: 0 } => new List(), diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.Span.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.Span.cs deleted file mode 100644 index 9e378b0a7..000000000 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.Span.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static List ToList(this Span source) - => ((ReadOnlySpan)source).ToList(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs index 128f93162..793f50ca6 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - public static Option ElementAt(this TList source, int index) + static Option ElementAt(this TList source, int index) where TList : struct, IReadOnlyList => source.ElementAt(index,0, source.Count); diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs index d72d8e6a7..4e57e37c3 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs @@ -8,7 +8,7 @@ public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Option ElementAt(this ReadOnlySpan source, int index) + static Option ElementAt(this ReadOnlySpan source, int index) => index < 0 || index >= source.Length ? Option.None : Option.Some(source[index]); diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.Span.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.Span.cs deleted file mode 100644 index 43d0f7327..000000000 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.Span.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Option ElementAt(this Span source, int index) - => ((ReadOnlySpan)source).ElementAt(index); - } -} diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs index ef8add524..4d09c68fa 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - public static Option First(this TList source) + static Option First(this TList source) where TList : struct, IReadOnlyList => source.First(0, source.Count); diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs index 2b0c768dd..cb0afa961 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs @@ -7,7 +7,7 @@ public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Option First(this ReadOnlySpan source) + static Option First(this ReadOnlySpan source) => source switch { { Length: 0 } => Option.None, diff --git a/NetFabric.Hyperlinq/Element/First/First.Span.cs b/NetFabric.Hyperlinq/Element/First/First.Span.cs deleted file mode 100644 index 4a1037d4a..000000000 --- a/NetFabric.Hyperlinq/Element/First/First.Span.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Option First(this Span source) - => ((ReadOnlySpan)source).First(); - } -} diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs index 73870a923..ba8677014 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - public static Option Single(this TList source) + static Option Single(this TList source) where TList : struct, IReadOnlyList => source.Single(0, source.Count); diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs index b37218f35..d5119b401 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - public static Option Single(this ReadOnlySpan source) + static Option Single(this ReadOnlySpan source) => source switch { { Length: 1 } => Option.Some(source[0]), diff --git a/NetFabric.Hyperlinq/Element/Single/Single.Span.cs b/NetFabric.Hyperlinq/Element/Single/Single.Span.cs deleted file mode 100644 index 06e120ce0..000000000 --- a/NetFabric.Hyperlinq/Element/Single/Single.Span.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Option Single(this Span source) - => ((ReadOnlySpan)source).Single(); - } -} diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index f68cf0e39..14994feca 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -12,11 +12,11 @@ public static partial class ArrayExtensions { [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) + static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) => source.Where(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereEnumerable Where(this in ArraySegment source, TPredicate predicate = default) + static ArraySegmentWhereEnumerable Where(this in ArraySegment source, TPredicate predicate = default) where TPredicate : struct, IFunction => new(source, predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index 5d6770b94..cdf313e02 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -33,8 +33,8 @@ public readonly partial struct WhereEnumerable where TPredicate : struct, IAsyncFunction { - readonly TEnumerable source; - readonly TPredicate predicate; + internal readonly TEnumerable source; + internal readonly TPredicate predicate; internal WhereEnumerable(in TEnumerable source, TPredicate predicate) { @@ -339,6 +339,76 @@ public ValueTask> ToDictionaryAsync SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, cancellationToken); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs index 294522a7d..9d2e95454 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs @@ -40,10 +40,10 @@ public readonly partial struct WhereEnumerable where TList : struct, IReadOnlyList where TPredicate : struct, IFunction { - readonly TList source; - readonly TPredicate predicate; - readonly int offset; - readonly int count; + internal readonly TList source; + internal readonly TPredicate predicate; + internal readonly int offset; + internal readonly int count; internal WhereEnumerable(in TList source, TPredicate predicate, int offset, int count) => (this.source, this.offset, this.count, this.predicate) = (source, offset, count, predicate); @@ -284,6 +284,66 @@ public Dictionary ToDictionary(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate, source.offset, source.count); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index fde4eba10..ce7676d54 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -12,11 +12,11 @@ public static partial class ArrayExtensions { [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemoryWhereEnumerable> Where(this ReadOnlyMemory source, Func predicate) + static MemoryWhereEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.Where(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemoryWhereEnumerable Where(this ReadOnlyMemory source, TPredicate predicate = default) + static MemoryWhereEnumerable Where(this ReadOnlyMemory source, TPredicate predicate = default) where TPredicate : struct, IFunction => new(source, predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index 54640b020..c7258c98c 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -11,11 +11,11 @@ public static partial class ArrayExtensions [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereEnumerable> Where(this ReadOnlySpan source, Func predicate) + static SpanWhereEnumerable> Where(this ReadOnlySpan source, Func predicate) => source.Where(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereEnumerable Where(this ReadOnlySpan source, TPredicate predicate = default) + static SpanWhereEnumerable Where(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction => new(source, predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.Span.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.Span.cs deleted file mode 100644 index 7597f947b..000000000 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.Span.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereEnumerable> Where(this Span source, Func predicate) - => source.Where(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereEnumerable Where(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source).Where(predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index 164dd19b6..da4c84f07 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -236,75 +236,75 @@ public Dictionary ToDictionary(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, int, int, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static int Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, int?, int, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static long Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, long, long, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static long Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, long?, long, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static float Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, float, float, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static float Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, float?, float, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static double Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, double, double, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static double Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, double?, double, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static decimal Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, decimal, decimal, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static decimal Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, decimal?, decimal, TPredicate>(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index b4638e7ad..1839a17c6 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -236,75 +236,75 @@ public Dictionary ToDictionary(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, int, int, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static int Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, int?, int, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static long Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, long, long, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static long Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, long?, long, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static float Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, float, float, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static float Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, float?, float, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static double Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, double, double, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static double Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, double?, double, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static decimal Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, decimal, decimal, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static decimal Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, decimal?, decimal, TPredicate>(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index c95b9229c..89d3cdd11 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -12,11 +12,11 @@ public static partial class ArrayExtensions { [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereAtEnumerable> Where(this in ArraySegment source, Func predicate) + static ArraySegmentWhereAtEnumerable> Where(this in ArraySegment source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereAtEnumerable WhereAt(this in ArraySegment source, TPredicate predicate = default) + static ArraySegmentWhereAtEnumerable WhereAt(this in ArraySegment source, TPredicate predicate = default) where TPredicate : struct, IFunction => new(source, predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index 7b0ecfc5e..a05c9756d 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -33,8 +33,8 @@ public readonly partial struct WhereAtEnumerable where TPredicate : struct, IAsyncFunction { - readonly TEnumerable source; - readonly TPredicate predicate; + internal readonly TEnumerable source; + internal readonly TPredicate predicate; internal WhereAtEnumerable(in TEnumerable source, TPredicate predicate) { @@ -332,6 +332,76 @@ public ValueTask> ToDictionaryAsync SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(source.predicate, cancellationToken); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs index 055bc29e0..e7ea30d9c 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs @@ -41,10 +41,10 @@ public readonly partial struct WhereAtEnumerable where TList : struct, IReadOnlyList where TPredicate : struct, IFunction { - readonly TList source; - readonly TPredicate predicate; - readonly int offset; - readonly int count; + internal readonly TList source; + internal readonly TPredicate predicate; + internal readonly int offset; + internal readonly int count; internal WhereAtEnumerable(in TList source, TPredicate predicate, int offset, int count) => (this.source, this.offset, this.count, this.predicate) = (source, offset, count, predicate); @@ -300,6 +300,66 @@ public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer } } } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereAtEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate, source.offset, source.count); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index 517a440b3..63d96d236 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -13,11 +13,11 @@ public static partial class ArrayExtensions [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemoryWhereAtEnumerable> Where(this ReadOnlyMemory source, Func predicate) + static MemoryWhereAtEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemoryWhereAtEnumerable WhereAt(this ReadOnlyMemory source, TPredicate predicate = default) + static MemoryWhereAtEnumerable WhereAt(this ReadOnlyMemory source, TPredicate predicate = default) where TPredicate : struct, IFunction => new(source, predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index ad13e7012..49bf641b3 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -11,11 +11,11 @@ public static partial class ArrayExtensions [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereAtEnumerable> Where(this ReadOnlySpan source, Func predicate) + static SpanWhereAtEnumerable> Where(this ReadOnlySpan source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereAtEnumerable WhereAt(this ReadOnlySpan source, TPredicate predicate = default) + static SpanWhereAtEnumerable WhereAt(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction => new(source, predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.Span.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.Span.cs deleted file mode 100644 index 9918c0983..000000000 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.Span.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereAtEnumerable> Where(this Span source, Func predicate) - => source.WhereAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanWhereAtEnumerable WhereAt(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source).WhereAt(predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index bc3922a28..3e1385a21 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -233,75 +233,75 @@ public Dictionary ToDictionaryAt(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.SumAt, WhereEnumerable.Enumerator, int, int, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static int Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.SumAt, WhereEnumerable.Enumerator, int?, int, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static long Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.SumAt, WhereEnumerable.Enumerator, long, long, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static long Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.SumAt, WhereEnumerable.Enumerator, long?, long, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static float Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, float, float, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static float Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.SumAt, WhereEnumerable.Enumerator, float?, float, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static double Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, double, double, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static double Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.SumAt, WhereEnumerable.Enumerator, double?, double, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static decimal Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.SumAt, WhereEnumerable.Enumerator, decimal, decimal, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static decimal Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.SumAt, WhereEnumerable.Enumerator, decimal?, decimal, TPredicate>(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index d467a8803..ebbb57525 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -232,75 +232,75 @@ public Dictionary ToDictionary(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, int, int, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static int Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, int?, int, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static long Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, long, long, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static long Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, long?, long, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static float Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, float, float, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static float Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, float?, float, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static double Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, double, double, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static double Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, double?, double, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static decimal Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, decimal, decimal, TPredicate>(source.predicate); - - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static decimal Sum(this WhereEnumerable source) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // where TPredicate : struct, IFunction - // => source.Sum, WhereEnumerable.Enumerator, decimal?, decimal, TPredicate>(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index 42620d2a1..413676c12 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentWhereSelectEnumerable WhereSelect( + static ArraySegmentWhereSelectEnumerable WhereSelect( this in ArraySegment source, TPredicate predicate, TSelector selector) diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index 8a33d3053..41af52210 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -31,9 +31,9 @@ public readonly partial struct WhereSelectEnumerable where TSelector : struct, IAsyncFunction { - readonly TEnumerable source; - readonly TPredicate predicate; - readonly TSelector selector; + internal readonly TEnumerable source; + internal readonly TPredicate predicate; + internal readonly TSelector selector; internal WhereSelectEnumerable(in TEnumerable source, TPredicate predicate, TSelector selector) => (this.source, this.predicate, this.selector) = (source, predicate, selector); @@ -366,6 +366,86 @@ public ValueTask> ToDictionaryAsync SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.predicate, source.selector, cancellationToken); } } diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs index 37b76c326..974d81b95 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs @@ -40,11 +40,11 @@ public readonly partial struct WhereSelectEnumerable where TSelector : struct, IFunction { - readonly TList source; - readonly TPredicate predicate; - readonly TSelector selector; - readonly int offset; - readonly int count; + internal readonly TList source; + internal readonly TPredicate predicate; + internal readonly TSelector selector; + internal readonly int offset; + internal readonly int count; internal WhereSelectEnumerable(TList source, TPredicate predicate, TSelector selector, int offset, int count) => (this.source, this.offset, this.count, this.predicate, this.selector) = (source, offset, count, predicate, selector); @@ -321,6 +321,76 @@ public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer } } } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereSelectEnumerable source) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector, source.offset, source.count); } } diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index cf5ed1118..5cf9f2afc 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -31,9 +31,9 @@ public readonly partial struct WhereSelectEnumerable where TSelector : struct, IFunction { - readonly TEnumerable source; - readonly TPredicate predicate; - readonly TSelector selector; + internal readonly TEnumerable source; + internal readonly TPredicate predicate; + internal readonly TSelector selector; internal WhereSelectEnumerable(in TEnumerable source, TPredicate predicate, TSelector selector) { @@ -253,6 +253,86 @@ public Dictionary ToDictionary(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); } } diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index 4c1c16816..285e0d6b5 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -31,9 +31,9 @@ public readonly partial struct WhereSelectEnumerable where TSelector : struct, IFunction { - readonly TEnumerable source; - readonly TPredicate predicate; - readonly TSelector selector; + internal readonly TEnumerable source; + internal readonly TPredicate predicate; + internal readonly TSelector selector; internal WhereSelectEnumerable(in TEnumerable source, TPredicate predicate, TSelector selector) { @@ -253,6 +253,86 @@ public Dictionary ToDictionary(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); } } diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs index ebe85f679..9eae8a6c6 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs @@ -11,17 +11,12 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerable { - public static EmptyEnumerable Empty() => - EmptyEnumerable.Instance; + public static EmptyEnumerable Empty() + => new(); - public partial class EmptyEnumerable + public readonly partial struct EmptyEnumerable : IAsyncValueEnumerable.DisposableEnumerator> { - // ReSharper disable once HeapView.ObjectAllocation.Evident - public static EmptyEnumerable Instance { get; } = new(); - - EmptyEnumerable() { } - [MethodImpl(MethodImplOptions.AggressiveInlining)] #pragma warning disable IDE0060 // Remove unused parameter public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs index 03681446b..54d00f210 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs @@ -12,7 +12,7 @@ public static partial class ValueEnumerable public static EmptyEnumerable Empty() => new(); - public partial struct EmptyEnumerable + public readonly partial struct EmptyEnumerable : IValueReadOnlyList.DisposableEnumerator> , IList { diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.Memory.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.Memory.cs deleted file mode 100644 index 146ba14d7..000000000 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.Memory.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static Memory Skip(this Memory source, int count) - { - var (skipCount, takeCount) = Utils.Skip(source.Length, count); - return source.Slice(skipCount, takeCount); - } - } -} diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyMemory.cs deleted file mode 100644 index 1cd534108..000000000 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyMemory.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ReadOnlyMemory Skip(this ReadOnlyMemory source, int count) - { - var (skipCount, takeCount) = Utils.Skip(source.Length, count); - return source.Slice(skipCount, takeCount); - } - } -} diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlySpan.cs deleted file mode 100644 index 1666133d1..000000000 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlySpan.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan Skip(this ReadOnlySpan source, int count) - { - var (skipCount, takeCount) = Utils.Skip(source.Length, count); - return source.Slice(skipCount, takeCount); - } - } -} diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.Span.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.Span.cs deleted file mode 100644 index b96eebf91..000000000 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.Span.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Span Skip(this Span source, int count) - { - var (skipCount, takeCount) = Utils.Skip(source.Length, count); - return source.Slice(skipCount, takeCount); - } - } -} diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs index cf375d7a4..40e719363 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs @@ -211,8 +211,9 @@ public bool Contains(TSource value, IEqualityComparer? comparer) if (source.Count is 0) return false; - if (comparer is null || ReferenceEquals(comparer, EqualityComparer.Default)) + if (Utils.UseDefault(comparer)) { + // ReSharper disable once HeapView.PossibleBoxingAllocation if (skipCount is 0 && Count == source.Count && source is ICollection collection) return collection.Contains(value); @@ -220,7 +221,6 @@ public bool Contains(TSource value, IEqualityComparer? comparer) return DefaultContains(source, value, skipCount, Count); } - comparer ??= EqualityComparer.Default; return ComparerContains(source, value, comparer, skipCount, Count); static bool DefaultContains(TEnumerable source, TSource value, int skipCount, int takeCount) @@ -246,8 +246,9 @@ static bool DefaultContains(TEnumerable source, TSource value, int skipCount, in return false; } - static bool ComparerContains(TEnumerable source, TSource value, IEqualityComparer comparer, int skipCount, int takeCount) + static bool ComparerContains(TEnumerable source, TSource value, IEqualityComparer? comparer, int skipCount, int takeCount) { + comparer ??= EqualityComparer.Default; using var enumerator = source.GetEnumerator(); // skip diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyMemory.cs deleted file mode 100644 index d4249db87..000000000 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyMemory.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ReadOnlyMemory Take(this ReadOnlyMemory source, int count) - => source.Slice(0, Utils.Take(source.Length, count)); - } -} diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlySpan.cs deleted file mode 100644 index 75abffd9d..000000000 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlySpan.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan Take(this ReadOnlySpan source, int count) - => source.Slice(0, Utils.Take(source.Length, count)); - } -} diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.Span.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.Span.cs deleted file mode 100644 index 205ff8ba3..000000000 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.Span.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Span Take(this Span source, int count) - => source.Slice(0, Utils.Take(source.Length, count)); - } -} diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index b5cecb90d..25614e0bd 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -12,11 +12,11 @@ public static partial class ArrayExtensions { [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectEnumerable> Select(this in ArraySegment source, Func selector) + static ArraySegmentSelectEnumerable> Select(this in ArraySegment source, Func selector) => source.Select>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectEnumerable Select(this in ArraySegment source, TSelector selector = default) + static ArraySegmentSelectEnumerable Select(this in ArraySegment source, TSelector selector = default) where TSelector : struct, IFunction => new(in source, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs index cc90a496f..48e010b89 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -34,8 +34,8 @@ public readonly partial struct SelectEnumerable where TSelector : struct, IAsyncFunction { - readonly TEnumerable source; - readonly TSelector selector; + internal readonly TEnumerable source; + internal readonly TSelector selector; internal SelectEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); @@ -263,6 +263,76 @@ public ValueTask> ToListAsync(CancellationToken cancellationToken #endregion } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(source.selector, cancellationToken); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs index b60cee6a1..17549b070 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs @@ -43,9 +43,9 @@ public partial struct SelectEnumerable where TList : struct, IReadOnlyList where TSelector : struct, IFunction { - readonly int offset; - readonly TList source; - TSelector selector; + internal int offset; + internal TList source; + internal TSelector selector; internal SelectEnumerable(in TList source, TSelector selector, int offset, int count) => (this.source, this.offset, Count, this.selector) = (source, offset, count, selector); @@ -306,13 +306,72 @@ public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer } } } - - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this in SelectEnumerable source) where TList : struct, IReadOnlyList where TSelector : struct, IFunction => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.Sum(source.selector, source.offset, source.Count); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index ebbaa8259..2585360f7 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -13,11 +13,11 @@ public static partial class ArrayExtensions [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemorySelectEnumerable> Select(this ReadOnlyMemory source, Func selector) + static MemorySelectEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.Select>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemorySelectEnumerable Select(this ReadOnlyMemory source, TSelector selector = default) + static MemorySelectEnumerable Select(this ReadOnlyMemory source, TSelector selector = default) where TSelector : struct, IFunction => new(source, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index 04e3c0dff..761782838 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -12,11 +12,11 @@ public static partial class ArrayExtensions [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectEnumerable> Select(this ReadOnlySpan source, Func selector) + static SpanSelectEnumerable> Select(this ReadOnlySpan source, Func selector) => source.Select>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectEnumerable Select(this ReadOnlySpan source, TSelector selector = default) + static SpanSelectEnumerable Select(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction => new(source, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.Span.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.Span.cs deleted file mode 100644 index cf1dac97b..000000000 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.Span.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectEnumerable> Select(this Span source, Func selector) - => ((ReadOnlySpan)source).Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectEnumerable Select(this Span source, TSelector selector = default) - where TSelector : struct, IFunction - => ((ReadOnlySpan)source).Select(selector); - } -} - diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index c11aae42a..0368774ab 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -33,8 +33,8 @@ public readonly partial struct SelectEnumerable where TSelector : struct, IFunction { - readonly TEnumerable source; - readonly TSelector selector; + internal readonly TEnumerable source; + internal readonly TSelector selector; internal SelectEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); @@ -166,6 +166,76 @@ public List ToList() #endregion } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index 25ae799af..d2812915e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -34,8 +34,8 @@ public partial struct SelectEnumerable where TSelector : struct, IFunction { - readonly TEnumerable source; - TSelector selector; + internal readonly TEnumerable source; + internal TSelector selector; internal SelectEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); @@ -211,6 +211,76 @@ public static int Count(t where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 5abda5ee6..1cc4541f3 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -12,11 +12,11 @@ public static partial class ArrayExtensions { [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectAtEnumerable> Select(this in ArraySegment source, Func selector) + static ArraySegmentSelectAtEnumerable> Select(this in ArraySegment source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectAtEnumerable SelectAt(this in ArraySegment source, TSelector selector = default) + static ArraySegmentSelectAtEnumerable SelectAt(this in ArraySegment source, TSelector selector = default) where TSelector : struct, IFunction => new(in source, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index cfb04e7d7..a76137f3a 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -34,8 +34,8 @@ public readonly partial struct SelectAtEnumerable where TSelector : struct, IAsyncFunction { - readonly TEnumerable source; - readonly TSelector selector; + internal readonly TEnumerable source; + internal readonly TSelector selector; internal SelectAtEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); @@ -265,6 +265,76 @@ public ValueTask> ToListAsync(CancellationToken cancellationToken #endregion } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(source.selector, cancellationToken); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs index f13f5aa58..03338580c 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs @@ -43,9 +43,9 @@ public partial struct SelectAtEnumerable where TList : struct, IReadOnlyList where TSelector : struct, IFunction { - readonly int offset; - readonly TList source; - TSelector selector; + internal readonly int offset; + internal readonly TList source; + internal TSelector selector; internal SelectAtEnumerable(in TList source, TSelector selector, int offset, int count) => (this.source, this.offset, Count, this.selector) = (source, offset, count, selector); @@ -332,6 +332,66 @@ public static int Count(this in SelectAtEnum where TList : struct, IReadOnlyList where TSelector : struct, IFunction => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectAtEnumerable source) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source.source.SumAt(source.selector, source.offset, source.Count); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 7a9d86722..dd0f512eb 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -13,11 +13,11 @@ public static partial class ArrayExtensions [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemorySelectAtEnumerable> Select(this ReadOnlyMemory source, Func selector) + static MemorySelectAtEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemorySelectAtEnumerable SelectAt(this ReadOnlyMemory source, TSelector selector = default) + static MemorySelectAtEnumerable SelectAt(this ReadOnlyMemory source, TSelector selector = default) where TSelector : struct, IFunction => new(source, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index 8da5a17f3..078721d31 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -12,11 +12,11 @@ public static partial class ArrayExtensions [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectAtEnumerable> Select(this ReadOnlySpan source, Func selector) + static SpanSelectAtEnumerable> Select(this ReadOnlySpan source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectAtEnumerable SelectAt(this ReadOnlySpan source, TSelector selector = default) + static SpanSelectAtEnumerable SelectAt(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction => new(source, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.Span.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.Span.cs deleted file mode 100644 index d4b073363..000000000 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.Span.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectAtEnumerable> Select(this Span source, Func selector) - => source.SelectAt>(new FunctionWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectAtEnumerable SelectAt(this Span source, TSelector selector = default) - where TSelector : struct, IFunction - => ((ReadOnlySpan)source).SelectAt(selector); - } -} - diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index f2ad9684f..7cd76ec37 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -33,8 +33,8 @@ public readonly partial struct SelectAtEnumerable where TSelector : struct, IFunction { - readonly TEnumerable source; - readonly TSelector selector; + internal readonly TEnumerable source; + internal readonly TSelector selector; internal SelectAtEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); @@ -176,6 +176,76 @@ public List ToList() #endregion } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index 33b2e1c63..b182a7a51 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -34,8 +34,8 @@ public partial struct SelectAtEnumerable where TSelector : struct, IFunction { - readonly TEnumerable source; - TSelector selector; + internal readonly TEnumerable source; + internal TSelector selector; internal SelectAtEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); @@ -220,6 +220,76 @@ public static int Count(t where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ArraySegment.cs deleted file mode 100644 index 901da4d52..000000000 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ArraySegment.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static MemorySelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ArraySegment source, Func, Vector> vectorSelector, Func selector) - where TSource : struct - where TResult : struct - => source.AsMemory().SelectVector(vectorSelector, selector); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static MemorySelectVectorContext SelectVector(this ArraySegment source, TSelector selector = default) - where TSelector : struct, IFunction, Vector>, IFunction - where TSource : struct - where TResult : struct - => source.AsMemory().SelectVector(selector); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static MemorySelectVectorContext SelectVector(this ArraySegment source, TVectorSelector vectorSelector = default, TSelector selector = default) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - where TResult : struct - => source.AsMemory().SelectVector(vectorSelector, selector); - } -} - diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Memory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Memory.cs deleted file mode 100644 index afb428bd7..000000000 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Memory.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Numerics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static MemorySelectVectorContext, Vector>, FunctionWrapper> SelectVector(this Memory source, Func, Vector> vectorSelector, Func selector) - where TSource : struct - where TResult : struct - => ((ReadOnlyMemory)source).SelectVector(vectorSelector, selector); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static MemorySelectVectorContext SelectVector(this Memory source, TSelector selector = default) - where TSelector : struct, IFunction, Vector>, IFunction - where TSource : struct - where TResult : struct - => ((ReadOnlyMemory)source).SelectVector(selector); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static MemorySelectVectorContext SelectVector(this Memory source, TVectorSelector vectorSelector = default, TSelector selector = default) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - where TResult : struct - => ((ReadOnlyMemory)source).SelectVector(vectorSelector, selector); - - } -} - diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlyMemory.cs deleted file mode 100644 index 704276e88..000000000 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlyMemory.cs +++ /dev/null @@ -1,135 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static MemorySelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ReadOnlyMemory source, Func, Vector> vectorSelector, Func selector) - where TSource : struct - where TResult : struct - => source.SelectVector, Vector>, FunctionWrapper>(new FunctionWrapper, Vector>(vectorSelector), new FunctionWrapper(selector)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static MemorySelectVectorContext SelectVector(this ReadOnlyMemory source, TSelector selector = default) - where TSelector : struct, IFunction, Vector>, IFunction - where TSource : struct - where TResult : struct - => source.SelectVector(selector, selector); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static MemorySelectVectorContext SelectVector(this ReadOnlyMemory source, TVectorSelector vectorSelector = default, TSelector selector = default) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - where TResult : struct - => new(source, vectorSelector, selector); - - [StructLayout(LayoutKind.Auto)] - public struct MemorySelectVectorContext - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - where TResult : struct - { - internal readonly ReadOnlyMemory source; - internal TVectorSelector vectorSelector; - internal TSelector selector; - - internal MemorySelectVectorContext(ReadOnlyMemory source, TVectorSelector vectorSelector, TSelector selector) - { - if (Vector.Count != Vector.Count) - Throw.NotSupportedException(); - - this.source = source; - this.vectorSelector = vectorSelector; - this.selector = selector; - } - - #region Aggregation - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count() - => source.Length; - - #endregion - - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.Length is not 0; - - #endregion - #region Filtering - - #endregion - #region Projection - - #endregion - #region Element - - #endregion - #region Conversion - - public TResult[] ToArray() - => source.Span.ToArrayVector(vectorSelector, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.Span.ToArrayVector(vectorSelector, selector, pool); - - public List ToList() - => source.Span.ToListVector(vectorSelector, selector); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this MemorySelectVectorContext source) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - => source.source.Span.Sum(source.vectorSelector, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this MemorySelectVectorContext source) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - => source.source.Span.Sum(source.vectorSelector, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this MemorySelectVectorContext source) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - => source.source.Span.Sum(source.vectorSelector, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this MemorySelectVectorContext source) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - => source.source.Span.Sum(source.vectorSelector, source.selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this MemorySelectVectorContext source) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - => source.source.Span.Sum(source.vectorSelector, source.selector); - - } -} - diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs index 0bdbc419a..11a84a12b 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs @@ -12,14 +12,14 @@ public static partial class ArrayExtensions [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ReadOnlySpan source, Func, Vector> vectorSelector, Func selector) + static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ReadOnlySpan source, Func, Vector> vectorSelector, Func selector) where TSource : struct where TResult : struct => source.SelectVector, Vector>, FunctionWrapper>(new FunctionWrapper, Vector>(vectorSelector), new FunctionWrapper(selector)); [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectVectorContext SelectVector(this ReadOnlySpan source, TSelector selector = default) + static SpanSelectVectorContext SelectVector(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction, Vector>, IFunction where TSource : struct where TResult : struct @@ -27,7 +27,7 @@ public static SpanSelectVectorContext Se [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectVectorContext SelectVector(this ReadOnlySpan source, TVectorSelector vectorSelector = default, TSelector selector = default) + static SpanSelectVectorContext SelectVector(this ReadOnlySpan source, TVectorSelector vectorSelector = default, TSelector selector = default) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Span.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Span.cs deleted file mode 100644 index ad91df53f..000000000 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Span.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Numerics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this Span source, Func, Vector> vectorSelector, Func selector) - where TSource : struct - where TResult : struct - => ((ReadOnlySpan)source).SelectVector(vectorSelector, selector); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectVectorContext SelectVector(this Span source, TSelector selector = default) - where TSelector : struct, IFunction, Vector>, IFunction - where TSource : struct - where TResult : struct - => ((ReadOnlySpan)source).SelectVector(selector); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectVectorContext SelectVector(this Span source, TVectorSelector vectorSelector = default, TSelector selector = default) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - where TResult : struct - => ((ReadOnlySpan)source).SelectVector(vectorSelector, selector); - - } -} - diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs index b4e1d4f38..278ce9ae6 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs @@ -11,13 +11,13 @@ public static partial class ArrayExtensions { [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectManyEnumerable> SelectMany(this in ArraySegment source, Func selector) + static ArraySegmentSelectManyEnumerable> SelectMany(this in ArraySegment source, Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => source.SelectMany>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentSelectManyEnumerable SelectMany(this in ArraySegment source, TSelector selector = default) + static ArraySegmentSelectManyEnumerable SelectMany(this in ArraySegment source, TSelector selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -226,6 +226,76 @@ public readonly ValueEnumerableExtensions.TakeEnumerable(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs index e072cddd1..d3f4ea7fb 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs @@ -12,7 +12,7 @@ public static partial class ReadOnlyListExtensions [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectManyEnumerable> SelectMany(this TList source, Func selector) + internal static SelectManyEnumerable> SelectMany(this TList source, Func selector) where TList : struct, IReadOnlyList where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator @@ -27,7 +27,7 @@ static SelectManyEnumerable source.SelectMany>(new FunctionWrapper(selector), offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectManyEnumerable SelectMany(this TList source, TSelector selector) + internal static SelectManyEnumerable SelectMany(this TList source, TSelector selector) where TList : struct, IReadOnlyList where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator @@ -245,6 +245,86 @@ public readonly ValueEnumerableExtensions.TakeEnumerable(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectManyEnumerable source) + where TList : struct, IReadOnlyList + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs index 0009dc360..0dee33578 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs @@ -12,13 +12,13 @@ public static partial class ArrayExtensions [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemorySelectManyEnumerable> SelectMany(this in ReadOnlyMemory source, Func selector) + static MemorySelectManyEnumerable> SelectMany(this in ReadOnlyMemory source, Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => source.SelectMany>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemorySelectManyEnumerable SelectMany(this in ReadOnlyMemory source, TSelector selector = default) + static MemorySelectManyEnumerable SelectMany(this in ReadOnlyMemory source, TSelector selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -224,6 +224,76 @@ public readonly ValueEnumerableExtensions.TakeEnumerable(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs index e6559fa4f..e5b7a6078 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs @@ -12,13 +12,13 @@ public static partial class ArrayExtensions [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SpanSelectManyEnumerable> SelectMany(this ReadOnlySpan source, Func selector) + static SpanSelectManyEnumerable> SelectMany(this ReadOnlySpan source, Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => source.SelectMany>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SpanSelectManyEnumerable SelectMany(this ReadOnlySpan source, TSelector selector = default) + static SpanSelectManyEnumerable SelectMany(this ReadOnlySpan source, TSelector selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -215,6 +215,77 @@ public readonly ValueEnumerableExtensions.TakeEnumerable(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SpanSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SpanSelectManyEnumerable.Enumerator, decimal?, decimal>(); +*/ } } diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs index d50200522..173ee4011 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs @@ -225,6 +225,96 @@ public Option Single() #endregion } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlyList.cs index 60f7c4fc5..a564e8749 100644 --- a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlyList.cs @@ -7,22 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.All(predicate, 0, source.Count); - [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool All(this TList source, Func predicate, int offset, int count) where TList : struct, IReadOnlyList => source.All>(new FunctionWrapper(predicate), offset, count); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this TList source, TPredicate predicate) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.All(predicate, 0, source.Count); - static bool All(this TList source, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction @@ -36,24 +25,12 @@ static bool All(this TList source, TPredicate predic } return true; } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.All(predicate, 0, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool All(this TList source, Func predicate, int offset, int count) where TList : struct, IReadOnlyList => source.AllAt>(new FunctionWrapper(predicate), offset, count); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AllAt(this TList source, TPredicate predicate) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.AllAt(predicate, 0, source.Count); - static bool AllAt(this TList source, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs index 251e67edd..e7093ea5f 100644 --- a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs @@ -6,10 +6,10 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this ReadOnlySpan source, Func predicate) + static bool All(this ReadOnlySpan source, Func predicate) => source.All(new FunctionWrapper(predicate)); - public static bool All(this ReadOnlySpan source, TPredicate predicate = default) + static bool All(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { foreach (var item in source) @@ -21,10 +21,10 @@ public static bool All(this ReadOnlySpan source, T } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this ReadOnlySpan source, Func predicate) + static bool All(this ReadOnlySpan source, Func predicate) => source.AllAt(new FunctionWrapper(predicate)); - public static bool AllAt(this ReadOnlySpan source, TPredicate predicate = default) + static bool AllAt(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { for (var index = 0; index < source.Length; index++) diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.Span.cs b/NetFabric.Hyperlinq/Quantifier/All/All.Span.cs deleted file mode 100644 index fd7633936..000000000 --- a/NetFabric.Hyperlinq/Quantifier/All/All.Span.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this Span source, Func predicate) - => source.All(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source).All(predicate); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this Span source, Func predicate) - => source.AllAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AllAt(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source).AllAt(predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs index 20cbf1744..459d7f828 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs @@ -9,7 +9,7 @@ public static partial class EnumerableExtensions internal static bool Contains(this TEnumerable source, TSource value, IEqualityComparer? comparer = default) where TEnumerable : IEnumerable { - if (comparer is null || ReferenceEquals(comparer, EqualityComparer.Default)) + if (Utils.UseDefault(comparer)) { // ReSharper disable once HeapView.PossibleBoxingAllocation if (source is ICollection collection) @@ -50,17 +50,16 @@ internal static bool Contains where TEnumeratorGenerator : struct, IFunction { - // TODO: - //if (comparer is null || ReferenceEquals(comparer, EqualityComparer.Default)) - //{ - // if (source is ICollection collection) - // return collection.Contains(value); + if (Utils.UseDefault(comparer)) + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + return collection.Contains(value); - // if (Utils.IsValueType()) - // return DefaultContains(source, value, getEnumerator); - //} + if (Utils.IsValueType()) + return DefaultContains(source, value, getEnumerator); + } - comparer ??= EqualityComparer.Default; return ComparerContains(source, value, comparer, getEnumerator); static bool DefaultContains(TEnumerable source, TSource value, TEnumeratorGenerator getEnumerator) @@ -74,8 +73,9 @@ static bool DefaultContains(TEnumerable source, TSource value, TEnumeratorGenera return false; } - static bool ComparerContains(TEnumerable source, TSource value, IEqualityComparer comparer, TEnumeratorGenerator getEnumerator) + static bool ComparerContains(TEnumerable source, TSource value, IEqualityComparer? comparer, TEnumeratorGenerator getEnumerator) { + comparer ??= EqualityComparer.Default; using var enumerator = getEnumerator.Invoke(source); while (enumerator.MoveNext()) { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs index 4eff630ea..514b88474 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs @@ -19,7 +19,7 @@ static bool Contains(this TList source, TSource value, IEquality if (count is 0) return false; - if (comparer is null || ReferenceEquals(comparer, EqualityComparer.Default)) + if (Utils.UseDefault(comparer)) { if (offset is 0 && count == source.Count && source is ICollection collection) return collection.Contains(value); @@ -109,10 +109,9 @@ static bool ContainsAt(this TList source, TR static bool ValueContains(TList source, TResult value, TSelector selector, int offset, int count) { - var end = count; if (offset is 0) { - for (var index = 0; index < end; index++) + for (var index = 0; index < count; index++) { var item = source[index]; if (EqualityComparer.Default.Equals(selector.Invoke(item, index), value)) @@ -121,7 +120,7 @@ static bool ValueContains(TList source, TResult value, TSelector selector, int o } else { - for (var index = 0; index < end; index++) + for (var index = 0; index < count; index++) { var item = source[index + offset]; if (EqualityComparer.Default.Equals(selector.Invoke(item, index), value)) @@ -134,10 +133,9 @@ static bool ValueContains(TList source, TResult value, TSelector selector, int o static bool ReferenceContains(TList source, TResult value, IEqualityComparer? comparer, TSelector selector, int offset, int count) { comparer ??= EqualityComparer.Default; - var end = count; if (offset is 0) { - for (var index = 0; index < end; index++) + for (var index = 0; index < count; index++) { var item = source[index]; if (comparer.Equals(selector.Invoke(item, index), value)) @@ -146,7 +144,7 @@ static bool ReferenceContains(TList source, TResult value, IEqualityComparer(this ReadOnlySpan source, TSource value, IEqualityComparer? comparer = default) + static bool Contains(this ReadOnlySpan source, TSource value, IEqualityComparer? comparer = default) { return source switch { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Span.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Span.cs deleted file mode 100644 index 95679aa69..000000000 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Span.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Contains(this Span source, TSource value, IEqualityComparer? comparer = default) - => ((ReadOnlySpan)source).Contains(value, comparer); - - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs index f5d5347b3..031c0bac2 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -9,8 +9,9 @@ public static bool Contains(this TEnumerable where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { - if (comparer is null || ReferenceEquals(comparer, EqualityComparer.Default)) + if (Utils.UseDefault(comparer)) { + // ReSharper disable once HeapView.PossibleBoxingAllocation if (source is ICollection collection) return collection.Contains(value); @@ -34,7 +35,6 @@ static bool DefaultContains(TEnumerable source, TSource value) static bool ComparerContains(TEnumerable source, TSource value, IEqualityComparer? comparer) { comparer ??= EqualityComparer.Default; - using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs index 26738634b..0a3747cd1 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegmentDistinctEnumerable Distinct(this in ArraySegment source, IEqualityComparer? comparer = default) + static ArraySegmentDistinctEnumerable Distinct(this in ArraySegment source, IEqualityComparer? comparer = default) => new(source, comparer); [StructLayout(LayoutKind.Auto)] @@ -126,6 +126,46 @@ public readonly List ToList() _ => GetSet().ToList() }; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs index 805d6c2a6..018303936 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs @@ -207,6 +207,66 @@ public readonly async ValueTask> ToArrayAsync(MemoryPool> ToListAsync(CancellationToken cancellationToken = default) => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToList(); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyList.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyList.cs index 4ab435ad2..14c4efd39 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyList.cs @@ -12,7 +12,7 @@ public static partial class ReadOnlyListExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static DistinctEnumerable Distinct(this TList source, IEqualityComparer? comparer = default) + static DistinctEnumerable Distinct(this TList source, IEqualityComparer? comparer = default) where TList : struct, IReadOnlyList => source.Distinct(comparer, 0, source.Count); @@ -175,6 +175,56 @@ public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer } } } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this DistinctEnumerable source) + where TList : struct, IReadOnlyList + => source.Sum, DistinctEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs index f24fc1bf9..42fcf5d17 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -12,7 +12,7 @@ public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static MemoryDistinctEnumerable Distinct( + static MemoryDistinctEnumerable Distinct( this ReadOnlyMemory source, IEqualityComparer? comparer = null) => new(source, comparer); @@ -150,6 +150,46 @@ public bool SequenceEqual(IEnumerable other, IEqualityComparer } } } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs index fe64f7c4a..a84144c03 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs @@ -10,7 +10,7 @@ public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanDistinctEnumerable Distinct( + static SpanDistinctEnumerable Distinct( this ReadOnlySpan source, IEqualityComparer? comparer = null) => new(source, comparer); diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.Span.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.Span.cs deleted file mode 100644 index b7228fffe..000000000 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.Span.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanDistinctEnumerable Distinct(this Span source, IEqualityComparer? comparer = null) - => ((ReadOnlySpan)source).Distinct(comparer); - } -} - diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs index 82d4c1bab..2a6c2ec5e 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs @@ -120,6 +120,66 @@ public readonly IMemoryOwner ToArray(MemoryPool pool) public readonly List ToList() => GetSet().ToList(); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index 8f351f569..4fe7a3bf4 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -30,6 +30,8 @@ struct Set : ICollection, IDisposable /// readonly IEqualityComparer comparer; + readonly bool useDefaultComparer; + /// /// The hash buckets, which are used to index into the slots. /// @@ -50,6 +52,7 @@ public Set(IEqualityComparer? comparer = default) { bucketsPool = ArrayPool.Shared; slotsPool = ArrayPool.Shared; + useDefaultComparer = Utils.UseDefault(comparer); this.comparer = comparer ?? EqualityComparer.Default; buckets = default; slots = default; @@ -77,15 +80,14 @@ public bool Add(TElement value) Debug.Assert(buckets is not null); Debug.Assert(slots is not null); - var hashCode = value switch - { - null => 0, - _ => comparer.GetHashCode(value) & 0x7FFFFFFF, - }; - if (Utils.UseDefault(comparer)) + var hashCode = 0; + if (useDefaultComparer) { + if (value is not null) + hashCode = EqualityComparer.Default.GetHashCode(value) & 0x7FFFFFFF; + var index = buckets[hashCode % buckets.Length] - 1; - while (index >= 0) + while (index >= 0 && index < slots.Length) { ref readonly var current = ref slots[index]; if (current.HashCode == hashCode && EqualityComparer.Default.Equals(current.Value, value)) @@ -96,8 +98,11 @@ public bool Add(TElement value) } else { + if (value is not null) + hashCode = comparer.GetHashCode(value) & 0x7FFFFFFF; + var index = buckets[hashCode % buckets.Length] - 1; - while (index >= 0) + while (index >= 0 && index < slots.Length) { ref readonly var current = ref slots[index]; if (current.HashCode == hashCode && comparer.Equals(current.Value, value)) @@ -138,7 +143,7 @@ void Resize() Array.Clear(newSlots, Count, newSlots.Length - Count); Array.Clear(newBuckets, 0, newBuckets.Length); - for (var index = 0; index < Count; index++) + for (var index = 0; index < Count && index < newSlots.Length; index++) { var bucket = newSlots[index].HashCode % newSize; newSlots[index].Next = newBuckets[bucket] - 1; @@ -180,6 +185,7 @@ public readonly IMemoryOwner ToArray(MemoryPool pool) public readonly List ToList() => Count switch { + // ReSharper disable once HeapView.ObjectAllocation.Evident 0 => new List(), _ => ToArray().AsList() }; diff --git a/NetFabric.Hyperlinq/Utils/GenericsOperator.cs b/NetFabric.Hyperlinq/Utils/GenericsOperator.cs index 345187874..98af3d29e 100644 --- a/NetFabric.Hyperlinq/Utils/GenericsOperator.cs +++ b/NetFabric.Hyperlinq/Utils/GenericsOperator.cs @@ -46,6 +46,8 @@ public static TValue Add(TValue a, TValue b) public static TValue AddNullable(TNullableValue a, TValue b) where TValue : struct { +#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. + if (typeof(TNullableValue) == typeof(int?) && typeof(TValue) == typeof(int)) return (TValue)(object)(((int?)(object)a).GetValueOrDefault() + (int)(object)b); @@ -75,6 +77,8 @@ public static TValue AddNullable(TNullableValue a, TValu if (typeof(TNullableValue) == typeof(decimal) && typeof(TValue) == typeof(decimal)) return (TValue)(object)((decimal)(object)a! + (decimal)(object)b); + +#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. return Throw.NotSupportedException(); } diff --git a/NetFabric.Hyperlinq/Utils/ListExtensions.cs b/NetFabric.Hyperlinq/Utils/ListExtensions.cs index d0ff148fe..2ca2708f1 100644 --- a/NetFabric.Hyperlinq/Utils/ListExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/ListExtensions.cs @@ -13,7 +13,7 @@ public static ArraySegment AsArraySegment(this List s [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Span AsSpan(this List source) -#if NET5_0 +#if NET5_0_OR_GREATER => CollectionsMarshal.AsSpan(source); #else => source.GetItems().AsSpan().Slice(0, source.Count); @@ -28,29 +28,32 @@ public static List AsList(this TSource[] source) { var result = new List(); var layout = Unsafe.As, ListLayout>(ref result); - layout.Items = source; - layout.Size = source.Length; + layout.items = source; + layout.size = source.Length; result.Capacity = source.Length; return result; } // ReSharper disable once ClassNeverInstantiated.Local -#if NET5_0 +#if NET5_0_OR_GREATER [SkipLocalsInit] #endif class ListLayout { - public TSource[]? Items; -#if !(NETCOREAPP3_0 || NETCOREAPP3_1 || NET5_0) + public TSource[]? items; + +#if !NETCOREAPP3_0_OR_GREATER #pragma warning disable IDE0051 // Remove unused private members +#pragma warning disable 169 readonly object? syncRoot; +#pragma warning restore 169 #pragma warning restore IDE0051 // Remove unused private members #endif - public int Size; + public int size; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static TSource[] GetItems(this List source) - => Unsafe.As, ListLayout>(ref source).Items!; + => Unsafe.As, ListLayout>(ref source).items!; } } diff --git a/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs b/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs index 596d11ce3..a5d244d30 100644 --- a/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs +++ b/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs @@ -7,7 +7,7 @@ static partial class Utils { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] AllocateUninitializedArray(int count) -#if NET5_0 +#if NET5_0_OR_GREATER => GC.AllocateUninitializedArray(count); #else => new T[count]; From cf6519ad25e2b523299dc80cedf368a801b1c2e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Wed, 3 Mar 2021 23:49:20 +0000 Subject: [PATCH 08/61] Code cleanup (#340) --- .../NetFabric.Hyperlinq.Abstractions.csproj | 2 +- .../TestData/Source/Any.ReadOnlyList.cs | 6 +- ...ncValueEnumerable.AsyncEnumerable.Tests.cs | 32 +- ...ncValueEnumerable.ValueEnumerable.Tests.cs | 18 +- .../AsValueEnumerable'1.Enumerable.Tests.cs | 51 +++ ...ueEnumerable'1.ReadOnlyCollection.Tests.cs | 51 +++ .../AsValueEnumerable'6.Enumerable.cs | 77 +++++ .../AsValueEnumerable'6.ReadOnlyCollection.cs | 80 +++++ .../AsValueEnumerable.Enumerable.Tests.cs | 144 -------- ...alueEnumerable.ReadOnlyCollection.Tests.cs | 242 -------------- .../AsValueEnumerable.ReadOnlyList.Tests.cs | 94 ++---- ...AsValueEnumerable.ValueEnumerable.Tests.cs | 13 +- .../Immutable/ImmutableArray.Tests.cs | 3 +- .../ElementAt/ElementAt.ReadOnlyList.Tests.cs | 24 +- .../ElementAt.ValueEnumerable.Tests.cs | 96 +++--- ...ElementAt.ValueReadOnlyCollection.Tests.cs | 12 +- ...ementAtAsync.AsyncValueEnumerable.Tests.cs | 96 +++--- .../Element/First/First.ReadOnlyList.Tests.cs | 28 +- .../Element/First/First.ReadOnlySpan.Tests.cs | 26 +- .../First/First.ValueEnumerable.Tests.cs | 72 ++-- .../First.ValueReadOnlyCollection.Tests.cs | 12 +- .../FirstAsync.AsyncValueEnumerable.Tests.cs | 72 ++-- .../Single/Single.ReadOnlyList.Tests.cs | 28 +- .../Single/Single.ValueEnumerable.Tests.cs | 96 +++--- .../Single.ValueReadOnlyCollection.Tests.cs | 12 +- .../SingleAsync.AsyncValueEnumerable.Tests.cs | 96 +++--- .../Where/Where.ArraySegment.Tests.cs | 2 +- .../AsyncValueEnumerable/Range.Tests.cs | 18 +- .../AsyncValueEnumerable/Repeat.Tests.cs | 12 +- .../Generation/ValueEnumerable/Range.Tests.cs | 20 +- .../ValueEnumerable/Repeat.Tests.cs | 51 ++- .../Select/Select.ArraySegment.Tests.cs | 6 +- .../Utils/Wrappers/Wrap.AsAsyncEnumerable.cs | 8 +- .../Aggregation/Count/Count.ReadOnlyList.cs | 6 +- .../Count/Count.ValueEnumerable.cs | 3 +- .../Count/CountAsync.AsyncValueEnumerable.cs | 1 - .../Aggregation/Sum/Sum.Range.cs | 1 - .../Aggregation/Sum/Sum.ReadOnlyList.cs | 16 +- .../Aggregation/Sum/Sum.ReadOnlySpan.cs | 1 - .../Aggregation/Sum/Sum.ValueEnumerable.cs | 2 - .../AsAsyncValueEnumerable.AsyncEnumerable.cs | 3 +- ...yncValueEnumerable.AsyncValueEnumerable.cs | 3 +- .../AsAsyncValueEnumerable.ValueEnumerable.cs | 8 +- .../AsValueEnumerable'1.Enumerable.cs | 10 +- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 8 +- .../AsValueEnumerable'6.Enumerable.cs | 7 +- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 8 +- .../AsValueEnumerable.ArraySegment.cs | 2 +- .../AsValueEnumerable.ReadOnlyList.cs | 314 +++++------------- .../AsValueEnumerable.ReadOnlyMemory.cs | 6 +- .../AsValueEnumerable.ReadOnlySpan.cs | 4 +- .../Collections/Immutable/ImmutableArray.cs | 30 +- .../Immutable/ImmutableDictionary.cs | 2 +- .../Collections/Immutable/ImmutableHashSet.cs | 2 +- .../Collections/Immutable/ImmutableList.cs | 2 +- .../Collections/Immutable/ImmutableQueue.cs | 2 +- .../Immutable/ImmutableSortedDictionary.cs | 2 +- .../Collections/Immutable/ImmutableStack.cs | 2 +- .../ToArray/ToArray.ReadOnlySpan.cs | 3 +- .../ToArray/ToArray.ValueEnumerable.cs | 5 +- .../ToArray.ValueReadOnlyCollection.cs | 1 - .../ToArrayAsync.AsyncValueEnumerable.cs | 3 +- .../ToDictionary/ToDictionary.ReadOnlyList.cs | 2 +- .../Conversion/ToList/ToList.ReadOnlyList.cs | 2 - .../Conversion/ToList/ToList.ReadOnlySpan.cs | 1 - .../ToList/ToList.ValueEnumerable.cs | 5 +- .../ToList/ToList.ValueReadOnlyCollection.cs | 2 +- .../ToListAsync.AsyncValueEnumerable.cs | 3 +- .../ElementAt/ElementAt.ReadOnlyList.cs | 2 - .../ElementAt/ElementAt.ReadOnlySpan.cs | 1 - .../ElementAt/ElementAt.ValueEnumerable.cs | 1 - .../Element/First/First.ReadOnlyList.cs | 1 - .../Element/First/First.ValueEnumerable.cs | 2 - .../Element/Single/Single.ReadOnlyList.cs | 2 - .../Element/Single/Single.ReadOnlySpan.cs | 2 - .../Element/Single/Single.ValueEnumerable.cs | 1 - .../SequenceEqual.ReadOnlySpan.cs | 2 - .../Where/Where/Where.ArraySegment.cs | 2 +- .../Where/Where/Where.AsyncValueEnumerable.cs | 2 +- .../Where/Where/Where.ReadOnlyList.cs | 6 +- .../Where/Where/Where.ReadOnlyMemory.cs | 4 +- .../Where/Where/Where.ReadOnlySpan.cs | 6 +- .../Where/Where/Where.ValueEnumerable.cs | 4 +- .../Where/Where.ValueReadOnlyCollection.cs | 4 +- .../Where/WhereAt/WhereAt.ArraySegment.cs | 8 +- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 2 +- .../Where/WhereAt/WhereAt.ReadOnlyList.cs | 8 +- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 4 +- .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 6 +- .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 4 +- .../WhereAt.ValueReadOnlyCollection.cs | 20 +- .../WhereSelect/WhereSelect.ArraySegment.cs | 40 +-- .../WhereSelect.AsyncValueEnumerable.cs | 26 +- .../WhereSelect/WhereSelect.ReadOnlyList.cs | 30 +- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 40 +-- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 5 +- .../WhereSelect.ValueEnumerable.cs | 2 +- .../WhereSelect.ValueReadOnlyCollection.cs | 2 +- .../Generation/AsyncValueEnumerable/Empty.cs | 3 - .../Generation/AsyncValueEnumerable/Range.cs | 6 +- .../Generation/AsyncValueEnumerable/Return.cs | 3 +- .../ValueEnumerable/CreateValueEnumerable.cs | 2 +- .../Generation/ValueEnumerable/Empty.cs | 2 +- .../Generation/ValueEnumerable/Range.cs | 3 +- .../Generation/ValueEnumerable/Return.cs | 4 +- .../NetFabric.Hyperlinq.csproj | 2 +- NetFabric.Hyperlinq/Option/NoneOption.cs | 2 - NetFabric.Hyperlinq/Option/Option.cs | 2 +- .../Skip/Skip.AsyncValueEnumerable.cs | 2 +- .../Partitioning/Skip/Skip.ValueEnumerable.cs | 5 +- .../Take/Take.AsyncValueEnumerable.cs | 2 +- .../Partitioning/Take/Take.Memory.cs | 13 - .../Select/Select/Select.ArraySegment.cs | 6 +- .../Select/Select/Select.ReadOnlyList.cs | 4 +- .../Select/Select/Select.ReadOnlyMemory.cs | 8 +- .../Select/Select/Select.ReadOnlySpan.cs | 1 - .../Select/Select/Select.ValueEnumerable.cs | 18 +- .../Select/Select.ValueReadOnlyCollection.cs | 8 +- .../Select/SelectAt/SelectAt.ArraySegment.cs | 10 +- .../Select/SelectAt/SelectAt.ReadOnlyList.cs | 2 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 16 +- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 1 - .../SelectAt/SelectAt.ValueEnumerable.cs | 8 +- .../SelectAt.ValueReadOnlyCollection.cs | 10 +- .../Select/SelectVector/SelectVector.Range.cs | 19 +- .../SelectMany/SelectMany.ArraySegment.cs | 3 +- .../SelectMany/SelectMany.ReadOnlyList.cs | 6 +- .../SelectMany/SelectMany.ReadOnlyMemory.cs | 2 +- .../SelectMany/SelectMany.ReadOnlySpan.cs | 1 - .../SelectMany/SelectMany.ValueEnumerable.cs | 68 ++-- .../Contains/Contains.Enumerable.cs | 4 +- .../Contains/Contains.ReadOnlyList.cs | 4 - .../Contains/Contains.ValueEnumerable.cs | 3 +- .../Contains.ValueReadOnlyCollection.cs | 1 - .../ContainsAsync.AsyncValueEnumerable.cs | 3 +- .../Set/Distinct/Distinct.ArraySegment.cs | 2 +- .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 2 +- .../Set/Distinct/Distinct.ValueEnumerable.cs | 1 - NetFabric.Hyperlinq/Set/Distinct/Set.cs | 1 - .../Utils/ArrayBuilder/ArrayBuilder.cs | 9 +- .../Utils/ArrayBuilder/LargeArrayBuilder.cs | 1 - .../ToArrayBuilder.AsyncValueEnumerable.cs | 4 +- .../ToArrayBuilder.ReadOnlyList.cs | 4 +- .../ToArrayBuilder.ReadOnlySpan.cs | 1 - .../ToArrayBuilder.ValueEnumerable.cs | 4 +- ...oArrayBuilderAsync.AsyncValueEnumerable.cs | 3 +- .../Utils/BooleanExtensions.cs | 3 +- NetFabric.Hyperlinq/Utils/GenericsOperator.cs | 3 +- .../Utils/IndexOf/IndexOf.ReadOnlyList.cs | 13 +- NetFabric.Hyperlinq/Utils/Throw.cs | 1 - 150 files changed, 1104 insertions(+), 1516 deletions(-) create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.Enumerable.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyCollection.Tests.cs delete mode 100644 NetFabric.Hyperlinq/Partitioning/Take/Take.Memory.cs diff --git a/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj b/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj index 3238fe924..8d49ed430 100644 --- a/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj +++ b/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj @@ -5,7 +5,7 @@ NetFabric.Hyperlinq.Abstractions NetFabric.Hyperlinq.Abstractions Abstractions for high performance enumeration. - 1.1.0 + 1.2.0 Icon.png LICENSE netfabric, hyperlinq, abstractions, linq, enumeration, performance diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ReadOnlyList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ReadOnlyList.cs index 0c52c3dbf..10383b01b 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ReadOnlyList.cs @@ -9,18 +9,18 @@ public static partial class ReadOnlyListExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool Any(this TList source) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList => source.Count is not 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool Any(this TList source, Func predicate) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList => source.Any>(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool Any(this TList source, TPredicate predicate = default) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList where TPredicate : struct, IFunction => default; } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs index 355ac9a4d..2966bda99 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs @@ -20,8 +20,8 @@ public void AsAsyncValueEnumerable_With_ValidData_Must_Succeed(int[] source) .AsAsyncEnumerable(source); // Act - var result = AsyncEnumerableExtensions - .AsAsyncValueEnumerable(wrapped); + var result = wrapped + .AsAsyncValueEnumerable(); // Assert _ = result.Must() @@ -38,12 +38,12 @@ public async ValueTask AsAsyncValueEnumerable_With_ToArrayAsync_Must_Succeed(int // Arrange var wrapped = Wrap .AsAsyncEnumerable(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act - var result = await AsyncEnumerableExtensions - .AsAsyncValueEnumerable(wrapped) + var result = await wrapped + .AsAsyncValueEnumerable() .ToArrayAsync(); // Assert @@ -61,12 +61,12 @@ public async ValueTask AsAsyncValueEnumerable_With_ToListAsync_Must_Succeed(int[ // Arrange var wrapped = Wrap .AsAsyncEnumerable(source); - var expected = Enumerable - .ToList(source); + var expected = source + .ToList(); // Act - var result = await AsyncEnumerableExtensions - .AsAsyncValueEnumerable(wrapped) + var result = await wrapped + .AsAsyncValueEnumerable() .ToListAsync(); // Assert @@ -87,8 +87,8 @@ public void AsAsyncValueEnumerable_GetEnumerator_With_ValidData_Must_Succeed(int .AsAsyncEnumerable(source); // Act - var result = AsyncEnumerableExtensions - .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>(wrapped, (enumerable, _) => enumerable.GetAsyncEnumerator()); + var result = wrapped + .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>((enumerable, _) => enumerable.GetAsyncEnumerator()); // Assert _ = result.Must() @@ -107,8 +107,8 @@ public async ValueTask AsAsyncValueEnumerable_GetEnumerator_ToListAsync_With_Val .AsAsyncEnumerable(source); // Act - var result = await AsyncEnumerableExtensions - .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>(wrapped, (enumerable, _) => enumerable.GetAsyncEnumerator()) + var result = await wrapped + .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>((enumerable, _) => enumerable.GetAsyncEnumerator()) .ToListAsync(); // Assert @@ -128,8 +128,8 @@ public async ValueTask AsAsyncValueEnumerable_GetEnumerator_ToArrayAsync_With_Va .AsAsyncEnumerable(source); // Act - var result = await AsyncEnumerableExtensions - .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>(wrapped, (enumerable, _) => enumerable.GetAsyncEnumerator()) + var result = await wrapped + .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>((enumerable, _) => enumerable.GetAsyncEnumerator()) .ToArrayAsync(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs index 3d621bc3b..4dff991e8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs @@ -13,7 +13,7 @@ public class ValueEnumerableTests [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable_With_ValidData_Must_Succeed(int[] source) + public void AsAsyncValueEnumerable_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap @@ -38,12 +38,12 @@ public async ValueTask AsAsyncValueEnumerable_With_ToArrayAsync_Must_Succeed(int // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .ToArray(); // Act - var result = await ValueEnumerableExtensions - .AsAsyncValueEnumerable, Wrap.Enumerator, int>(wrapped) + var result = await wrapped + .AsAsyncValueEnumerable, Wrap.Enumerator, int>() .ToArrayAsync(); // Assert @@ -61,12 +61,12 @@ public async ValueTask AsAsyncValueEnumerable_With_ToListAsync_Must_Succeed(int[ // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .ToList(source); + var expected = source + .ToList(); // Act - var result = await ValueEnumerableExtensions - .AsAsyncValueEnumerable, Wrap.Enumerator, int>(wrapped) + var result = await wrapped + .AsAsyncValueEnumerable, Wrap.Enumerator, int>() .ToListAsync(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.Tests.cs new file mode 100644 index 000000000..3a7e9a632 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.Tests.cs @@ -0,0 +1,51 @@ +using System.Linq; +using NetFabric.Assertive; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class EnumerableTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsEnumerable(source); + + // Act + var result = wrapped + .AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs new file mode 100644 index 000000000..fcd2a1558 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs @@ -0,0 +1,51 @@ +using System.Linq; +using NetFabric.Assertive; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ReadOnlyCollectionTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyCollection(source); + + // Act + var result = wrapped + .AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyCollection(source); + var expected = source + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs new file mode 100644 index 000000000..abb36fdea --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -0,0 +1,77 @@ +using System.Linq; +using NetFabric.Assertive; +using System.Collections.Generic; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class EnumerableTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsEnumerable(source); + + // Act + var result = wrapped + .AsValueEnumerable, Wrap.Enumerator, int>( + enumerable => enumerable.GetEnumerator()); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsEnumerable(source); + + // Act + var result = wrapped + .AsValueEnumerable, Wrap.Enumerator, ValueEnumerator, int>( + enumerable => enumerable.GetEnumerator(), + enumerable => new ValueEnumerator(((IEnumerable)enumerable).GetEnumerator())); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable, Wrap.Enumerator, ValueEnumerator, int>( + enumerable => enumerable.GetEnumerator(), + enumerable => new ValueEnumerator(((IEnumerable)enumerable).GetEnumerator())) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs new file mode 100644 index 000000000..a75108d8a --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -0,0 +1,80 @@ +using System.Linq; +using NetFabric.Assertive; +using System.Collections.Generic; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ReadOnlyCollectionTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyCollection(source); + + // Act + var result = ReadOnlyCollectionExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyCollection(source); + + // Act + var result = ReadOnlyCollectionExtensions + .AsValueEnumerable, Wrap.Enumerator, ValueEnumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator(), + enumerable => new ValueEnumerator(((IEnumerable)enumerable).GetEnumerator())); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyCollection(source); + var expected = source + .Sum(); + + // Act + var result = ReadOnlyCollectionExtensions + .AsValueEnumerable, Wrap.Enumerator, ValueEnumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator(), + enumerable => new ValueEnumerator(((IEnumerable)enumerable).GetEnumerator())) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.Enumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.Enumerable.Tests.cs deleted file mode 100644 index 61c366113..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.Enumerable.Tests.cs +++ /dev/null @@ -1,144 +0,0 @@ -using NetFabric.Assertive; -using Xunit; -using System.Collections.Generic; -using System.Linq; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable -{ - public class EnumerableTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsEnumerable(source); - - // Act - var result = EnumerableExtensions - .AsValueEnumerable(wrapped); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(wrapped); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsEnumerable(source); - var expected = Enumerable - .ToArray(source); - - // Act - var result = EnumerableExtensions - .AsValueEnumerable(wrapped) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToList_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsEnumerable(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = EnumerableExtensions - .AsValueEnumerable(wrapped) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_GetEnumerator_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsEnumerable(source); - - // Act - var result = EnumerableExtensions - .AsValueEnumerable, Wrap.Enumerator, int>(wrapped, enumerable => enumerable.GetEnumerator()); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(wrapped); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_GetEnumerator_With_ToArray_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsEnumerable(source); - var expected = Enumerable - .ToArray(source); - - // Act - var result = EnumerableExtensions - .AsValueEnumerable, Wrap.Enumerator, int>(wrapped, enumerable => enumerable.GetEnumerator()) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_GetEnumerator_With_ToList_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsEnumerable(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = EnumerableExtensions - .AsValueEnumerable, Wrap.Enumerator, int>(wrapped, enumerable => enumerable.GetEnumerator()) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyCollection.Tests.cs deleted file mode 100644 index df1bef375..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyCollection.Tests.cs +++ /dev/null @@ -1,242 +0,0 @@ -using NetFabric.Assertive; -using Xunit; -using System.Collections.Generic; -using System.Linq; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable -{ - public class ReadOnlyCollectionTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyCollection(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable(wrapped); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(wrapped); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyCollection(source); - var expected = Enumerable - .ToArray(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable(wrapped) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_Collection_With_ToArray_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsCollection(source); - var expected = Enumerable - .ToArray(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable(wrapped) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToList_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyCollection(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable(wrapped) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_Collection_With_ToList_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsCollection(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable(wrapped) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - ////////// - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_GetEnumerator_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyCollection(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable, Wrap.Enumerator, int>(wrapped, enumerable => enumerable.GetEnumerator()); - - // Assert - _ = result.Must() - .BeOfType, Wrap.Enumerator, Wrap.Enumerator, int, FunctionWrapper, Wrap.Enumerator>, FunctionWrapper, Wrap.Enumerator>>>() - .BeEnumerableOf() - .BeEqualTo(wrapped); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_GetEnumerator_With_ToArray_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyCollection(source); - var expected = Enumerable - .ToArray(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable, Wrap.Enumerator, int>(wrapped, enumerable => enumerable.GetEnumerator()) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_GetEnumerator_Collection_With_ToArray_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsCollection(source); - var expected = Enumerable - .ToArray(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable, Wrap.Enumerator, int>(wrapped, enumerable => enumerable.GetEnumerator()) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_GetEnumerator_With_ToList_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyCollection(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable, Wrap.Enumerator, int>(wrapped, enumerable => enumerable.GetEnumerator()) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_GetEnumerator_Collection_With_ToList_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsCollection(source); - var expected = Enumerable - .ToList(source); - - // Act - var result = ReadOnlyCollectionExtensions - .AsValueEnumerable, Wrap.Enumerator, int>(wrapped, enumerable => enumerable.GetEnumerator()) - .ToList(); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs index 5c4ab230a..b8e119022 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs @@ -1,17 +1,16 @@ -using NetFabric.Assertive; -using Xunit; -using System.Collections.Generic; using System.Linq; +using NetFabric.Assertive; +using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable { - public class ReadOnlyListTests + public partial class ReadOnlyListTests { [Theory] [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) + public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap @@ -23,102 +22,79 @@ public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) // Assert _ = result.Must() - .BeOfType>() .BeEnumerableOf() - .BeEqualTo(wrapped); + .BeEqualTo(source); } - + [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source) + [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Skip_With_ValidData_Must_Succeed(int[] source, int count) { // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .ToArray(source); - - // Act - var result = wrapped - .AsValueEnumerable() - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_Collection_With_ToArray_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsList(source); - var expected = Enumerable - .ToArray(source); + var expected = source + .Skip(count); // Act var result = wrapped .AsValueEnumerable() - .ToArray(); + .Skip(count); // Assert _ = result.Must() - .BeArrayOf() + .BeEnumerableOf() .BeEqualTo(expected); } - + [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToList_Must_Succeed(int[] source) + [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count) { // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .ToList(source); + var expected = source + .Take(count); // Act var result = wrapped .AsValueEnumerable() - .ToList(); + .Take(count); // Assert _ = result.Must() - .BeOfType>() .BeEnumerableOf() .BeEqualTo(expected); } - + [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_Collection_With_ToList_Must_Succeed(int[] source) + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) { // Arrange var wrapped = Wrap - .AsList(source); - var expected = Enumerable - .ToList(source); + .AsReadOnlyList(source); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .Sum(); // Act var result = wrapped .AsValueEnumerable() - .ToList(); + .Skip(skipCount) + .Take(takeCount) + .Sum(); // Assert _ = result.Must() - .BeOfType>() - .BeEnumerableOf() .BeEqualTo(expected); } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs index 4fae4e922..6e04524de 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs @@ -1,4 +1,5 @@ using NetFabric.Assertive; +using System; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable @@ -9,12 +10,12 @@ public class ValueEnumerableTests public void AsValueEnumerable_With_ValueType_Must_ReturnCopy() { // Arrange - var source = new int[0]; + var source = Array.Empty(); var wrapped = Wrap.AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .AsValueEnumerable, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .AsValueEnumerable, Wrap.Enumerator, int>(); // Assert _ = result.Must() @@ -25,13 +26,13 @@ public void AsValueEnumerable_With_ValueType_Must_ReturnCopy() public void AsValueEnumerable_With_ReferenceType_Must_ReturnSame() { // Arrange - var source = new int[0]; + var source = Array.Empty(); var wrapped = Wrap .AsValueEnumerable(source) as IValueEnumerable>; // Act - var result = ValueEnumerableExtensions - .AsValueEnumerable>, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .AsValueEnumerable>, Wrap.Enumerator, int>(); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs index b46dd59c4..588ee658c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs @@ -20,8 +20,7 @@ public void AsValueEnumerable_With_ImmutableArray_Must_ReturnWrapper(int[] sourc // Assert _ = result.Must() - .BeOfType>() -// .BeOfType, ValueEnumerator, ImmutableArray.Enumerator, int, ImmutableArrayExtensions.GetEnumerator, ImmutableArrayExtensions.GetEnumerator2>>() + .BeOfType, int>>() .BeEnumerableOf() .BeEqualTo(source); } diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs index d30902644..ac1be3df1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs @@ -87,8 +87,8 @@ public void ElementAt_Skip_Take_With_ValidData_Must_Return_Some(int[] source, in { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skipCount) + var expected = source + .Skip(skipCount) .Take(takeCount) .ToList(); @@ -144,8 +144,8 @@ public void ElementAt_Skip_Take_Predicate_With_ValidData_Must_Return_Some(int[] { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skipCount) + var expected = source + .Skip(skipCount) .Take(takeCount) .Where(predicate) .ToList(); @@ -203,8 +203,8 @@ public void ElementAt_Skip_Take_PredicateAt_With_ValidData_Must_Return_Some(int[ { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skipCount) + var expected = source + .Skip(skipCount) .Take(takeCount) .Where(predicate) .ToList(); @@ -262,8 +262,8 @@ public void ElementAt_Skip_Take_Selector_With_ValidData_Must_Return_Some(int[] s { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skipCount) + var expected = source + .Skip(skipCount) .Take(takeCount) .Select(selector) .ToList(); @@ -321,8 +321,8 @@ public void ElementAt_Skip_Take_SelectorAt_With_ValidData_Must_Return_Some(int[] { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skipCount) + var expected = source + .Skip(skipCount) .Take(takeCount) .Select(selector) .ToList(); @@ -382,8 +382,8 @@ public void ElementAt_Skip_Take_Predicate_Selector_With_ValidData_Must_Return_So { // Arrange var wrapped = Wrap.AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skipCount) + var expected = source + .Skip(skipCount) .Take(takeCount) .Where(predicate) .Select(selector) diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueEnumerable.Tests.cs index 0561f4e94..421132231 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueEnumerable.Tests.cs @@ -18,10 +18,10 @@ public void ElementAt_With_OutOfRange_Must_Return_None(int[] source) .AsValueEnumerable(source); // Act - var optionNegative = ValueEnumerableExtensions - .ElementAt, Wrap.Enumerator, int>(wrapped, -1); - var optionTooLarge = ValueEnumerableExtensions - .ElementAt, Wrap.Enumerator, int>(wrapped, source.Length); + var optionNegative = wrapped + .ElementAt, Wrap.Enumerator, int>(-1); + var optionTooLarge = wrapped + .ElementAt, Wrap.Enumerator, int>(source.Length); // Assert _ = optionNegative.Must() @@ -42,12 +42,12 @@ public void ElementAt_With_ValidData_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .ElementAt(source, index); + var expected = source + .ElementAt(index); // Act - var result = ValueEnumerableExtensions - .ElementAt, Wrap.Enumerator, int>(wrapped, index); + var result = wrapped + .ElementAt, Wrap.Enumerator, int>(index); // Assert _ = result.Match( @@ -67,11 +67,11 @@ public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, F .AsValueEnumerable(source); // Act - var optionNegative = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var optionNegative = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ElementAt(-1); - var optionTooLarge = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var optionTooLarge = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ElementAt(source.Length); // Assert @@ -91,15 +91,15 @@ public void ElementAt_Predicate_With_ValidData_Must_Return_Some(int[] source, Fu // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ElementAt(index); // Assert @@ -120,11 +120,11 @@ public void ElementAt_PredicateAt_With_OutOfRange_Must_Return_None(int[] source, .AsValueEnumerable(source); // Act - var optionNegative = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var optionNegative = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ElementAt(-1); - var optionTooLarge = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var optionTooLarge = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ElementAt(source.Length); // Assert @@ -144,15 +144,15 @@ public void ElementAt_PredicateAt_With_ValidData_Must_Return_Some(int[] source, // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .ElementAt(index); // Assert @@ -173,11 +173,11 @@ public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, Fu .AsValueEnumerable(source); // Act - var optionNegative = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var optionNegative = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ElementAt(-1); - var optionTooLarge = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var optionTooLarge = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ElementAt(source.Length); // Assert @@ -197,15 +197,15 @@ public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Fun // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act - var result = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ElementAt(index); // Assert @@ -226,11 +226,11 @@ public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, .AsValueEnumerable(source); // Act - var optionNegative = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var optionNegative = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ElementAt(-1); - var optionTooLarge = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var optionTooLarge = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ElementAt(source.Length); // Assert @@ -250,15 +250,15 @@ public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, F // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act - var result = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .ElementAt(index); // Assert @@ -279,12 +279,12 @@ public void ElementAt_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] .AsValueEnumerable(source); // Act - var optionNegative = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var optionNegative = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .ElementAt(-1); - var optionTooLarge = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var optionTooLarge = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .ElementAt(source.Length); @@ -305,16 +305,16 @@ public void ElementAt_Predicate_Selector_With_ValidData_Must_Return_Some(int[] s // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .ElementAt(index); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs index 659cbc4bf..fc2aebb99 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs @@ -42,8 +42,8 @@ public void ElementAt_With_ValidData_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .ElementAt(source, index); + var expected = source + .ElementAt(index); // Act var result = ValueReadOnlyCollectionExtensions @@ -90,8 +90,8 @@ public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Fun { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) @@ -143,8 +143,8 @@ public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, F // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs index dc6f77f7d..e293faf1e 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs @@ -19,10 +19,10 @@ public async void ElementAtAsync_With_OutOfRange_Must_Return_None(int[] source) .AsAsyncValueEnumerable(source); // Act - var optionNegative = await AsyncValueEnumerableExtensions - .ElementAtAsync, Wrap.AsyncEnumerator, int>(wrapped, -1); - var optionTooLarge = await AsyncValueEnumerableExtensions - .ElementAtAsync, Wrap.AsyncEnumerator, int>(wrapped, source.Length); + var optionNegative = await wrapped + .ElementAtAsync, Wrap.AsyncEnumerator, int>(-1); + var optionTooLarge = await wrapped + .ElementAtAsync, Wrap.AsyncEnumerator, int>(source.Length); // Assert _ = optionNegative.Must() @@ -43,12 +43,12 @@ public async ValueTask ElementAtAsync_With_ValidData_Must_Return_Some(int[] sour for (var index = 0; index < source.Length; index++) { // Arrange - var expected = Enumerable - .ElementAt(source, index); + var expected = source + .ElementAt(index); // Act - var result = await AsyncValueEnumerableExtensions - .ElementAtAsync, Wrap.AsyncEnumerator, int>(wrapped, index); + var result = await wrapped + .ElementAtAsync, Wrap.AsyncEnumerator, int>(index); // Assert _ = result.Match( @@ -68,11 +68,11 @@ public async void ElementAtAsync_Predicate_With_OutOfRange_Must_Return_None(int[ .AsAsyncValueEnumerable(source); // Act - var optionNegative = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var optionNegative = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ElementAtAsync(-1); - var optionTooLarge = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var optionTooLarge = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ElementAtAsync(source.Length); // Assert @@ -92,15 +92,15 @@ public async ValueTask ElementAtAsync_Predicate_With_ValidData_Must_Return_Some( // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ElementAtAsync(index); // Assert @@ -121,11 +121,11 @@ public async void ElementAtAsync_PredicateAt_With_OutOfRange_Must_Return_None(in .AsAsyncValueEnumerable(source); // Act - var optionNegative = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var optionNegative = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ElementAtAsync(-1); - var optionTooLarge = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var optionTooLarge = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ElementAtAsync(source.Length); // Assert @@ -144,15 +144,15 @@ public async ValueTask ElementAtAsync_PredicateAt_With_ValidData_Must_Return_Som { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .ElementAtAsync(index); // Assert @@ -173,11 +173,11 @@ public async void ElementAtAsync_Selector_With_OutOfRange_Must_Return_None(int[] .AsAsyncValueEnumerable(source); // Act - var optionNegative = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var optionNegative = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ElementAtAsync(-1); - var optionTooLarge = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var optionTooLarge = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ElementAtAsync(source.Length); // Assert @@ -196,15 +196,15 @@ public async ValueTask ElementAtAsync_Selector_With_ValidData_Must_Return_Some(i { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ElementAtAsync(index); // Assert @@ -225,11 +225,11 @@ public async void ElementAtAsync_SelectorAt_With_OutOfRange_Must_Return_None(int .AsAsyncValueEnumerable(source); // Act - var optionNegative = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var optionNegative = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ElementAtAsync(-1); - var optionTooLarge = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var optionTooLarge = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ElementAtAsync(source.Length); // Assert @@ -249,15 +249,15 @@ public async ValueTask ElementAtAsync_SelectorAt_With_ValidData_Must_Return_Some // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .ElementAtAsync(index); // Assert @@ -278,12 +278,12 @@ public async void ElementAtAsync_Predicate_Selector_With_OutOfRange_Must_Return_ .AsAsyncValueEnumerable(source); // Act - var optionNegative = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var optionNegative = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .ElementAtAsync(-1); - var optionTooLarge = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var optionTooLarge = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .ElementAtAsync(source.Length); @@ -304,16 +304,16 @@ public async ValueTask ElementAtAsync_Predicate_Selector_With_ValidData_Must_Ret // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .ElementAtAsync(index); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs index d238f8355..1edfe5679 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs @@ -33,8 +33,8 @@ public void First_With_ValidData_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .First(source); + var expected = source + .First(); // Act var result = wrapped.AsValueEnumerable() @@ -74,8 +74,8 @@ public void First_SkipTake_With_ValidData_Must_Return_Some(int[] source, int ski // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .First(); @@ -120,8 +120,8 @@ public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, int sk // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .First(predicate); @@ -167,8 +167,8 @@ public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, int // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(wrapped, skip) + var expected = wrapped + .Skip(skip) .Take(take) .Where(predicate) .First(); @@ -215,8 +215,8 @@ public void First_Selector_With_ValidData_Must_Return_Some(int[] source, int ski // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .First(); @@ -263,8 +263,8 @@ public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, int s // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .First(); @@ -312,8 +312,8 @@ public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] sourc // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .Select(selector) diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs index 636bf0061..8e609ef94 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs @@ -31,8 +31,8 @@ public void First_With_ValidData_Must_Return_Some(int[] source) { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); - var expected = Enumerable - .First(source); + var expected = source + .First(); // Act var result = wrapped.AsValueEnumerable() @@ -69,8 +69,8 @@ public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, Func)source.AsSpan(); - var expected = Enumerable - .First(source, predicate); + var expected = source + .First(predicate); // Act var result = wrapped.AsValueEnumerable() @@ -108,8 +108,8 @@ public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .First(); // Act @@ -148,8 +148,8 @@ public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Func)source.AsSpan(); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .First(); // Act @@ -188,8 +188,8 @@ public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func< { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .First(); // Act @@ -229,8 +229,8 @@ public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] sourc { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .First(); @@ -246,4 +246,4 @@ public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] sourc () => throw new Exception()); } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueEnumerable.Tests.cs index 364a06132..081c29cd5 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueEnumerable.Tests.cs @@ -16,8 +16,8 @@ public void First_With_Empty_Must_Return_None(int[] source) .AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .First, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .First, Wrap.Enumerator, int>(); // Assert _ = result.Must() @@ -33,12 +33,12 @@ public void First_With_ValidData_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .First(source); + var expected = source + .First(); // Act - var result = ValueEnumerableExtensions - .First, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .First, Wrap.Enumerator, int>(); // Assert _ = result.Match( @@ -55,8 +55,8 @@ public void First_Predicate_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .First(); // Assert @@ -73,12 +73,12 @@ public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .First(); // Assert @@ -96,8 +96,8 @@ public void First_PredicateAt_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .First(); // Assert @@ -114,13 +114,13 @@ public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .First(); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .First(); // Assert @@ -138,8 +138,8 @@ public void First_Selector_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .First(); // Assert @@ -156,13 +156,13 @@ public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .First(); // Assert @@ -180,8 +180,8 @@ public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .First(); // Assert @@ -198,13 +198,13 @@ public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func< // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .First(); // Act - var result = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .First(); // Assert @@ -222,8 +222,8 @@ public void First_Predicate_Selector_With_Empty_Must_Return_None(int[] source, F .AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .First(); @@ -241,14 +241,14 @@ public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] sourc // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .First(); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .First(); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs index c5a3ef19c..ecbb6c856 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs @@ -33,8 +33,8 @@ public void First_With_ValidData_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .First(source); + var expected = source + .First(); // Act var result = ValueReadOnlyCollectionExtensions @@ -73,8 +73,8 @@ public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Func, Wrap.AsyncEnumerator, int>(wrapped); + var result = await wrapped + .FirstAsync, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Must() @@ -34,12 +34,12 @@ public async ValueTask FirstAsync_With_ValidData_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .First(source); + var expected = source + .First(); // Act - var result = await AsyncValueEnumerableExtensions - .FirstAsync, Wrap.AsyncEnumerator, int>(wrapped); + var result = await wrapped + .FirstAsync, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Match( @@ -56,8 +56,8 @@ public async void FirstAsync_Predicate_With_Empty_Must_Return_None(int[] source, .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .FirstAsync(); // Assert @@ -74,12 +74,12 @@ public async ValueTask FirstAsync_Predicate_With_ValidData_Must_Return_Some(int[ // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .First(source, predicate); + var expected = source + .First(predicate); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .FirstAsync(); // Assert @@ -97,8 +97,8 @@ public async void FirstAsync_PredicateAt_With_Empty_Must_Return_None(int[] sourc .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .FirstAsync(); // Assert @@ -115,13 +115,13 @@ public async ValueTask FirstAsync_PredicateAt_With_ValidData_Must_Return_Some(in // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .First(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .FirstAsync(); // Assert @@ -139,8 +139,8 @@ public async void FirstAsync_Selector_With_Empty_Must_Return_None(int[] source, .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .FirstAsync(); // Assert @@ -157,13 +157,13 @@ public async ValueTask FirstAsync_Selector_With_ValidData_Must_Return_Some(int[] // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .First(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .FirstAsync(); // Assert @@ -181,8 +181,8 @@ public async void FirstAsync_SelectorAt_With_Empty_Must_Return_None(int[] source .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .FirstAsync(); // Assert @@ -199,13 +199,13 @@ public async ValueTask FirstAsync_SelectorAt_With_ValidData_Must_Return_Some(int // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .First(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .FirstAsync(); // Assert @@ -223,8 +223,8 @@ public async void FirstAsync_Predicate_Selector_With_Empty_Must_Return_None(int[ .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .FirstAsync(); @@ -242,14 +242,14 @@ public async ValueTask FirstAsync_Predicate_Selector_With_ValidData_Must_Return_ // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .First(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .FirstAsync(); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs index 5ee477522..075660b4d 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs @@ -32,8 +32,8 @@ public void Single_With_Single_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Single(source); + var expected = source + .Single(); // Act var result = wrapped.AsValueEnumerable() @@ -90,8 +90,8 @@ public void Single_SkipTake_With_Single_Must_Return_Some(int[] source, int skip, // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Single(); @@ -155,8 +155,8 @@ public void Single_Predicate_With_Single_Must_Return_Some(int[] source, int skip // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Single(predicate); @@ -222,8 +222,8 @@ public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, int sk // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .Single(); @@ -290,8 +290,8 @@ public void Single_Selector_With_Single_Must_Return_Some(int[] source, int skip, // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .Single(); @@ -358,8 +358,8 @@ public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, int ski // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Select(selector) .Single(); @@ -427,8 +427,8 @@ public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .Skip(source, skip) + var expected = source + .Skip(skip) .Take(take) .Where(predicate) .Select(selector) diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueEnumerable.Tests.cs index 44a7ed031..b87cc4cab 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueEnumerable.Tests.cs @@ -16,8 +16,8 @@ public void Single_With_Empty_Must_Return_None(int[] source) .AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Single, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .Single, Wrap.Enumerator, int>(); // Assert _ = result.Must() @@ -32,12 +32,12 @@ public void Single_With_Single_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Single(source); + var expected = source + .Single(); // Act - var result = ValueEnumerableExtensions - .Single, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .Single, Wrap.Enumerator, int>(); // Assert _ = result.Match( @@ -54,8 +54,8 @@ public void Single_With_Multiple_Must_Return_None(int[] source) .AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Single, Wrap.Enumerator, int>(wrapped); + var result = wrapped + .Single, Wrap.Enumerator, int>(); // Assert _ = result.Must() @@ -72,8 +72,8 @@ public void Single_Predicate_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Single(); // Assert @@ -89,12 +89,12 @@ public void Single_Predicate_With_Single_Must_Return_Some(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Single(); // Assert @@ -112,8 +112,8 @@ public void Single_Predicate_With_Multiple_Must_Return_None(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Single(); // Assert @@ -131,8 +131,8 @@ public void Single_PredicateAt_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Single(); // Assert @@ -148,13 +148,13 @@ public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Single(); // Assert @@ -172,8 +172,8 @@ public void Single_PredicateAt_With_Multiple_Must_Return_None(int[] source, Func .AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Single(); // Assert @@ -191,8 +191,8 @@ public void Single_Selector_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .Single(); // Assert @@ -208,13 +208,13 @@ public void Single_Selector_With_Single_Must_Return_Some(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .Single(); // Assert @@ -232,8 +232,8 @@ public void Single_Selector_With_Multiple_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .Single(); // Assert @@ -251,8 +251,8 @@ public void Single_SelectorAt_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .Single(); // Assert @@ -268,13 +268,13 @@ public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .Single(); // Assert @@ -292,8 +292,8 @@ public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, Func< .AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped + .Select, Wrap.Enumerator, int, string>(selector) .Single(); // Assert @@ -311,8 +311,8 @@ public void Single_Predicate_Selector_With_Empty_Must_Return_None(int[] source, .AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .Single(); @@ -329,14 +329,14 @@ public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, // Arrange var wrapped = Wrap .AsValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .Single(); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .Single(); @@ -355,8 +355,8 @@ public void Single_Predicate_Selector_With_Multiple_Must_Return_None(int[] sourc .AsValueEnumerable(source); // Act - var result = ValueEnumerableExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped + .Where, Wrap.Enumerator, int>(predicate) .Select(selector) .Single(); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs index 25f7f34a5..297504b08 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs @@ -32,8 +32,8 @@ public void Single_With_Single_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); - var expected = Enumerable - .Single(source); + var expected = source + .Single(); // Act var result = ValueReadOnlyCollectionExtensions @@ -89,8 +89,8 @@ public void Single_Selector_With_Single_Must_Return_Some(int[] source, Func, Wrap.AsyncEnumerator, int>(wrapped); + var result = await wrapped + .SingleAsync, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Must() @@ -33,12 +33,12 @@ public async ValueTask SingleAsync_With_SingleAsync_Must_Return_Some(int[] sourc // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Single(source); + var expected = source + .Single(); // Act - var result = await AsyncValueEnumerableExtensions - .SingleAsync, Wrap.AsyncEnumerator, int>(wrapped); + var result = await wrapped + .SingleAsync, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Match( @@ -55,8 +55,8 @@ public async void SingleAsync_With_Multiple_Must_Return_None(int[] source) .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .SingleAsync, Wrap.AsyncEnumerator, int>(wrapped); + var result = await wrapped + .SingleAsync, Wrap.AsyncEnumerator, int>(); // Assert _ = result.Must() @@ -73,8 +73,8 @@ public async void SingleAsync_Predicate_With_Empty_Must_Return_None(int[] source .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .SingleAsync(); // Assert @@ -90,12 +90,12 @@ public async ValueTask SingleAsync_Predicate_With_SingleAsync_Must_Return_Some(i // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Single(source, predicate); + var expected = source + .Single(predicate); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .SingleAsync(); // Assert @@ -113,8 +113,8 @@ public async void SingleAsync_Predicate_With_Multiple_Must_Return_None(int[] sou .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .SingleAsync(); // Assert @@ -132,8 +132,8 @@ public async void SingleAsync_PredicateAt_With_Empty_Must_Return_None(int[] sour .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .SingleAsync(); // Assert @@ -149,13 +149,13 @@ public async ValueTask SingleAsync_PredicateAt_With_SingleAsync_Must_Return_Some // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Single(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .SingleAsync(); // Assert @@ -173,8 +173,8 @@ public async void SingleAsync_PredicateAt_With_Multiple_Must_Return_None(int[] s .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .SingleAsync(); // Assert @@ -192,8 +192,8 @@ public async void SingleAsync_Selector_With_Empty_Must_Return_None(int[] source, .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .SingleAsync(); // Assert @@ -209,13 +209,13 @@ public async ValueTask SingleAsync_Selector_With_SingleAsync_Must_Return_Some(in // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .Single(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .SingleAsync(); // Assert @@ -233,8 +233,8 @@ public async void SingleAsync_Selector_With_Multiple_Must_Return_None(int[] sour .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .SingleAsync(); // Assert @@ -252,8 +252,8 @@ public async void SingleAsync_SelectorAt_With_Empty_Must_Return_None(int[] sourc .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .SingleAsync(); // Assert @@ -269,13 +269,13 @@ public async ValueTask SingleAsync_SelectorAt_With_SingleAsync_Must_Return_Some( // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .Single(); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .SingleAsync(); // Assert @@ -293,8 +293,8 @@ public async void SingleAsync_SelectorAt_With_Multiple_Must_Return_None(int[] so .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Select, Wrap.AsyncEnumerator, int, string>(wrapped, selector.AsAsync()) + var result = await wrapped + .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) .SingleAsync(); // Assert @@ -312,8 +312,8 @@ public async void SingleAsync_Predicate_Selector_With_Empty_Must_Return_None(int .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .SingleAsync(); @@ -330,14 +330,14 @@ public async ValueTask SingleAsync_Predicate_Selector_With_SingleAsync_Must_Retu // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .Single(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .SingleAsync(); @@ -356,8 +356,8 @@ public async void SingleAsync_Predicate_Selector_With_Multiple_Must_Return_None( .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped + .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) .SingleAsync(); diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs index 3573542ee..e9d142ba7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs @@ -96,4 +96,4 @@ public void Where_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int ta .BeEqualTo(expected); } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs index abca4cf1b..80903dfda 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs @@ -45,7 +45,7 @@ public void Range_With_ValidData_Must_Succeed(int start, int count) public void Range_Skip_With_ValidData_Must_Succeed(int start, int count, int skip) { // Arrange - var expected = Enumerable.Skip(Enumerable.Range(start, count), skip); + var expected = Enumerable.Range(start, count).Skip(skip); // Act var result = AsyncValueEnumerable.Range(start, count).Skip(skip); @@ -61,7 +61,7 @@ public void Range_Skip_With_ValidData_Must_Succeed(int start, int count, int ski public void Range_Take_With_ValidData_Must_Succeed(int start, int count, int take) { // Arrange - var expected = Enumerable.Take(Enumerable.Range(start, count), take); + var expected = Enumerable.Range(start, count).Take(take); // Act var result = AsyncValueEnumerable.Range(start, count).Take(take); @@ -77,7 +77,7 @@ public void Range_Take_With_ValidData_Must_Succeed(int start, int count, int tak public async ValueTask Range_AnyAsync_With_ValidData_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.Any(Enumerable.Range(start, count)); + var expected = Enumerable.Range(start, count).Any(); // Act var result = await AsyncValueEnumerable.Range(start, count).AnyAsync(); @@ -92,10 +92,14 @@ public async ValueTask Range_AnyAsync_With_ValidData_Must_Succeed(int start, int public async ValueTask Range_ContainsAsync_With_ValidData_Must_Succeed(int start, int count, int value) { // Arrange - var expected = Enumerable.Contains(Enumerable.Range(start, count), value); + var expected = Enumerable + .Range(start, count) + .Contains(value); // Act - var result = await AsyncValueEnumerable.Range(start, count).ContainsAsync(value); + var result = await AsyncValueEnumerable + .Range(start, count) + .ContainsAsync(value); // Assert _ = result.Must() @@ -107,7 +111,7 @@ public async ValueTask Range_ContainsAsync_With_ValidData_Must_Succeed(int start public async ValueTask Range_ToArray_With_ValidData_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.ToArray(Enumerable.Range(start, count)); + var expected = Enumerable.Range(start, count).ToArray(); // Act var result = await AsyncValueEnumerable.Range(start, count).ToArrayAsync(); @@ -123,7 +127,7 @@ public async ValueTask Range_ToArray_With_ValidData_Must_Succeed(int start, int public async ValueTask Range_With_ToList_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.ToList(Enumerable.Range(start, count)); + var expected = Enumerable.Range(start, count).ToList(); // Act var result = await AsyncValueEnumerable.Range(start, count).ToListAsync(); diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs index 3a59d55a4..e1161af90 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs @@ -46,7 +46,7 @@ public void Repeat_With_ValidData_Must_Succeed(int value, int count) public void Repeat_Skip_With_ValidData_Must_Succeed(int value, int count, int skip) { // Arrange - var expected = Enumerable.Skip(Enumerable.Repeat(value, count), skip); + var expected = Enumerable.Repeat(value, count).Skip(skip); // Act var result = AsyncValueEnumerable.Repeat(value, count).Skip(skip); @@ -62,7 +62,7 @@ public void Repeat_Skip_With_ValidData_Must_Succeed(int value, int count, int sk public void Repeat_Take_With_ValidData_Must_Succeed(int value, int count, int take) { // Arrange - var expected = Enumerable.Take(Enumerable.Repeat(value, count), take); + var expected = Enumerable.Repeat(value, count).Take(take); // Act var result = AsyncValueEnumerable.Repeat(value, count).Take(take); @@ -78,7 +78,7 @@ public void Repeat_Take_With_ValidData_Must_Succeed(int value, int count, int ta public async ValueTask Repeat_All_With_ValidData_Must_Succeed(int value, int count) { // Arrange - var expected = Enumerable.All(Enumerable.Repeat(value, count), item => false); + var expected = Enumerable.Repeat(value, count).All(item => false); // Act var result = await AsyncValueEnumerable.Repeat(value, count).AllAsync(item => false); @@ -93,7 +93,7 @@ public async ValueTask Repeat_All_With_ValidData_Must_Succeed(int value, int cou public async ValueTask Repeat_Any_With_ValidData_Must_Succeed(int value, int count) { // Arrange - var expected = Enumerable.Any(Enumerable.Repeat(value, count)); + var expected = Enumerable.Repeat(value, count).Any(); // Act var result = await AsyncValueEnumerable.Repeat(value, count).AnyAsync(); @@ -108,7 +108,7 @@ public async ValueTask Repeat_Any_With_ValidData_Must_Succeed(int value, int cou public async ValueTask Repeat_ToArray_With_ValidData_Must_Succeed(int value, int count) { // Arrange - var expected = Enumerable.ToArray(Enumerable.Repeat(value, count)); + var expected = Enumerable.Repeat(value, count).ToArray(); // Act var result = await AsyncValueEnumerable.Repeat(value, count).ToArrayAsync(); @@ -124,7 +124,7 @@ public async ValueTask Repeat_ToArray_With_ValidData_Must_Succeed(int value, int public async ValueTask Repeat_ToList_With_ValidData_Must_Succeed(int value, int count) { // Arrange - var expected = Enumerable.ToList(Enumerable.Repeat(value, count)); + var expected = Enumerable.Repeat(value, count).ToList(); // Act var result = await AsyncValueEnumerable.Repeat(value, count).ToListAsync(); diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs index 0a769fdfa..657412273 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs @@ -44,7 +44,7 @@ public void Range_With_ValidData_Must_Succeed(int start, int count) public void Range_Skip_With_ValidData_Must_Succeed(int start, int count, int skip) { // Arrange - var expected = Enumerable.Skip(Enumerable.Range(start, count), skip); + var expected = Enumerable.Range(start, count).Skip(skip); // Act var result = ValueEnumerable.Range(start, count).Skip(skip); @@ -60,7 +60,7 @@ public void Range_Skip_With_ValidData_Must_Succeed(int start, int count, int ski public void Range_Take_With_ValidData_Must_Succeed(int start, int count, int take) { // Arrange - var expected = Enumerable.Take(Enumerable.Range(start, count), take); + var expected = Enumerable.Range(start, count).Take(take); // Act var result = ValueEnumerable.Range(start, count).Take(take); @@ -76,7 +76,7 @@ public void Range_Take_With_ValidData_Must_Succeed(int start, int count, int tak public void Range_Any_With_ValidData_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.Any(Enumerable.Range(start, count)); + var expected = Enumerable.Range(start, count).Any(); // Act var result = ValueEnumerable.Range(start, count).Any(); @@ -91,7 +91,7 @@ public void Range_Any_With_ValidData_Must_Succeed(int start, int count) public void Range_Contains_With_ValidData_Must_Succeed(int start, int count, int value) { // Arrange - var expected = Enumerable.Contains(Enumerable.Range(start, count), value); + var expected = Enumerable.Range(start, count).Contains(value); // Act var result = ValueEnumerable.Range(start, count).Contains(value); @@ -106,7 +106,7 @@ public void Range_Contains_With_ValidData_Must_Succeed(int start, int count, int public void Range_ToArray_With_ValidData_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.ToArray(Enumerable.Range(start, count)); + var expected = Enumerable.Range(start, count).ToArray(); // Act var result = ValueEnumerable.Range(start, count).ToArray(); @@ -122,7 +122,7 @@ public void Range_ToArray_With_ValidData_Must_Succeed(int start, int count) public void Range_With_ToList_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.ToList(Enumerable.Range(start, count)); + var expected = Enumerable.Range(start, count).ToList(); // Act var result = ValueEnumerable.Range(start, count).ToList(); @@ -139,7 +139,7 @@ public void Range_With_ToList_Must_Succeed(int start, int count) public void Range_SelectVector_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.Select(Enumerable.Range(start, count), item => item * 2); + var expected = Enumerable.Range(start, count).Select(item => item * 2); // Act var result = ValueEnumerable.Range(start, count).SelectVector(item => item * 2, item => item * 2); @@ -156,7 +156,7 @@ public void Range_SelectVector_Must_Succeed(int start, int count) public void Range_SelectVector_Sum_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.Sum(Enumerable.Select(Enumerable.Range(start, count), item => item * 2)); + var expected = Enumerable.Range(start, count).Select(item => item * 2).Sum(); // Act var result = ValueEnumerable.Range(start, count).SelectVector(item => item * 2, item => item * 2).Sum(); @@ -172,7 +172,7 @@ public void Range_SelectVector_Sum_Must_Succeed(int start, int count) public void Range_SelectVector_ToArray_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.ToArray(Enumerable.Select(Enumerable.Range(start, count), item => item * 2)); + var expected = Enumerable.Range(start, count).Select(item => item * 2).ToArray(); // Act var result = ValueEnumerable.Range(start, count).SelectVector(item => item * 2, item => item * 2).ToArray(); @@ -188,7 +188,7 @@ public void Range_SelectVector_ToArray_Must_Succeed(int start, int count) public void Range_SelectVector_ToList_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.ToList(Enumerable.Select(Enumerable.Range(start, count), item => item * 2)); + var expected = Enumerable.Range(start, count).Select(item => item * 2).ToList(); // Act var result = ValueEnumerable.Range(start, count).SelectVector(item => item * 2, item => item * 2).ToList(); diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Repeat.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Repeat.Tests.cs index a57516052..a5aad7217 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Repeat.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Repeat.Tests.cs @@ -1,6 +1,7 @@ using NetFabric.Assertive; using System; using System.Collections.Generic; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Generation.ValueEnumerableTests @@ -28,7 +29,7 @@ public void Repeat_With_NegativeCount_Must_Throw(int count) public void Repeat_With_ValidData_Must_Succeed(int value, int count) { // Arrange - var expected = System.Linq.Enumerable.Repeat(value, count); + var expected = Enumerable.Repeat(value, count); // Act var result = ValueEnumerable.Repeat(value, count); @@ -44,10 +45,14 @@ public void Repeat_With_ValidData_Must_Succeed(int value, int count) public void Repeat_Skip_With_ValidData_Must_Succeed(int value, int count, int skip) { // Arrange - var expected = System.Linq.Enumerable.Skip(System.Linq.Enumerable.Repeat(value, count), skip); + var expected = Enumerable + .Repeat(value, count) + .Skip(skip); // Act - var result = ValueEnumerable.Repeat(value, count).Skip(skip); + var result = ValueEnumerable + .Repeat(value, count) + .Skip(skip); // Assert _ = result.Must() @@ -60,10 +65,14 @@ public void Repeat_Skip_With_ValidData_Must_Succeed(int value, int count, int sk public void Repeat_Take_With_ValidData_Must_Succeed(int value, int count, int take) { // Arrange - var expected = System.Linq.Enumerable.Take(System.Linq.Enumerable.Repeat(value, count), take); + var expected = Enumerable + .Repeat(value, count) + .Take(take); // Act - var result = ValueEnumerable.Repeat(value, count).Take(take); + var result = ValueEnumerable + .Repeat(value, count) + .Take(take); // Assert _ = result.Must() @@ -76,10 +85,14 @@ public void Repeat_Take_With_ValidData_Must_Succeed(int value, int count, int ta public void Repeat_All_With_ValidData_Must_Succeed(int value, int count) { // Arrange - var expected = System.Linq.Enumerable.All(System.Linq.Enumerable.Repeat(value, count), item => false); + var expected = Enumerable + .Repeat(value, count) + .All(item => false); // Act - var result = ValueEnumerable.Repeat(value, count).All(item => false); + var result = ValueEnumerable + .Repeat(value, count) + .All(item => false); // Assert _ = result.Must() @@ -91,10 +104,14 @@ public void Repeat_All_With_ValidData_Must_Succeed(int value, int count) public void Repeat_Any_With_ValidData_Must_Succeed(int value, int count) { // Arrange - var expected = System.Linq.Enumerable.Any(System.Linq.Enumerable.Repeat(value, count)); + var expected = Enumerable + .Repeat(value, count) + .Any(); // Act - var result = ValueEnumerable.Repeat(value, count).Any(); + var result = ValueEnumerable + .Repeat(value, count) + .Any(); // Assert _ = result.Must() @@ -106,10 +123,14 @@ public void Repeat_Any_With_ValidData_Must_Succeed(int value, int count) public void Repeat_ToArray_With_ValidData_Must_Succeed(int value, int count) { // Arrange - var expected = System.Linq.Enumerable.ToArray(System.Linq.Enumerable.Repeat(value, count)); + var expected = Enumerable + .Repeat(value, count) + .ToArray(); // Act - var result = ValueEnumerable.Repeat(value, count).ToArray(); + var result = ValueEnumerable + .Repeat(value, count) + .ToArray(); // Assert _ = result.Must() @@ -122,10 +143,14 @@ public void Repeat_ToArray_With_ValidData_Must_Succeed(int value, int count) public void Repeat_ToList_With_ValidData_Must_Succeed(int value, int count) { // Arrange - var expected = System.Linq.Enumerable.ToList(System.Linq.Enumerable.Repeat(value, count)); + var expected = Enumerable + .Repeat(value, count) + .ToList(); // Act - var result = ValueEnumerable.Repeat(value, count).ToList(); + var result = ValueEnumerable + .Repeat(value, count) + .ToList(); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs index 1903fbbce..4594c50e4 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs @@ -57,8 +57,8 @@ public void Select_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int t // Arrange var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); - var expected = wrapped - .Select(item => item) + var expected = Enumerable + .Select(wrapped, item => item) .Sum(); // Act @@ -72,4 +72,4 @@ public void Select_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int t } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs index 63f6670c4..985c894b6 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs @@ -14,7 +14,7 @@ public static AsyncEnumerableWrapper AsAsyncEnumerable(T[] source) _ => new AsyncEnumerableWrapper(source) }; - public readonly struct AsyncEnumerableWrapper + public class AsyncEnumerableWrapper : IAsyncEnumerable { readonly T[] source; @@ -22,10 +22,10 @@ public readonly struct AsyncEnumerableWrapper internal AsyncEnumerableWrapper(T[] source) => this.source = source; - public readonly AsyncEnumerator GetAsyncEnumerator() + public AsyncEnumerator GetAsyncEnumerator() => new(source); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) => new AsyncEnumerator(source); } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs index d829b51a9..56e043d52 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -30,10 +29,9 @@ static int CountAt(this TList source, TPredicate pre where TPredicate: struct, IFunction { var counter = 0; - var end = count; if (offset is 0) { - for (var index = 0; index < end; index++) + for (var index = 0; index < count; index++) { var item = source[index]; counter += predicate.Invoke(item, index).AsByte(); @@ -41,7 +39,7 @@ static int CountAt(this TList source, TPredicate pre } else { - for (var index = 0; index < end; index++) + for (var index = 0; index < count; index++) { var item = source[index + offset]; counter += predicate.Invoke(item, index).AsByte(); diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs index 5a44adece..85159bc7d 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs index c424480b6..5f77da2ff 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs index c67621338..03bf9f08f 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs @@ -1,4 +1,3 @@ -using System; using System.Numerics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs index d9386b3ee..4510feb15 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs @@ -1,18 +1,16 @@ -using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { public static partial class ReadOnlyListExtensions { public static TSum Sum(this TList source) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList where TSum : struct => source.Sum(0, source.Count); static TSum Sum(this TList source, int offset, int count) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList where TSum : struct { var sum = default(TSum); @@ -26,7 +24,7 @@ static TSum Sum(this TList source, int offset, int count) } static TSum Sum(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList where TPredicate : struct, IFunction where TSum : struct { @@ -42,7 +40,7 @@ static TSum Sum(this TList source, TPredicate } static TSum SumAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList where TPredicate : struct, IFunction where TSum : struct { @@ -58,7 +56,7 @@ static TSum SumAt(this TList source, TPredicat } static TSum Sum(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList where TSelector : struct, IFunction where TSum : struct { @@ -73,7 +71,7 @@ static TSum Sum(this TList source, TSe } static TSum SumAt(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList where TSelector : struct, IFunction where TSum : struct { @@ -88,7 +86,7 @@ static TSum SumAt(this TList source, T } static TSum Sum(this TList source, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList + where TList : IReadOnlyList where TPredicate : struct, IFunction where TSelector : struct, IFunction where TSum : struct diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs index 598f6b1ec..a64ae75b8 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs @@ -1,6 +1,5 @@ using System; using System.Numerics; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs index 676997d87..e12e9aec3 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs index 74942f074..f02249d36 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -59,7 +58,7 @@ readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator( // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source, cancellationToken); - public readonly partial struct AsyncEnumerator + public readonly struct AsyncEnumerator : IAsyncEnumerator { readonly IAsyncEnumerator enumerator; diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.cs index b1adc1b5b..f8da8bc8f 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.cs index d6c0d244e..3d66cb4a3 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; +using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; @@ -39,10 +37,10 @@ readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator( => GetAsyncEnumerator(cancellationToken); [StructLayout(LayoutKind.Auto)] - public readonly partial struct AsyncEnumerator + public struct AsyncEnumerator : IAsyncEnumerator { - readonly TEnumerator enumerator; + TEnumerator enumerator; readonly CancellationToken cancellationToken; internal AsyncEnumerator(TEnumerable enumerable, CancellationToken cancellationToken) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs index 1ad4541c1..ea975d83d 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -28,11 +26,9 @@ internal ValueEnumerable(IEnumerable source) public ValueEnumerator GetEnumerator() => new(source.GetEnumerator()); IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => GetEnumerator(); + => source.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => GetEnumerator(); + => source.GetEnumerator(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index 3ea24f837..a8f49a657 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -32,11 +32,9 @@ public int Count public ValueEnumerator GetEnumerator() => new(source.GetEnumerator()); IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => GetEnumerator(); + => source.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => GetEnumerator(); + => source.GetEnumerator(); bool ICollection.IsReadOnly => true; @@ -64,7 +62,7 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - => Count is not 0 && EnumerableExtensions.Contains(source, item); + => Count is not 0 && source.Contains(item); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs index 4cb5227ee..c3a2e443a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -63,14 +63,11 @@ internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetE public TEnumerator2 GetEnumerator() => getEnumerator2.Invoke(source); TEnumerator IValueEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation => getEnumerator.Invoke(source); IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => getEnumerator.Invoke(source); + => source.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => getEnumerator.Invoke(source); + => source.GetEnumerator(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index 71d5d6d22..c65bda255 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -68,14 +68,11 @@ public readonly int Count public TEnumerator2 GetEnumerator() => getEnumerator2.Invoke(source); TEnumerator IValueEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation => getEnumerator.Invoke(source); IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => getEnumerator.Invoke(source); + => source.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => getEnumerator.Invoke(source); + => source.GetEnumerator(); bool ICollection.IsReadOnly => true; @@ -114,6 +111,7 @@ void ICollection.Clear() [ExcludeFromCodeCoverage] bool ICollection.Remove(TSource item) => Throw.NotSupportedException(); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index 4d24ff86e..5849568db 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -128,7 +128,7 @@ public readonly TSource Current } readonly object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation - => this.Current; + => Current; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs index f2399f52a..f910096ed 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs @@ -1,5 +1,4 @@ using System; -using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -11,21 +10,27 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ListValueEnumerable AsValueEnumerable(this IReadOnlyList source) + public static ValueEnumerable, TSource> AsValueEnumerable(this IReadOnlyList source) + => AsValueEnumerable, TSource>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TList source) + where TList : IReadOnlyList => new(source, 0, source.Count); [StructLayout(LayoutKind.Auto)] - public readonly partial struct ListValueEnumerable - : IValueReadOnlyList.DisposableEnumerator> + public readonly partial struct ValueEnumerable + : IValueReadOnlyList.DisposableEnumerator> , IList + where TList : IReadOnlyList { - internal readonly IReadOnlyList source; + internal readonly TList source; internal readonly int offset; - internal ListValueEnumerable(IReadOnlyList source, int offset, int count) + internal ValueEnumerable(TList source, int offset, int count) => (this.source, this.offset, Count) = (source, offset, count); - public readonly int Count { get; } + public readonly int Count { get; } public readonly TSource this[int index] { @@ -33,31 +38,35 @@ public readonly TSource this[int index] get { if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); - + return source[index + offset]; } } + TSource IReadOnlyList.this[int index] => this[index]; + TSource IList.this[int index] { get => this[index]; - + [ExcludeFromCodeCoverage] // ReSharper disable once ValueParameterNotUsed set => Throw.NotSupportedException(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() + => new(in this); + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); @@ -79,15 +88,7 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - { - var end = offset + Count; - for (var index = offset; index < end; index++) - { - if (EqualityComparer.Default.Equals(source[index], item)) - return true; - } - return false; - } + => Count is not 0 && source.Contains(item); public int IndexOf(TSource item) => ReadOnlyListExtensions.IndexOf(source, item, offset, Count); @@ -95,9 +96,11 @@ public int IndexOf(TSource item) [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] bool ICollection.Remove(TSource item) => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] void ICollection.Clear() => Throw.NotSupportedException(); @@ -105,32 +108,33 @@ void ICollection.Clear() [ExcludeFromCodeCoverage] void IList.Insert(int index, TSource item) => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] void IList.RemoveAt(int index) => Throw.NotSupportedException(); - + [StructLayout(LayoutKind.Auto)] public struct Enumerator { - readonly IReadOnlyList source; + readonly TList source; readonly int end; int index; - internal Enumerator(in ListValueEnumerable enumerable) + internal Enumerator(in ValueEnumerable enumerable) { source = enumerable.source; index = enumerable.offset - 1; end = index + enumerable.Count; } - public readonly TSource Current + public TSource Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => source[index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() + public bool MoveNext() => ++index <= end; } @@ -138,276 +142,108 @@ public bool MoveNext() public struct DisposableEnumerator : IEnumerator { - readonly IReadOnlyList source; + readonly TList source; readonly int end; int index; - internal DisposableEnumerator(in ListValueEnumerable enumerable) + internal DisposableEnumerator(in ValueEnumerable enumerable) { source = enumerable.source; index = enumerable.offset - 1; end = index + enumerable.Count; } - public readonly TSource Current + public TSource Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => source[index]; } - readonly TSource IEnumerator.Current + TSource IEnumerator.Current => source[index]; - readonly object? IEnumerator.Current + object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => source[index]; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() + public bool MoveNext() => ++index <= end; - [MethodImpl(MethodImplOptions.AggressiveInlining)] [ExcludeFromCodeCoverage] - public void Reset() + public readonly void Reset() => Throw.NotSupportedException(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly void Dispose() { } } - - #region Aggregation - - #endregion - - #region Conversion - - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ListValueEnumerable AsEnumerable() - // => this; - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public ListValueEnumerable AsValueEnumerable() - // => this; - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public TSource[] ToArray() - // => ReadOnlyListExtensions.ToArray(source, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public IMemoryOwner ToArray(MemoryPool memoryPool) - // => ReadOnlyListExtensions.ToArray(source, offset, Count, memoryPool); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public List ToList() - // => ReadOnlyListExtensions.ToList(source, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - // where TKey : notnull - // => ReadOnlyListExtensions.ToDictionary(source, keySelector, comparer, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - // where TKey : notnull - // where TKeySelector : struct, IFunction - // => ReadOnlyListExtensions.ToDictionary(source, keySelector, comparer, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - // where TKey : notnull - // => ReadOnlyListExtensions.ToDictionary(source, keySelector, elementSelector, comparer, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - // where TKey : notnull - // where TKeySelector : struct, IFunction - // where TElementSelector : struct, IFunction - // => ReadOnlyListExtensions.ToDictionary(source, keySelector, elementSelector, comparer, offset, Count); - - #endregion - - #region Element - - // public Option ElementAt(int index) - // => ReadOnlyListExtensions.ElementAt(source, index, offset, Count); - // - // public Option First() - // => ReadOnlyListExtensions.First(source, offset, Count); - // - // public Option Single() - // => ReadOnlyListExtensions.Single(source, offset, Count); - - #endregion - - #region Filtering - - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public WhereEnumerable> Where(Func predicate) - // => ReadOnlyListExtensions.Where(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public WhereEnumerable Where(TPredicate predicate = default) - // where TPredicate : struct, IFunction - // => ReadOnlyListExtensions.Where(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public WhereAtEnumerable> Where(Func predicate) - // => ReadOnlyListExtensions.Where(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public WhereAtEnumerable WhereAt(TPredicate predicate = default) - // where TPredicate : struct, IFunction - // => ReadOnlyListExtensions.WhereAt(source, predicate, offset, Count); - - #endregion #region Partitioning [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ListValueEnumerable Skip(int count) + public ValueEnumerable Skip(int count) { var (skipCount, takeCount) = Utils.Skip(Count, count); - return new ListValueEnumerable(source, offset + skipCount, takeCount); + return new ValueEnumerable(source, offset + skipCount, takeCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ListValueEnumerable Take(int count) + public ValueEnumerable Take(int count) => new(source, offset, Utils.Take(Count, count)); #endregion - - #region Projection - - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public SelectEnumerable> Select(Func selector) - // => ReadOnlyListExtensions.Select(source, selector, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public SelectEnumerable Select(TSelector selector = default) - // where TSelector : struct, IFunction - // => ReadOnlyListExtensions.Select(source, selector, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public SelectAtEnumerable> Select(Func selector) - // => ReadOnlyListExtensions.Select(source, selector, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public SelectAtEnumerable SelectAt(TSelector selector = default) - // where TSelector : struct, IFunction - // => ReadOnlyListExtensions.SelectAt(source, selector, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public SelectManyEnumerable> SelectMany(Func selector) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // => ReadOnlyListExtensions.SelectMany(source, selector, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public SelectManyEnumerable SelectMany(TSelector selector = default) - // where TSubEnumerable : IValueEnumerable - // where TSubEnumerator : struct, IEnumerator - // where TSelector : struct, IFunction - // => ReadOnlyListExtensions.SelectMany(source, selector, offset, Count); - - #endregion - - #region Quantifier - - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool All(Func predicate) - // => ReadOnlyListExtensions.All(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool All(TPredicate predicate) - // where TPredicate : struct, IFunction - // => ReadOnlyListExtensions.All(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool All(Func predicate) - // => ReadOnlyListExtensions.All(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool AllAt(TPredicate predicate) - // where TPredicate : struct, IFunction - // => ReadOnlyListExtensions.AllAt(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool Any() - // => ReadOnlyListExtensions.Any(source, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool Any(Func predicate) - // => ReadOnlyListExtensions.Any(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool Any(TPredicate predicate) - // where TPredicate : struct, IFunction - // => ReadOnlyListExtensions.Any(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool Any(Func predicate) - // => ReadOnlyListExtensions.Any(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool AnyAt(TPredicate predicate) - // where TPredicate : struct, IFunction - // => ReadOnlyListExtensions.AnyAt(source, predicate, offset, Count); - // - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public bool Contains(TSource value, IEqualityComparer? comparer) - // => ReadOnlyListExtensions.Contains(source, value, comparer, offset, Count); - - #endregion - - #region Set - - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public DistinctEnumerable Distinct(IEqualityComparer? comparer = default) - // => ReadOnlyListExtensions.Distinct(source, comparer, offset, Count); - - #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in ListValueEnumerable source) + public static int Count(this in ValueEnumerable source) + where TList : IReadOnlyList => source.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ListValueEnumerable source) - => source.Sum, int, int>(source.offset, source.Count); + public static int Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ListValueEnumerable source) - => source.Sum, int?, int>(source.offset, source.Count); + public static int Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ListValueEnumerable source) - => source.Sum, long, long>(source.offset, source.Count); + public static long Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ListValueEnumerable source) - => source.Sum, long?, long>(source.offset, source.Count); + public static long Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ListValueEnumerable source) - => source.Sum, float, int>(source.offset, source.Count); + public static float Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ListValueEnumerable source) - => source.Sum, float?, float>(source.offset, source.Count); + public static float Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ListValueEnumerable source) - => source.Sum, double, double>(source.offset, source.Count); + public static double Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ListValueEnumerable source) - => source.Sum, double?, double>(source.offset, source.Count); + public static double Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ListValueEnumerable source) - => source.Sum, decimal, decimal>(source.offset, source.Count); + public static decimal Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ListValueEnumerable source) - => source.Sum, decimal?, decimal>(source.offset, source.Count); + public static decimal Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => source.source.Sum(source.offset, source.Count); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index a33b43fda..00e0c5fa3 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -18,7 +18,7 @@ public static MemoryValueEnumerable AsValueEnumerable(this Rea [GeneratorIgnore] [StructLayout(LayoutKind.Auto)] - public readonly partial struct MemoryValueEnumerable + public readonly struct MemoryValueEnumerable : IValueReadOnlyList.DisposableEnumerator> , IList { @@ -168,12 +168,12 @@ public Dictionary ToDictionary(Func keySelec public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => source.Span.ToDictionary(keySelector, comparer); + => source.Span.ToDictionary(keySelector, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) where TKey : notnull - => source.Span.ToDictionary(keySelector, elementSelector, comparer); + => source.Span.ToDictionary(keySelector, elementSelector, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index 9e04b1678..5c2b97bd2 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -74,12 +74,12 @@ public Dictionary ToDictionary(Func keySelec public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => source.ToDictionary(keySelector, comparer); + => source.ToDictionary(keySelector, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) where TKey : notnull - => source.ToDictionary(keySelector, elementSelector, comparer); + => source.ToDictionary(keySelector, elementSelector, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs index c9f85c2c7..55f19de69 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs @@ -1,38 +1,14 @@ -using System.Collections.Generic; using System.Collections.Immutable; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; namespace NetFabric.Hyperlinq { public static class ImmutableArrayExtensions { - // ImmutableArray implements IReadOnlyList - // No need for bindings -/* - // ImmutableArray implements IReadOnlyCollection and has two enumerators: - // One that is a value-type and doesn't implement interfaces. - // Another that is a reference-type and implements IEnumerator. + // ImmutableArray is a value-type that implements IReadOnlyList [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, ValueEnumerator, ImmutableArray.Enumerator, TSource, GetEnumerator, GetEnumerator2> AsValueEnumerable(this ImmutableArray source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, ValueEnumerator, ImmutableArray.Enumerator, TSource, GetEnumerator, GetEnumerator2>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ValueEnumerator> - { - public ValueEnumerator Invoke(ImmutableArray source) - => new(((IEnumerable)source).GetEnumerator()); - } - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator2 - : IFunction, ImmutableArray.Enumerator> - { - public ImmutableArray.Enumerator Invoke(ImmutableArray source) - => source.GetEnumerator(); - } -*/ + public static ReadOnlyListExtensions.ValueEnumerable, TSource> AsValueEnumerable(this ImmutableArray source) + => source.AsValueEnumerable, TSource>(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.cs index f8a02593d..ddbbacf56 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq { public static class ImmutableDictionaryExtensions { - // ImmutableDictionary implements IReadOnlyCollection> and has a value-type enumerator that implements IEnumerator + // ImmutableDictionary is reference-type that implements IReadOnlyCollection> and has a value-type enumerator that implements IEnumerator [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableDictionary.Enumerator, ImmutableDictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableDictionary source) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.cs index fe24f214f..c3f1cdd7c 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq { public static class ImmutableHashSetExtensions { - // ImmutableHashSet implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + // ImmutableHashSet is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableHashSet.Enumerator, ImmutableHashSet.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableHashSet source) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.cs index 186dad50d..e60a32bd5 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq { public static class ImmutableListExtensions { - // ImmutableList implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + // ImmutableList is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableList.Enumerator, ImmutableList.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableList source) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.cs index d17458b2a..569daa154 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq { public static class ImmutableQueueExtensions { - // ImmutableQueue implements IEnumerable and has two enumerators: + // ImmutableQueue is reference-type that implements IEnumerable and has two enumerators: // One that is a value-type and doesn't implement interfaces. // Another that is a reference-type and implements IEnumerator. diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.cs index dbbeacda5..0d94acc82 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq { public static class ImmutableSortedDictionaryExtensions { - // ImmutableSortedDictionary implements IReadOnlyCollection> and has a value-type enumerator that implements IEnumerator + // ImmutableSortedDictionary is reference-type that implements IReadOnlyCollection> and has a value-type enumerator that implements IEnumerator [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableSortedDictionary.Enumerator, ImmutableSortedDictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableSortedDictionary source) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.cs index 77242d89a..95de76a42 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq { public static class ImmutableStackExtensions { - // ImmutableStack implements IEnumerable and has two enumerators: + // ImmutableStack is reference-type that implements IEnumerable and has two enumerators: // One that is a value-type and doesn't implement interfaces. // Another that is a reference-type and implements IEnumerator. diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index 0ffe8c2a9..05a73aaa6 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -1,6 +1,5 @@ using System; using System.Buffers; -using System.Diagnostics; using System.Numerics; using System.Runtime.CompilerServices; @@ -157,7 +156,7 @@ static IMemoryOwner ToArrayVector BuildArray(ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector, MemoryPool pool) { var result = pool.RentSliced(source.Length); - CopyVector(source, result.Memory.Span, vectorSelector, selector); + CopyVector(source, result.Memory.Span, vectorSelector, selector); return result; } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index 921c895cf..eddfe1768 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -1,8 +1,5 @@ -using System; -using System.Buffers; +using System.Buffers; using System.Collections.Generic; -using System.Diagnostics; -using System.Numerics; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index afd1dfcd3..1efd93618 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -1,7 +1,6 @@ using System; using System.Buffers; using System.Collections.Generic; -using System.Diagnostics; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs index 4052f1c3c..fdf164f95 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs @@ -1,5 +1,4 @@ -using System; -using System.Buffers; +using System.Buffers; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Threading; diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlyList.cs index 8266427bb..2a61574d5 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlyList.cs @@ -108,7 +108,7 @@ static Dictionary ToDictionary ToDictionary(this TList source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) where TList : struct, IReadOnlyList where TKey : notnull - => source.ToDictionary(keySelector, elementSelector, comparer, 0, source.Count); + => source.ToDictionary(keySelector, elementSelector, comparer, 0, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] static Dictionary ToDictionary(this TList source, Func keySelector, Func elementSelector, IEqualityComparer? comparer, int offset, int count) diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlyList.cs index 4fe06f879..501bdaf6c 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlyList.cs @@ -1,5 +1,3 @@ -using System; -using System.Buffers; using System.Collections.Generic; using System.Runtime.CompilerServices; // ReSharper disable HeapView.ObjectAllocation.Evident diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs index 57f85e4a6..7a1163ffb 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs @@ -1,5 +1,4 @@ using System; -using System.Buffers; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs index 07f51b1b4..95da0dea1 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs @@ -1,7 +1,4 @@ -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Numerics; +using System.Collections.Generic; using System.Runtime.CompilerServices; // ReSharper disable HeapView.ObjectAllocation.Evident diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs index d8ef06390..ee436a8be 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices.ComTypes; + // ReSharper disable HeapView.ObjectAllocation.Evident namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs index 1f6d9b73e..9ec3fa66d 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs @@ -1,5 +1,4 @@ -using System.Buffers; -using System.Collections.Generic; +using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs index 793f50ca6..a308fae61 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs index 4e57e37c3..3da1b3d3f 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs index 16ad1c4a3..530aa2181 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs index 4d09c68fa..0e0792986 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs b/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs index c6684cf86..e5d220577 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs index ba8677014..255f31e50 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs index d5119b401..e97e96e42 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs @@ -1,6 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs b/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs index cd2d44e63..d5324063b 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs index 9ae09241a..33acafd38 100644 --- a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Text; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index 14994feca..9be1537d7 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -209,7 +209,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index cdf313e02..07578d5b2 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -317,7 +317,7 @@ public ValueTask> ToListAsync(CancellationToken cancellationToken [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(Func> keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull - => ToDictionaryAsync>(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); + => ToDictionaryAsync(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs index 9d2e95454..27253530d 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs @@ -208,7 +208,7 @@ public WhereEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -253,7 +253,7 @@ public TSource[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(predicate, offset, count, memoryPool); + => source.ToArray(predicate, offset, count, memoryPool); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() @@ -262,7 +262,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index ce7676d54..9bc2af7eb 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -155,7 +155,7 @@ public MemoryWhereEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public MemoryWhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -201,7 +201,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index c7258c98c..7f6319e36 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -101,7 +101,7 @@ public SpanWhereEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SpanWhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -147,13 +147,13 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => source.ToDictionary(keySelector, comparer, predicate); + => source.ToDictionary(keySelector, comparer, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index da4c84f07..9a4161b2a 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -159,7 +159,7 @@ public WhereEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -213,7 +213,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index 1839a17c6..c709b2b5c 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -159,7 +159,7 @@ public WhereEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -176,7 +176,7 @@ public WhereSelectEnumerable Select(TSelector selector = default) where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.WhereSelect(source, predicate, selector); + => WhereSelect(source, predicate, selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index 89d3cdd11..a0b787703 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -162,7 +162,7 @@ public ArraySegmentWhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ArraySegmentWhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -177,11 +177,11 @@ public ArraySegmentWhereAtEnumerable ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAtAt(index, predicate); + => ((ReadOnlySpan)source.AsSpan()).ElementAtAt(index, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).FirstAt(predicate); + => ((ReadOnlySpan)source.AsSpan()).FirstAt(predicate); #pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -207,7 +207,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index a05c9756d..997dc074c 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -310,7 +310,7 @@ public ValueTask> ToListAsync(CancellationToken cancellationToken [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(Func> keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull - => ToDictionaryAsync>(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); + => ToDictionaryAsync(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs index e7ea30d9c..a1488e499 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs @@ -50,7 +50,7 @@ internal WhereAtEnumerable(in TList source, TPredicate predicate, int offset, in => (this.source, this.offset, this.count, this.predicate) = (source, offset, count, predicate); public readonly Enumerator GetEnumerator() - => new Enumerator(in this); + => new(in this); readonly DisposableEnumerator IValueEnumerable.GetEnumerator() => new(in this); readonly IEnumerator IEnumerable.GetEnumerator() @@ -211,7 +211,7 @@ public WhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -247,7 +247,7 @@ public TSource[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArrayAt(predicate, offset, count, memoryPool); + => source.ToArrayAt(predicate, offset, count, memoryPool); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() @@ -256,7 +256,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionaryAt>(new FunctionWrapper(keySelector), comparer); + => ToDictionaryAt(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionaryAt(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index 63d96d236..72cb4e50f 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -155,7 +155,7 @@ public MemoryWhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public MemoryWhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -192,7 +192,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionaryAt>(new FunctionWrapper(keySelector), comparer); + => ToDictionaryAt(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionaryAt(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index 49bf641b3..65997a6c8 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -101,7 +101,7 @@ public SpanWhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SpanWhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -138,13 +138,13 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => source.ToDictionaryAt(keySelector, comparer, predicate); + => source.ToDictionaryAt(keySelector, comparer, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index 3e1385a21..8e2d697e1 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -165,7 +165,7 @@ public WhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -210,7 +210,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionaryAt>(new FunctionWrapper(keySelector), comparer); + => ToDictionaryAt(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionaryAt(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index ebbb57525..294ecdda6 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -101,7 +101,7 @@ public void Dispose() [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() - => ValueReadOnlyCollectionExtensions.CountAt(source, predicate); + => CountAt(source, predicate); #endregion #region Quantifier @@ -164,7 +164,7 @@ public WhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt>(new FunctionWrapper(predicate)); + => WhereAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -179,16 +179,16 @@ public WhereAtEnumerable ElementAt(int index) - => ValueReadOnlyCollectionExtensions.ElementAtAt(source, index, predicate); + => ElementAtAt(source, index, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ValueReadOnlyCollectionExtensions.FirstAt(source, predicate); + => FirstAt(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() #pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() - => ValueReadOnlyCollectionExtensions.SingleAt(source, predicate); + => SingleAt(source, predicate); #pragma warning restore HLQ005 // Avoid Single() and SingleOrDefault() #endregion @@ -196,15 +196,15 @@ public Option Single() [MethodImpl(MethodImplOptions.AggressiveInlining)] public TSource[] ToArray() - => ValueReadOnlyCollectionExtensions.ToArrayAt(source, predicate); + => ToArrayAt(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => ValueReadOnlyCollectionExtensions.ToArrayAt(source, predicate, memoryPool); + => ToArrayAt(source, predicate, memoryPool); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ValueReadOnlyCollectionExtensions.ToListAt(source, predicate); + => ToListAt(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) @@ -215,7 +215,7 @@ public Dictionary ToDictionary(Func keySelec public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.ToDictionaryAt(source, keySelector, comparer, predicate); + => ToDictionaryAt(source, keySelector, comparer, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) @@ -227,7 +227,7 @@ public Dictionary ToDictionary where TElementSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.ToDictionaryAt(source, keySelector, elementSelector, comparer, predicate); + => ToDictionaryAt(source, keySelector, elementSelector, comparer, predicate); #endregion } diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index 413676c12..b17948e5c 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -64,13 +64,13 @@ internal Enumerator(in ArraySegmentWhereSelectEnumerable selector.Invoke(source![index]); - readonly TResult IEnumerator.Current + TResult IEnumerator.Current => selector.Invoke(source![index]); - readonly object? IEnumerator.Current + object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(source![index])!; + => selector.Invoke(source![index]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() @@ -111,7 +111,7 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate) where TPredicate2 : struct, IFunction - => this.All, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.All, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -120,7 +120,7 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate) where TPredicate2 : struct, IFunction - => this.AllAt, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.AllAt, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() @@ -133,7 +133,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate) where TPredicate2 : struct, IFunction - => this.Any, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.Any, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -142,28 +142,28 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate) where TPredicate2 : struct, IFunction - => this.AnyAt, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.AnyAt, Enumerator, TResult, TPredicate2>(predicate); #endregion #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, ArraySegmentWhereSelectEnumerable.Enumerator, TResult>(predicate); + public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) + public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => this.Where, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.Where, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, ArraySegmentWhereSelectEnumerable.Enumerator, TResult>(predicate); + public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) + public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => this.WhereAt, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.WhereAt, Enumerator, TResult, TPredicate2>(predicate); #endregion #region Projection @@ -178,17 +178,17 @@ public ArraySegmentWhereSelectEnumerable source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, ArraySegmentWhereSelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index 41af52210..82bd919bd 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -243,7 +243,7 @@ public ValueTask AllAsync(Func [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AllAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction - => this.AllAsync, WhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate, cancellationToken); + => this.AllAsync, Enumerator, TResult, TPredicate2>(predicate, cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AllAsync(Func> predicate, CancellationToken cancellationToken = default) @@ -252,7 +252,7 @@ public ValueTask AllAsync(Func AllAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction - => this.AllAtAsync, WhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate, cancellationToken); + => this.AllAtAsync, Enumerator, TResult, TPredicate2>(predicate, cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AnyAsync(CancellationToken cancellationToken = default) @@ -265,7 +265,7 @@ public ValueTask AnyAsync(Func [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AnyAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction - => this.AnyAsync, WhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate, cancellationToken); + => this.AnyAsync, Enumerator, TResult, TPredicate2>(predicate, cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AnyAsync(Func> predicate, CancellationToken cancellationToken = default) @@ -274,28 +274,28 @@ public ValueTask AnyAsync(Func AnyAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction - => this.AnyAtAsync, WhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate, cancellationToken); + => this.AnyAtAsync, Enumerator, TResult, TPredicate2>(predicate, cancellationToken); #endregion #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereEnumerable, WhereSelectEnumerable.Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) - => this.Where, WhereSelectEnumerable.Enumerator, TResult>(predicate); + public readonly WhereEnumerable, Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) + => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereEnumerable, WhereSelectEnumerable.Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) + public readonly WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IAsyncFunction - => this.Where, WhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.Where, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereAtEnumerable, WhereSelectEnumerable.Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) - => this.Where, WhereSelectEnumerable.Enumerator, TResult>(predicate); + public readonly WhereAtEnumerable, Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) + => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereAtEnumerable, WhereSelectEnumerable.Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) + public readonly WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IAsyncFunction - => this.WhereAt, WhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.WhereAt, Enumerator, TResult, TPredicate2>(predicate); #endregion #region Projection @@ -344,7 +344,7 @@ public ValueTask> ToListAsync(CancellationToken cancellationToken [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(Func> keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull - => ToDictionaryAsync>(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); + => ToDictionaryAsync(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs index 974d81b95..21e819613 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs @@ -79,7 +79,7 @@ internal Enumerator(in WhereSelectEnumerable selector.Invoke(source[index]); @@ -116,7 +116,7 @@ internal DisposableEnumerator(in WhereSelectEnumerable selector.Invoke(source[index]); @@ -202,22 +202,22 @@ public bool AnyAt(TPredicate2 predicate) #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, WhereSelectEnumerable.DisposableEnumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, WhereSelectEnumerable.DisposableEnumerator, TResult>(predicate); + public readonly ValueEnumerableExtensions.WhereEnumerable, DisposableEnumerator, TResult, FunctionWrapper> Where(Func predicate) + => this.Where, DisposableEnumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, WhereSelectEnumerable.DisposableEnumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) + public readonly ValueEnumerableExtensions.WhereEnumerable, DisposableEnumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => this.Where, WhereSelectEnumerable.DisposableEnumerator, TResult, TPredicate2>(predicate); + => this.Where, DisposableEnumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, WhereSelectEnumerable.DisposableEnumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, WhereSelectEnumerable.DisposableEnumerator, TResult>(predicate); + public readonly ValueEnumerableExtensions.WhereAtEnumerable, DisposableEnumerator, TResult, FunctionWrapper> Where(Func predicate) + => this.Where, DisposableEnumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, WhereSelectEnumerable.DisposableEnumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) + public readonly ValueEnumerableExtensions.WhereAtEnumerable, DisposableEnumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => this.WhereAt, WhereSelectEnumerable.DisposableEnumerator, TResult, TPredicate2>(predicate); + => this.WhereAt, DisposableEnumerator, TResult, TPredicate2>(predicate); #endregion #region Projection @@ -232,17 +232,17 @@ public WhereSelectEnumerable source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector), offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, WhereSelectEnumerable.DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, WhereSelectEnumerable.DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, WhereSelectEnumerable.DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, WhereSelectEnumerable.DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element @@ -277,7 +277,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index e0bf9c4aa..671fe619c 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -64,14 +64,14 @@ internal Enumerator(in MemoryWhereSelectEnumerable selector.Invoke(source.Span[index]); } - readonly TResult IEnumerator.Current + TResult IEnumerator.Current => selector.Invoke(source.Span[index]); - readonly object? IEnumerator.Current + object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source.Span[index]); @@ -115,7 +115,7 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate) where TPredicate2 : struct, IFunction - => this.All, MemoryWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.All, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -124,7 +124,7 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate) where TPredicate2 : struct, IFunction - => this.AllAt, MemoryWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.AllAt, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() @@ -137,7 +137,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate) where TPredicate2 : struct, IFunction - => this.Any, MemoryWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.Any, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -146,28 +146,28 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate) where TPredicate2 : struct, IFunction - => this.AnyAt, MemoryWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.AnyAt, Enumerator, TResult, TPredicate2>(predicate); #endregion #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, MemoryWhereSelectEnumerable.Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, MemoryWhereSelectEnumerable.Enumerator, TResult>(predicate); + public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, MemoryWhereSelectEnumerable.Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) + public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => this.Where, MemoryWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.Where, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, MemoryWhereSelectEnumerable.Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, MemoryWhereSelectEnumerable.Enumerator, TResult>(predicate); + public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, MemoryWhereSelectEnumerable.Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) + public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => this.WhereAt, MemoryWhereSelectEnumerable.Enumerator, TResult, TPredicate2>(predicate); + => this.WhereAt, Enumerator, TResult, TPredicate2>(predicate); #endregion #region Projection @@ -182,17 +182,17 @@ public MemoryWhereSelectEnumerable source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, MemoryWhereSelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, MemoryWhereSelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, MemoryWhereSelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, MemoryWhereSelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element @@ -227,7 +227,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index bbcb0826c..09dd074f7 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -1,7 +1,6 @@ using System; using System.Buffers; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -95,7 +94,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(predicate, selector, memoryPool); + => source.ToArray(predicate, selector, memoryPool); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() @@ -104,7 +103,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index 5cf9f2afc..3bc24ed8e 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -231,7 +231,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index 285e0d6b5..ca1f5d712 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -183,7 +183,7 @@ public WhereSelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.WhereSelect>(source, predicate, new SelectorSelectorCombination(this.selector, selector)); + => WhereSelect>(source, predicate, new SelectorSelectorCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs index 9eae8a6c6..abc5e18f4 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs index 2149a5031..9aedd0d55 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs @@ -115,7 +115,7 @@ public ValueTask MoveNextAsync() } public readonly ValueTask DisposeAsync() - => new ValueTask(); + => new(); } #pragma warning disable IDE0060 // Remove unused parameter @@ -142,8 +142,8 @@ public RangeEnumerable Take(int count) => Range(start, Utils.Take(this.count, count)); #pragma warning disable IDE0060 // Remove unused parameter - public ValueTask ContainsAsync(int value, CancellationToken cancellationToken = default) - => new ValueTask(value >= start && value < end); + public ValueTask ContainsAsync(int value, CancellationToken cancellationToken) + => new(value >= start && value < end); #pragma warning restore IDE0060 // Remove unused parameter public ValueTask ContainsAsync(int value, IEqualityComparer? comparer, CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs index 018d73662..8b946828b 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; @@ -130,7 +129,7 @@ public ValueTask> ToListAsync() [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionaryAsync>(new FunctionWrapper(keySelector), comparer); + => ToDictionaryAsync(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs index 68441f2ed..a211ed2b3 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs @@ -11,7 +11,7 @@ public static partial class ValueEnumerable public static CreateValueEnumerable Create(Func getEnumerator) where TEnumerator : struct, IEnumerator - => new CreateValueEnumerable(getEnumerator); + => new(getEnumerator); [StructLayout(LayoutKind.Auto)] public readonly partial struct CreateValueEnumerable diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs index 54d00f210..47528d3f1 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs @@ -99,7 +99,7 @@ readonly TSource IEnumerator.Current => default!; readonly object? IEnumerator.Current - => default!; + => default; public readonly bool MoveNext() => default; diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs index a47b59766..8d62cea06 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs @@ -2,7 +2,6 @@ using System.Buffers; using System.Collections; using System.Collections.Generic; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Numerics; using System.Runtime.CompilerServices; @@ -198,7 +197,7 @@ public bool Contains(int value, IEqualityComparer? comparer) [MethodImpl(MethodImplOptions.AggressiveInlining)] public RangeSelectVectorEnumerable, Vector>, FunctionWrapper> SelectVector(Func, Vector> vectorSelector, Func selector) where TResult : struct - => ValueEnumerable.SelectVector, Vector>, FunctionWrapper>(start, Count, vectorSelector, selector); + => ValueEnumerable.SelectVector(start, Count, vectorSelector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public RangeSelectVectorEnumerable SelectVector(TSelector selector = default) diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs index 6ecd443e8..842a5fb42 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs @@ -50,7 +50,7 @@ TSource IList.this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly Enumerator GetEnumerator() - => new Enumerator(in this); + => new(in this); readonly DisposableEnumerator IValueEnumerable.GetEnumerator() => new(in this); readonly IEnumerator IEnumerable.GetEnumerator() @@ -209,7 +209,7 @@ public List ToList() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull - => ToDictionary>(new FunctionWrapper(keySelector), comparer); + => ToDictionary(new FunctionWrapper(keySelector), comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 83a8878a8..208efae2d 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -5,7 +5,7 @@ NetFabric.Hyperlinq NetFabric.Hyperlinq High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays, Memory and Span. - 3.0.0-beta41 + 3.0.0-beta42 Icon.png LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance diff --git a/NetFabric.Hyperlinq/Option/NoneOption.cs b/NetFabric.Hyperlinq/Option/NoneOption.cs index 1e43ad1a9..8998dc5b8 100644 --- a/NetFabric.Hyperlinq/Option/NoneOption.cs +++ b/NetFabric.Hyperlinq/Option/NoneOption.cs @@ -1,5 +1,3 @@ -using System; - namespace NetFabric.Hyperlinq { public readonly struct NoneOption diff --git a/NetFabric.Hyperlinq/Option/Option.cs b/NetFabric.Hyperlinq/Option/Option.cs index 560475064..fac41907c 100644 --- a/NetFabric.Hyperlinq/Option/Option.cs +++ b/NetFabric.Hyperlinq/Option/Option.cs @@ -206,7 +206,7 @@ public readonly TValue[] ToArray() => IsSome switch { // ReSharper disable once HeapView.ObjectAllocation.Evident - true => new TValue[] { Value }, + true => new[] { Value }, _ => Array.Empty() }; diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs index ba45e761b..2fd69b45b 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs @@ -91,7 +91,7 @@ public ValueTask MoveNextAsync() return builder.Task; } - public readonly ValueTask DisposeAsync() + public ValueTask DisposeAsync() => enumerator.DisposeAsync(); void IAsyncStateMachine.MoveNext() diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs index 356d662c3..6c933d9aa 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs @@ -1,4 +1,3 @@ -using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -62,7 +61,7 @@ readonly TSource IEnumerator.Current => enumerator.Current; readonly object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation - => enumerator.Current!; + => enumerator.Current; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() @@ -82,7 +81,7 @@ public bool MoveNext() public readonly void Reset() => Throw.NotSupportedException(); - public readonly void Dispose() + public void Dispose() => enumerator.Dispose(); } diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs index b780840f0..7ef457d0c 100644 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs @@ -92,7 +92,7 @@ public ValueTask MoveNextAsync() return builder.Task; } - public readonly ValueTask DisposeAsync() + public ValueTask DisposeAsync() => enumerator.DisposeAsync(); void IAsyncStateMachine.MoveNext() diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.Memory.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.Memory.cs deleted file mode 100644 index 9d8e0ad63..000000000 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.Memory.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static Memory Take(this Memory source, int count) - => source.Slice(0, Utils.Take(source.Length, count)); - } -} diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 25614e0bd..fd1e8c2ae 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -115,14 +115,14 @@ internal Enumerator(in ArraySegmentSelectEnumerable end = index + enumerable.source.Count; } - public readonly TResult Current + public TResult Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(source![index]); } - readonly TResult IEnumerator.Current + TResult IEnumerator.Current => selector.Invoke(source![index]); - readonly object? IEnumerator.Current + object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source![index]); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs index 17549b070..738b45c69 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs @@ -105,7 +105,7 @@ public bool Contains(TResult item) => source.Contains(item, default, selector, offset, Count); public int IndexOf(TResult item) - => ReadOnlyListExtensions.IndexOf(source, item, selector, offset, Count); + => ReadOnlyListExtensions.IndexOf(source, item, selector, offset, Count); [ExcludeFromCodeCoverage] void ICollection.Add(TResult item) @@ -177,7 +177,7 @@ TResult IEnumerator.Current => selector.Invoke(source[index]); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(source[index])!; + => selector.Invoke(source[index]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index 2585360f7..76fed7f4f 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -91,7 +91,7 @@ public bool Contains(TResult item) bool ICollection.Remove(TResult item) => Throw.NotSupportedException(); int IList.IndexOf(TResult item) - => ArrayExtensions.IndexOf(source.Span, item, selector); + => ArrayExtensions.IndexOf(source.Span, item, selector); void IList.Insert(int index, TResult item) => Throw.NotSupportedException(); void IList.RemoveAt(int index) @@ -112,14 +112,14 @@ internal Enumerator(in MemorySelectEnumerable enume index = -1; } - public readonly TResult Current + public TResult Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(source.Span[index]); } - readonly TResult IEnumerator.Current + TResult IEnumerator.Current => selector.Invoke(source.Span[index]); - readonly object? IEnumerator.Current + object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source.Span[index]); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index 761782838..b5c18276c 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -1,7 +1,6 @@ using System; using System.Buffers; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index 0368774ab..1792f52a2 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -63,16 +63,16 @@ internal Enumerator(in SelectEnumerable selector.Invoke(enumerator.Current); } - readonly TResult IEnumerator.Current - => selector.Invoke(enumerator.Current)!; - readonly object? IEnumerator.Current + TResult IEnumerator.Current + => selector.Invoke(enumerator.Current); + object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(enumerator.Current)!; + => selector.Invoke(enumerator.Current); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() @@ -124,17 +124,17 @@ public SelectAtEnumerable source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, SelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, SelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, SelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, SelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index d2812915e..8f1905fca 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -160,17 +160,17 @@ public SelectAtEnumerable ValueReadOnlyCollectionExtensions.SelectAt>(source, new SelectorSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, SelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, SelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, SelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, SelectEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 1cc4541f3..9d1b553dc 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -87,7 +87,7 @@ public bool Contains(TResult item) bool ICollection.Remove(TResult item) => Throw.NotSupportedException(); int IList.IndexOf(TResult item) - => ArrayExtensions.IndexOfAt(source, item, selector); + => IndexOfAt(source, item, selector); void IList.Insert(int index, TResult item) => Throw.NotSupportedException(); @@ -113,11 +113,11 @@ internal Enumerator(in ArraySegmentSelectAtEnumerable selector.Invoke(source![index + offset], index); - readonly TResult IEnumerator.Current - => selector.Invoke(source![index + offset], index)!; - readonly object? IEnumerator.Current + TResult IEnumerator.Current + => selector.Invoke(source![index + offset], index); + object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source![index + offset], index); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs index 03338580c..cdc96ffeb 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs @@ -120,7 +120,7 @@ public bool Contains(TResult item) => source.ContainsAt(item, default, selector, offset, Count); public int IndexOf(TResult item) - => ReadOnlyListExtensions.IndexOfAt(source, item, selector, offset, Count); + => IndexOfAt(source, item, selector, offset, Count); [ExcludeFromCodeCoverage] void ICollection.Add(TResult item) diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index dd0f512eb..0fc489393 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -46,7 +46,7 @@ public TResult this[int index] get => selector.Invoke(source.Span[index], index); } TResult IReadOnlyList.this[int index] - => this[index]!; + => this[index]; TResult IList.this[int index] { get => this[index]; @@ -74,7 +74,7 @@ void ICollection.CopyTo(TResult[] array, int arrayAt) { var span = source.Span; for (var index = 0; index < span.Length; index++) - array[index + arrayAt] = selector.Invoke(span[index], index)!; + array[index + arrayAt] = selector.Invoke(span[index], index); } void ICollection.Add(TResult item) => Throw.NotSupportedException(); @@ -85,7 +85,7 @@ public bool Contains(TResult item) bool ICollection.Remove(TResult item) => Throw.NotSupportedException(); int IList.IndexOf(TResult item) - => ArrayExtensions.IndexOfAt(source.Span, item, selector); + => IndexOfAt(source.Span, item, selector); void IList.Insert(int index, TResult item) => Throw.NotSupportedException(); void IList.RemoveAt(int index) @@ -106,16 +106,16 @@ internal Enumerator(in MemorySelectAtEnumerable enu index = -1; } - public readonly TResult Current + public TResult Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(source.Span[index], index); } - readonly TResult IEnumerator.Current - => selector.Invoke(source.Span[index], index)!; - readonly object? IEnumerator.Current + TResult IEnumerator.Current + => selector.Invoke(source.Span[index], index); + object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(source.Span[index], index)!; + => selector.Invoke(source.Span[index], index); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index 078721d31..61acaa5e4 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -1,7 +1,6 @@ using System; using System.Buffers; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index 7cd76ec37..5a113de9d 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -134,17 +134,17 @@ public SelectAtEnumerable source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, SelectAtEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, SelectAtEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, SelectAtEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, SelectAtEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index b182a7a51..3c1eedf76 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -67,7 +67,7 @@ public void CopyTo(Span span) { using var enumerator = source.GetEnumerator(); for (var index = 0; enumerator.MoveNext(); index++) - span[index] = selector.Invoke(enumerator.Current, index)!; + span[index] = selector.Invoke(enumerator.Current, index); } } } @@ -169,17 +169,17 @@ public SelectAtEnumerable ValueReadOnlyCollectionExtensions.SelectAt>(source, new SelectorAtSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, SelectAtEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, SelectAtEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, SelectAtEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, SelectAtEnumerable.Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs index feed02386..102ec24a1 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs @@ -2,7 +2,6 @@ using System.Buffers; using System.Collections; using System.Collections.Generic; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Numerics; using System.Runtime.CompilerServices; @@ -14,9 +13,7 @@ public static partial class ValueEnumerable { [MethodImpl(MethodImplOptions.AggressiveInlining)] - static RangeSelectVectorEnumerable, Vector>, FunctionWrapper> SelectVector(int start, int count, Func, Vector> vectorSelector, Func selector) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction + static RangeSelectVectorEnumerable, Vector>, FunctionWrapper> SelectVector(int start, int count, Func, Vector> vectorSelector, Func selector) where TResult : struct => SelectVector, Vector>, FunctionWrapper>(start, count, new FunctionWrapper, Vector>(vectorSelector), new FunctionWrapper(selector)); @@ -192,7 +189,7 @@ internal Enumerator(in RangeSelectVectorEnumerable selector.Invoke(value); @@ -218,15 +215,15 @@ internal DisposableEnumerator(in RangeSelectVectorEnumerable selector.Invoke(value); } - readonly TResult IEnumerator.Current + TResult IEnumerator.Current => selector.Invoke(value); - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation + object IEnumerator.Current + // ReSharper disable once HeapView.BoxingAllocation => selector.Invoke(value); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -272,7 +269,7 @@ public bool Contains(TResult value, IEqualityComparer? comparer) public TResult[] ToArray() { var result = Utils.AllocateUninitializedArray(count); - ArrayExtensions.CopyRange(start, count, result.AsSpan(), vectorSelector, selector); + ArrayExtensions.CopyRange(start, count, result.AsSpan(), vectorSelector, selector); return result; } @@ -280,7 +277,7 @@ public TResult[] ToArray() public IMemoryOwner ToArray(MemoryPool pool) { var result = pool.RentSliced(count); - ArrayExtensions.CopyRange(start, count, result.Memory.Span, vectorSelector, selector); + ArrayExtensions.CopyRange(start, count, result.Memory.Span, vectorSelector, selector); return result; } diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs index 278ce9ae6..caafa4e6c 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs @@ -104,7 +104,6 @@ public bool MoveNext() } return true; - case EnumeratorState.Complete: default: return false; } @@ -162,7 +161,7 @@ public readonly ValueEnumerableExtensions.WhereAtEnumerable ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(System.Func predicate) + public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs index d3f4ea7fb..c11ab2a77 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs @@ -151,7 +151,7 @@ public bool Any() => this.Any, Enumerator, TResult>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) + public bool Any(Func predicate) => this.Any, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -160,7 +160,7 @@ public bool Any(TPredicate predicate = default) => this.Any, Enumerator, TResult, TPredicate>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) + public bool Any(Func predicate) => this.Any, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -181,7 +181,7 @@ public readonly ValueEnumerableExtensions.WhereAtEnumerable ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(System.Func predicate) + public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs index 0dee33578..f4164a3c8 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs @@ -160,7 +160,7 @@ public readonly ValueEnumerableExtensions.WhereAtEnumerable ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(System.Func predicate) + public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs index e5b7a6078..e5122506d 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs index 173ee4011..ad3bb0104 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs @@ -79,7 +79,7 @@ readonly TResult IEnumerator.Current => subEnumerator.Current; readonly object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation - => subEnumerator.Current!; + => subEnumerator.Current; public bool MoveNext() { @@ -121,107 +121,107 @@ public readonly void Reset() [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly int Count() - => this.Count, SelectManyEnumerable.Enumerator, TResult>(); + => this.Count, Enumerator, TResult>(); #endregion #region Quantifier [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() - => this.Any, SelectManyEnumerable.Enumerator, TResult>(); + => this.Any, Enumerator, TResult>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, SelectManyEnumerable.Enumerator, TResult>(predicate); + public bool Any(Func predicate) + => this.Any, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate predicate = default) where TPredicate : struct, IFunction - => this.Any, SelectManyEnumerable.Enumerator, TResult, TPredicate>(predicate); + => this.Any, Enumerator, TResult, TPredicate>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, SelectManyEnumerable.Enumerator, TResult>(predicate); + public bool Any(Func predicate) + => this.Any, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate predicate = default) where TPredicate : struct, IFunction - => this.AnyAt, SelectManyEnumerable.Enumerator, TResult, TPredicate>(predicate); + => this.AnyAt, Enumerator, TResult, TPredicate>(predicate); #endregion #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, SelectManyEnumerable.Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, SelectManyEnumerable.Enumerator, TResult>(this, predicate); + public readonly WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, SelectManyEnumerable.Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) + public readonly WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) where TPredicate : struct, IFunction - => ValueEnumerableExtensions.WhereAt, SelectManyEnumerable.Enumerator, TResult, TPredicate>(this, predicate); + => ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, SelectManyEnumerable.Enumerator, TResult, FunctionWrapper> Where(System.Func predicate) - => ValueEnumerableExtensions.Where, SelectManyEnumerable.Enumerator, TResult>(this, predicate); + public readonly WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, SelectManyEnumerable.Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) + public readonly WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, IFunction - => ValueEnumerableExtensions.Where, SelectManyEnumerable.Enumerator, TResult, TPredicate>(this, predicate); + => ValueEnumerableExtensions.Where, Enumerator, TResult, TPredicate>(this, predicate); #endregion #region Projection [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectEnumerable, SelectManyEnumerable.Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, SelectManyEnumerable.Enumerator, TResult, TResult2>(this, selector); + public readonly SelectEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectEnumerable, SelectManyEnumerable.Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) + public readonly SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction - => ValueEnumerableExtensions.Select, SelectManyEnumerable.Enumerator, TResult, TResult2, TSelector2>(this, selector); + => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2, TSelector2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectAtEnumerable, SelectManyEnumerable.Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, SelectManyEnumerable.Enumerator, TResult, TResult2>(this, selector); + public readonly SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectAtEnumerable, SelectManyEnumerable.Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) + public readonly SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction - => ValueEnumerableExtensions.SelectAt, SelectManyEnumerable.Enumerator, TResult, TResult2, TSelector2>(this, selector); + => ValueEnumerableExtensions.SelectAt, Enumerator, TResult, TResult2, TSelector2>(this, selector); #endregion #region Element [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option ElementAt(int index) - => this.ElementAt, SelectManyEnumerable.Enumerator, TResult>(index); + => this.ElementAt, Enumerator, TResult>(index); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => this.First, SelectManyEnumerable.Enumerator, TResult>(); + => this.First, Enumerator, TResult>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() - => this.Single, SelectManyEnumerable.Enumerator, TResult>(); + => this.Single, Enumerator, TResult>(); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.AsyncValueEnumerableWrapper, SelectManyEnumerable.Enumerator, TResult> AsAsyncValueEnumerable() - => ValueEnumerableExtensions.AsAsyncValueEnumerable, SelectManyEnumerable.Enumerator, TResult>(this); + public readonly AsyncValueEnumerableWrapper, Enumerator, TResult> AsAsyncValueEnumerable() + => ValueEnumerableExtensions.AsAsyncValueEnumerable, Enumerator, TResult>(this); #endregion #region Partitioning [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SkipEnumerable, SelectManyEnumerable.Enumerator, TResult> Skip(int count) - => ValueEnumerableExtensions.Skip, SelectManyEnumerable.Enumerator, TResult>(this, count); + public readonly SkipEnumerable, Enumerator, TResult> Skip(int count) + => ValueEnumerableExtensions.Skip, Enumerator, TResult>(this, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.TakeEnumerable, SelectManyEnumerable.Enumerator, TResult> Take(int count) - => ValueEnumerableExtensions.Take, SelectManyEnumerable.Enumerator, TResult>(this, count); + public readonly TakeEnumerable, Enumerator, TResult> Take(int count) + => ValueEnumerableExtensions.Take, Enumerator, TResult>(this, count); #endregion } diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs index 459d7f828..a8d28127d 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; +using System.Collections.Generic; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs index 514b88474..7d02cad93 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs @@ -1,8 +1,4 @@ -using System; using System.Collections.Generic; -using System.ComponentModel.Design; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs index 031c0bac2..60911f9ce 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs index f44787d7b..1c6c950c1 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs index 48f146f26..66122d65b 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; @@ -23,7 +22,7 @@ public static async ValueTask ContainsAsync ContainsAsync(this TEnumerable source, TSource value, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) + public static ValueTask ContainsAsync(this TEnumerable source, TSource value, IEqualityComparer? comparer, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator { diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs index 0a3747cd1..25c3724c7 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs @@ -99,7 +99,7 @@ public readonly int Count() [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Any() - => source is not 0; + => source.Count is not 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly TSource[] ToArray() diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs index 42fcf5d17..4d039a2b5 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -101,7 +101,7 @@ public readonly int Count() [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Any() - => source is not 0; + => source.Length is not 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly TSource[] ToArray() diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs index 2a6c2ec5e..ecbc2ed9f 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs @@ -1,4 +1,3 @@ -using System; using System.Buffers; using System.Collections; using System.Collections.Generic; diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index 4fe7a3bf4..74e1393e0 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -10,7 +10,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs index 5f520ef37..c6dac872d 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs @@ -7,7 +7,6 @@ using System; using System.Buffers; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; namespace NetFabric.Hyperlinq { @@ -57,10 +56,10 @@ public int Capacity /// public int Count { get; private set; } - /// - /// Gets or sets the item at a certain index in the array. - /// - /// The index into the array. + // /// + // /// Gets or sets the item at a certain index in the array. + // /// + // /// The index into the array. // public T this[int index] // { // get diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs index fc7ce037a..7ab715f02 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs @@ -34,7 +34,6 @@ struct LargeArrayBuilder /// /// Constructs a new builder. /// - /// Pass true. public LargeArrayBuilder(ArrayPool pool) : this(maxCapacity: int.MaxValue, pool: pool, arrayBuilderPool: ArrayPool.Shared) { diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs index 5369a6714..1c551c8e8 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs @@ -1,7 +1,5 @@ -using System; -using System.Buffers; +using System.Buffers; using System.Collections.Generic; -using System.Diagnostics; using System.Threading; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs index 0e3ab27c8..a1e598724 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs @@ -1,7 +1,5 @@ -using System; -using System.Buffers; +using System.Buffers; using System.Collections.Generic; -using System.Diagnostics; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs index bd9b009a5..565a2c716 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs @@ -1,6 +1,5 @@ using System; using System.Buffers; -using System.Diagnostics; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs index 137d701a3..aa28964d1 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs @@ -1,7 +1,5 @@ -using System; -using System.Buffers; +using System.Buffers; using System.Collections.Generic; -using System.Diagnostics; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs index 1deb76efa..a23dcd2de 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs @@ -1,5 +1,4 @@ -using System; -using System.Buffers; +using System.Buffers; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq/Utils/BooleanExtensions.cs b/NetFabric.Hyperlinq/Utils/BooleanExtensions.cs index 0841c41d9..22f201c86 100644 --- a/NetFabric.Hyperlinq/Utils/BooleanExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/BooleanExtensions.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Utils/GenericsOperator.cs b/NetFabric.Hyperlinq/Utils/GenericsOperator.cs index 98af3d29e..8821a3670 100644 --- a/NetFabric.Hyperlinq/Utils/GenericsOperator.cs +++ b/NetFabric.Hyperlinq/Utils/GenericsOperator.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs index d6f1ddb1e..f3004b831 100644 --- a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq @@ -7,11 +6,13 @@ namespace NetFabric.Hyperlinq static partial class ReadOnlyListExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOf(IReadOnlyList source, TSource item, int offset, int count) + public static int IndexOf(TList source, TSource item, int offset, int count) + where TList : IReadOnlyList { if (count is 0) return -1; + // ReSharper disable once HeapView.PossibleBoxingAllocation if (offset is 0 && count == source.Count && source is IList list) return list.IndexOf(item); @@ -40,7 +41,8 @@ public static int IndexOf(IReadOnlyList source, TSource item, } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOf(IReadOnlyList source, TResult item, TSelector selector, int offset, int count) + public static int IndexOf(TList source, TResult item, TSelector selector, int offset, int count) + where TList : IReadOnlyList where TSelector : struct, IFunction { if (count is 0) @@ -72,7 +74,8 @@ public static int IndexOf(IReadOnlyList so [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAt(IReadOnlyList source, TResult item, TSelector selector, int offset, int count) + public static int IndexOfAt(TList source, TResult item, TSelector selector, int offset, int count) + where TList : IReadOnlyList where TSelector : struct, IFunction { if (count is 0) diff --git a/NetFabric.Hyperlinq/Utils/Throw.cs b/NetFabric.Hyperlinq/Utils/Throw.cs index 082ef9f74..ad0f7901d 100644 --- a/NetFabric.Hyperlinq/Utils/Throw.cs +++ b/NetFabric.Hyperlinq/Utils/Throw.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Runtime.Versioning; namespace NetFabric.Hyperlinq { From 4ddac7680abc75055d2703ddcc626b16b1c091ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Thu, 4 Mar 2021 19:57:43 +0000 Subject: [PATCH 09/61] Optimize ImmutableArray<> by getting inner array (#341) --- .../Collections/Immutable/ImmutableArray.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs index 55f19de69..debe79407 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs @@ -1,14 +1,23 @@ +using System; using System.Collections.Immutable; +using System.Net.Http.Headers; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { public static class ImmutableArrayExtensions { - // ImmutableArray is a value-type that implements IReadOnlyList + // Get the inner array and return its IValueEnumerable<> wrapper. + // Do not use the available AsSpan() or AsMemory() because the enumerables for ReadOnlySpan<> do not + // implement IEnumerable<>, restricting its use, and the enumerables for ReadOnlyMemory<> are less efficient + // because they call .Span in each iteration. + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ArrayExtensions.ArraySegmentValueEnumerable AsValueEnumerable(this ImmutableArray source) + => source.GetArray().AsValueEnumerable(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyListExtensions.ValueEnumerable, TSource> AsValueEnumerable(this ImmutableArray source) - => source.AsValueEnumerable, TSource>(); + static TSource[] GetArray(this ImmutableArray source) + => Unsafe.As, TSource[]?>(ref source) ?? Array.Empty(); } -} \ No newline at end of file +} From 893396f169a035be7950f20680f46fe0b21370c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Thu, 4 Mar 2021 21:33:10 +0000 Subject: [PATCH 10/61] Improve coverage (#342) * Improve coverage * Fix build --- .../CountAsync.AsyncValueEnumerable.Tests.cs | 9 +- .../SumAsync.AsyncValueEnumerable.Tests.cs | 49 ++++++ ...ncValueEnumerable.AsyncEnumerable.Tests.cs | 14 +- ...ncValueEnumerable.ValueEnumerable.Tests.cs | 8 +- .../AsValueEnumerable.ArraySegment.cs | 147 ++++++++++++++++++ .../AsValueEnumerable.ReadOnlyList.Tests.cs | 116 +++++++++++--- .../AsValueEnumerable.ReadOnlyMemory.cs | 147 ++++++++++++++++++ .../AsValueEnumerable.ReadOnlySpan.cs | 132 ++++++++++++++++ .../Immutable/ImmutableArray.Tests.cs | 6 +- ...ToArrayAsync.AsyncValueEnumerable.Tests.cs | 36 +++-- .../ToListAsync.AsyncValueEnumerable.Tests.cs | 18 ++- ...ementAtAsync.AsyncValueEnumerable.Tests.cs | 88 ++++++----- .../FirstAsync.AsyncValueEnumerable.Tests.cs | 70 +++++---- .../SingleAsync.AsyncValueEnumerable.Tests.cs | 92 ++++++----- .../Where/Where.AsyncValueEnumerable.Tests.cs | 3 +- .../WhereAt.AsyncValueEnumerable.Tests.cs | 3 +- .../WhereSelect.AsyncValueEnumerable.Tests.cs | 3 +- .../AsyncValueEnumerable/Range.Tests.cs | 33 ++-- .../AsyncValueEnumerable/Repeat.Tests.cs | 20 ++- .../Select.AsyncValueEnumerable.Tests.cs | 3 +- .../SelectAt.AsyncValueEnumerable.Tests.cs | 3 +- .../All/All.AsyncValueEnumerable.Tests.cs | 6 +- .../Any/Any.AsyncValueEnumerable.Tests.cs | 9 +- .../Contains.AsyncValueEnumerable.Tests.cs | 24 ++- .../Distinct.AsyncValueEnumerable.Tests.cs | 12 +- .../AsValueEnumerable.ReadOnlyMemory.cs | 22 +++ .../AsValueEnumerable.ReadOnlySpan.cs | 22 +++ .../System/Collections/Generic/List.cs | 3 +- .../NetFabric.Hyperlinq.csproj | 2 +- 29 files changed, 904 insertions(+), 196 deletions(-) create mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs index 6314766a4..18ca41074 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs @@ -22,7 +22,8 @@ public async ValueTask CountAsync_With_ValidData_Must_Succeed(int[] source) // Act var result = await wrapped - .CountAsync, Wrap.AsyncEnumerator, int>(); + .CountAsync, Wrap.AsyncEnumerator, int>() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -44,7 +45,8 @@ public async ValueTask CountAsync_Predicate_With_ValidData_Must_Succeed(int[] so // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .CountAsync(); + .CountAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -67,7 +69,8 @@ public async ValueTask CountAsync_PredicateAt_With_ValidData_Must_Succeed(int[] // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .CountAsync(); + .CountAsync() + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs new file mode 100644 index 000000000..83b6a9539 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs @@ -0,0 +1,49 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum +{ + public class AsyncValueEnumerableTests + { + [Theory] + [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] + public async ValueTask SumAsync_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsAsyncValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = await wrapped + .SumAsync, Wrap.AsyncEnumerator, int, int>() + .ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] + public async ValueTask SumAsync_With_Nullable_ValidData_Must_Succeed(int?[] source) + { + // Arrange + var wrapped = Wrap.AsAsyncValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = await wrapped + .SumAsync, Wrap.AsyncEnumerator, int?, int>() + .ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected.Value); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs index 2966bda99..4a64819dd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs @@ -44,7 +44,8 @@ public async ValueTask AsAsyncValueEnumerable_With_ToArrayAsync_Must_Succeed(int // Act var result = await wrapped .AsAsyncValueEnumerable() - .ToArrayAsync(); + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -67,7 +68,8 @@ public async ValueTask AsAsyncValueEnumerable_With_ToListAsync_Must_Succeed(int[ // Act var result = await wrapped .AsAsyncValueEnumerable() - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -109,7 +111,8 @@ public async ValueTask AsAsyncValueEnumerable_GetEnumerator_ToListAsync_With_Val // Act var result = await wrapped .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>((enumerable, _) => enumerable.GetAsyncEnumerator()) - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -130,7 +133,8 @@ public async ValueTask AsAsyncValueEnumerable_GetEnumerator_ToArrayAsync_With_Va // Act var result = await wrapped .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>((enumerable, _) => enumerable.GetAsyncEnumerator()) - .ToArrayAsync(); + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -138,4 +142,4 @@ public async ValueTask AsAsyncValueEnumerable_GetEnumerator_ToArrayAsync_With_Va .BeEqualTo(source); } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs index 4dff991e8..ffd8b864a 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs @@ -44,7 +44,8 @@ public async ValueTask AsAsyncValueEnumerable_With_ToArrayAsync_Must_Succeed(int // Act var result = await wrapped .AsAsyncValueEnumerable, Wrap.Enumerator, int>() - .ToArrayAsync(); + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -67,7 +68,8 @@ public async ValueTask AsAsyncValueEnumerable_With_ToListAsync_Must_Succeed(int[ // Act var result = await wrapped .AsAsyncValueEnumerable, Wrap.Enumerator, int>() - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -76,4 +78,4 @@ public async ValueTask AsAsyncValueEnumerable_With_ToListAsync_Must_Succeed(int[ .BeEqualTo(expected); } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs new file mode 100644 index 000000000..a7f8660b2 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -0,0 +1,147 @@ +using System.Linq; +using NetFabric.Assertive; +using System; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ArraySegmentTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = new ArraySegment(source); + + // Act + var result = wrapped + .AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source, testRefStructs: false); + result.SequenceEqual(source).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Skip_With_ValidData_Must_Succeed(int[] source, int count) + { + // Arrange + var wrapped = new ArraySegment(source); + var expected = source + .Skip(count); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(count); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected, testRefStructs: false); + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = new ArraySegment(source); + var expected = source + .Skip(count0) + .Skip(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(count0) + .Skip(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected, testRefStructs: false); + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count) + { + // Arrange + var wrapped = new ArraySegment(source); + var expected = source + .Take(count); + + // Act + var result = wrapped + .AsValueEnumerable() + .Take(count); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected, testRefStructs: false); + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = new ArraySegment(source); + var expected = source + .Take(count0) + .Take(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Take(count0) + .Take(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected, testRefStructs: false); + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) + { + // Arrange + var wrapped = new ArraySegment(source); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs index b8e119022..4f2f6fa86 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs @@ -1,16 +1,17 @@ -using System.Linq; -using NetFabric.Assertive; +using NetFabric.Assertive; using Xunit; +using System.Collections.Generic; +using System.Linq; namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable { - public partial class ReadOnlyListTests + public class ReadOnlyListTests { [Theory] [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) + public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap @@ -22,26 +23,73 @@ public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) // Assert _ = result.Must() + .BeOfType, int>>() .BeEnumerableOf() - .BeEqualTo(source); + .BeEqualTo(wrapped); } - + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyList(source); + var expected = Enumerable + .ToArray(source); + + // Act + var result = wrapped + .AsValueEnumerable() + .ToArray(); + + // Assert + _ = result.Must() + .BeArrayOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_Collection_With_ToArray_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsList(source); + var expected = Enumerable + .ToArray(source); + + // Act + var result = wrapped + .AsValueEnumerable() + .ToArray(); + + // Assert + _ = result.Must() + .BeArrayOf() + .BeEqualTo(expected); + } + [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Skip_With_ValidData_Must_Succeed(int[] source, int count) + [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) { // Arrange var wrapped = Wrap .AsReadOnlyList(source); var expected = source - .Skip(count); + .Skip(count0) + .Skip(count1); // Act var result = wrapped .AsValueEnumerable() - .Skip(count); + .Skip(count0) + .Skip(count1); // Assert _ = result.Must() @@ -54,17 +102,41 @@ public void AsValueEnumerable1_Skip_With_ValidData_Must_Succeed(int[] source, in [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyList(source); + var expected = Enumerable + .ToList(source); + + // Act + var result = wrapped + .AsValueEnumerable() + .ToList(); + + // Assert + _ = result.Must() + .BeOfType>() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) { // Arrange var wrapped = Wrap .AsReadOnlyList(source); var expected = source - .Take(count); + .Take(count0) + .Take(count1); // Act var result = wrapped .AsValueEnumerable() - .Take(count); + .Take(count0) + .Take(count1); // Assert _ = result.Must() @@ -80,22 +152,20 @@ public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int { // Arrange var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Sum(); + .AsList(source); + var expected = Enumerable + .ToList(source); // Act var result = wrapped .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Sum(); + .ToList(); // Assert _ = result.Must() + .BeOfType>() + .BeEnumerableOf() .BeEqualTo(expected); } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs new file mode 100644 index 000000000..d250d6d35 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -0,0 +1,147 @@ +using System.Linq; +using NetFabric.Assertive; +using System; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ReadOnlyMemoryTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + + // Act + var result = wrapped + .AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source, testRefStructs: false); + result.SequenceEqual(source).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Skip_With_ValidData_Must_Succeed(int[] source, int count) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Skip(count); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(count); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected, testRefStructs: false); + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Skip(count0) + .Skip(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(count0) + .Skip(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected, testRefStructs: false); + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Take(count); + + // Act + var result = wrapped + .AsValueEnumerable() + .Take(count); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected, testRefStructs: false); + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Take(count0) + .Take(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Take(count0) + .Take(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected, testRefStructs: false); + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) + { + // Arrange + var wrapped = (ReadOnlyMemory)source.AsMemory(); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs new file mode 100644 index 000000000..ba6fe399c --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -0,0 +1,132 @@ +using System.Linq; +using NetFabric.Assertive; +using System; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ReadOnlySpanTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + + // Act + var result = wrapped + .AsValueEnumerable(); + + // Assert + result.SequenceEqual(source).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Skip_With_ValidData_Must_Succeed(int[] source, int count) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Skip(count); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(count); + + // Assert + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Skip(count0) + .Skip(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(count0) + .Skip(count1); + + // Assert + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Take(count); + + // Act + var result = wrapped + .AsValueEnumerable() + .Take(count); + + // Assert + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Take(count0) + .Take(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Take(count0) + .Take(count1); + + // Assert + result.SequenceEqual(expected).Must().BeTrue(); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs index 588ee658c..a6a47df45 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using System.Collections.Immutable; +using System.Linq; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Immutable @@ -20,9 +21,10 @@ public void AsValueEnumerable_With_ImmutableArray_Must_ReturnWrapper(int[] sourc // Assert _ = result.Must() - .BeOfType, int>>() + .BeOfType>() .BeEnumerableOf() - .BeEqualTo(source); + .BeEqualTo(source, testRefStructs: false); + result.SequenceEqual(source).Must().BeTrue(); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs index ae70e3d12..6931d4850 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs @@ -23,7 +23,8 @@ public async ValueTask ToArrayAsync_With_ValidData_Must_Succeed(int[] source) // Act var result = await wrapped - .ToArrayAsync, Wrap.AsyncEnumerator, int>(); + .ToArrayAsync, Wrap.AsyncEnumerator, int>() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -46,7 +47,8 @@ public async ValueTask ToArrayAsync_MemoryPool_Must_Succeed(int[] source) // Act var result = await wrapped - .ToArrayAsync, Wrap.AsyncEnumerator, int>(pool); + .ToArrayAsync, Wrap.AsyncEnumerator, int>(pool) + .ConfigureAwait(false); // Assert _ = result.Memory @@ -71,7 +73,8 @@ public async ValueTask ToArrayAsync_Predicate_With_ValidData_Must_Succeed(int[] // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ToArrayAsync(); + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -96,7 +99,8 @@ public async ValueTask ToArrayAsync_Predicate_MemoryPool_Must_Succeed(int[] sour // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ToArrayAsync(pool); + .ToArrayAsync(pool) + .ConfigureAwait(false); // Assert _ = result.Memory @@ -121,7 +125,8 @@ public async ValueTask ToArrayAsync_PredicateAt_With_ValidData_Must_Succeed(int[ // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ToArrayAsync(); + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -146,7 +151,8 @@ public async ValueTask ToArrayAsync_PredicateAt_MemoryPool_Must_Succeed(int[] so // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ToArrayAsync(pool); + .ToArrayAsync(pool) + .ConfigureAwait(false); // Assert _ = result.Memory @@ -171,7 +177,8 @@ public async ValueTask ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] s // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ToArrayAsync(); + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -196,7 +203,8 @@ public async ValueTask ToArrayAsync_Selector_MemoryPool_Must_Succeed(int[] sourc // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ToArrayAsync(pool); + .ToArrayAsync(pool) + .ConfigureAwait(false); // Assert _ = result.Memory @@ -221,7 +229,8 @@ public async ValueTask ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[] // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ToArrayAsync(); + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -246,7 +255,8 @@ public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] sou // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ToArrayAsync(pool); + .ToArrayAsync(pool) + .ConfigureAwait(false); // Assert _ = result.Memory @@ -274,7 +284,8 @@ public async ValueTask ToArrayAsync_Predicate_Selector_With_ValidData_Must_Succe var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) - .ToArrayAsync(); + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -301,7 +312,8 @@ public async ValueTask ToArrayAsync_Predicate_Selector_MemoryPool_Must_Succeed(i var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) - .ToArrayAsync(pool); + .ToArrayAsync(pool) + .ConfigureAwait(false); // Assert _ = result.Memory diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs index 53e5e64a5..7e705771b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs @@ -23,7 +23,8 @@ public async ValueTask ToListAsync_With_ValidData_Must_Succeed(int[] source) // Act var result = await wrapped - .ToListAsync, Wrap.AsyncEnumerator, int>(); + .ToListAsync, Wrap.AsyncEnumerator, int>() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -48,7 +49,8 @@ public async ValueTask ToListAsync_Predicate_With_ValidData_Must_Succeed(int[] s // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -73,7 +75,8 @@ public async ValueTask ToListAsync_PredicateAt_With_ValidData_Must_Succeed(int[] // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -98,7 +101,8 @@ public async ValueTask ToListAsync_Selector_With_ValidData_Must_Succeed(int[] so // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -123,7 +127,8 @@ public async ValueTask ToListAsync_SelectorAt_With_ValidData_Must_Succeed(int[] // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -151,7 +156,8 @@ public async ValueTask ToListAsync_Predicate_Selector_With_ValidData_Must_Succee var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs index e293faf1e..b98cbdf0f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs @@ -20,9 +20,11 @@ public async void ElementAtAsync_With_OutOfRange_Must_Return_None(int[] source) // Act var optionNegative = await wrapped - .ElementAtAsync, Wrap.AsyncEnumerator, int>(-1); + .ElementAtAsync, Wrap.AsyncEnumerator, int>(-1) + .ConfigureAwait(false); var optionTooLarge = await wrapped - .ElementAtAsync, Wrap.AsyncEnumerator, int>(source.Length); + .ElementAtAsync, Wrap.AsyncEnumerator, int>(source.Length) + .ConfigureAwait(false); // Assert _ = optionNegative.Must() @@ -43,12 +45,13 @@ public async ValueTask ElementAtAsync_With_ValidData_Must_Return_Some(int[] sour for (var index = 0; index < source.Length; index++) { // Arrange - var expected = source - .ElementAt(index); + var expected = Enumerable + .ElementAt(source, index); // Act var result = await wrapped - .ElementAtAsync, Wrap.AsyncEnumerator, int>(index); + .ElementAtAsync, Wrap.AsyncEnumerator, int>(index) + .ConfigureAwait(false); // Assert _ = result.Match( @@ -70,10 +73,12 @@ public async void ElementAtAsync_Predicate_With_OutOfRange_Must_Return_None(int[ // Act var optionNegative = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ElementAtAsync(-1); + .ElementAtAsync(-1) + .ConfigureAwait(false); var optionTooLarge = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ElementAtAsync(source.Length); + .ElementAtAsync(source.Length) + .ConfigureAwait(false); // Assert _ = optionNegative.Must() @@ -92,8 +97,8 @@ public async ValueTask ElementAtAsync_Predicate_With_ValidData_Must_Return_Some( // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Where(predicate) + var expected = Enumerable + .Where(source, predicate) .ToList(); for (var index = 0; index < expected.Count; index++) @@ -101,7 +106,8 @@ public async ValueTask ElementAtAsync_Predicate_With_ValidData_Must_Return_Some( // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ElementAtAsync(index); + .ElementAtAsync(index) + .ConfigureAwait(false); // Assert _ = result.Match( @@ -123,10 +129,12 @@ public async void ElementAtAsync_PredicateAt_With_OutOfRange_Must_Return_None(in // Act var optionNegative = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ElementAtAsync(-1); + .ElementAtAsync(-1) + .ConfigureAwait(false); var optionTooLarge = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ElementAtAsync(source.Length); + .ElementAtAsync(source.Length) + .ConfigureAwait(false); // Assert _ = optionNegative.Must() @@ -144,8 +152,8 @@ public async ValueTask ElementAtAsync_PredicateAt_With_ValidData_Must_Return_Som { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = source - .Where(predicate) + var expected = Enumerable + .Where(source, predicate) .ToList(); for (var index = 0; index < expected.Count; index++) @@ -153,7 +161,8 @@ public async ValueTask ElementAtAsync_PredicateAt_With_ValidData_Must_Return_Som // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .ElementAtAsync(index); + .ElementAtAsync(index) + .ConfigureAwait(false); // Assert _ = result.Match( @@ -175,10 +184,12 @@ public async void ElementAtAsync_Selector_With_OutOfRange_Must_Return_None(int[] // Act var optionNegative = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ElementAtAsync(-1); + .ElementAtAsync(-1) + .ConfigureAwait(false); var optionTooLarge = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ElementAtAsync(source.Length); + .ElementAtAsync(source.Length) + .ConfigureAwait(false); // Assert _ = optionNegative.Must() @@ -196,8 +207,8 @@ public async ValueTask ElementAtAsync_Selector_With_ValidData_Must_Return_Some(i { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = source - .Select(selector) + var expected = Enumerable + .Select(source, selector) .ToList(); for (var index = 0; index < source.Length; index++) @@ -205,7 +216,8 @@ public async ValueTask ElementAtAsync_Selector_With_ValidData_Must_Return_Some(i // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ElementAtAsync(index); + .ElementAtAsync(index) + .ConfigureAwait(false); // Assert _ = result.Match( @@ -227,10 +239,12 @@ public async void ElementAtAsync_SelectorAt_With_OutOfRange_Must_Return_None(int // Act var optionNegative = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ElementAtAsync(-1); + .ElementAtAsync(-1) + .ConfigureAwait(false); var optionTooLarge = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ElementAtAsync(source.Length); + .ElementAtAsync(source.Length) + .ConfigureAwait(false); // Assert _ = optionNegative.Must() @@ -249,8 +263,8 @@ public async ValueTask ElementAtAsync_SelectorAt_With_ValidData_Must_Return_Some // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Select(selector) + var expected = Enumerable + .Select(source, selector) .ToList(); for (var index = 0; index < source.Length; index++) @@ -258,7 +272,8 @@ public async ValueTask ElementAtAsync_SelectorAt_With_ValidData_Must_Return_Some // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .ElementAtAsync(index); + .ElementAtAsync(index) + .ConfigureAwait(false); // Assert _ = result.Match( @@ -278,14 +293,16 @@ public async void ElementAtAsync_Predicate_Selector_With_OutOfRange_Must_Return_ .AsAsyncValueEnumerable(source); // Act - var optionNegative = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var optionNegative = await AsyncValueEnumerableExtensions + .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) .Select(selector.AsAsync()) - .ElementAtAsync(-1); + .ElementAtAsync(-1) + .ConfigureAwait(false); var optionTooLarge = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select(selector.AsAsync()) - .ElementAtAsync(source.Length); + .ElementAtAsync(source.Length) + .ConfigureAwait(false); // Assert _ = optionNegative.Must() @@ -304,18 +321,19 @@ public async ValueTask ElementAtAsync_Predicate_Selector_With_ValidData_Must_Ret // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Where(predicate) + var expected = Enumerable + .Where(source, predicate) .Select(selector) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await AsyncValueEnumerableExtensions + .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) .Select(selector.AsAsync()) - .ElementAtAsync(index); + .ElementAtAsync(index) + .ConfigureAwait(false); // Assert _ = result.Match( @@ -324,4 +342,4 @@ public async ValueTask ElementAtAsync_Predicate_Selector_With_ValidData_Must_Ret } } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs index 54e90bb83..c5e2358bf 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs @@ -18,7 +18,8 @@ public async void FirstAsync_With_Empty_Must_Return_None(int[] source) // Act var result = await wrapped - .FirstAsync, Wrap.AsyncEnumerator, int>(); + .FirstAsync, Wrap.AsyncEnumerator, int>() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -34,12 +35,13 @@ public async ValueTask FirstAsync_With_ValidData_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .First(); + var expected = Enumerable + .First(source); // Act var result = await wrapped - .FirstAsync, Wrap.AsyncEnumerator, int>(); + .FirstAsync, Wrap.AsyncEnumerator, int>() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -58,7 +60,8 @@ public async void FirstAsync_Predicate_With_Empty_Must_Return_None(int[] source, // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -74,13 +77,14 @@ public async ValueTask FirstAsync_Predicate_With_ValidData_Must_Return_Some(int[ // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .First(predicate); + var expected = Enumerable + .First(source, predicate); // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -99,7 +103,8 @@ public async void FirstAsync_PredicateAt_With_Empty_Must_Return_None(int[] sourc // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -115,14 +120,15 @@ public async ValueTask FirstAsync_PredicateAt_With_ValidData_Must_Return_Some(in // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Where(predicate) + var expected = Enumerable + .Where(source, predicate) .First(); // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -141,7 +147,8 @@ public async void FirstAsync_Selector_With_Empty_Must_Return_None(int[] source, // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -157,14 +164,15 @@ public async ValueTask FirstAsync_Selector_With_ValidData_Must_Return_Some(int[] // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Select(selector) + var expected = Enumerable + .Select(source, selector) .First(); // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -183,7 +191,8 @@ public async void FirstAsync_SelectorAt_With_Empty_Must_Return_None(int[] source // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -199,14 +208,15 @@ public async ValueTask FirstAsync_SelectorAt_With_ValidData_Must_Return_Some(int // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Select(selector) + var expected = Enumerable + .Select(source, selector) .First(); // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -223,10 +233,11 @@ public async void FirstAsync_Predicate_Selector_With_Empty_Must_Return_None(int[ .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await AsyncValueEnumerableExtensions + .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) .Select(selector.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -242,16 +253,17 @@ public async ValueTask FirstAsync_Predicate_Selector_With_ValidData_Must_Return_ // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Where(predicate) + var expected = Enumerable + .Where(source, predicate) .Select(selector) .First(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await AsyncValueEnumerableExtensions + .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) .Select(selector.AsAsync()) - .FirstAsync(); + .FirstAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -259,4 +271,4 @@ public async ValueTask FirstAsync_Predicate_Selector_With_ValidData_Must_Return_ () => throw new Exception()); } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs index bdd1e2ede..733300ab1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs @@ -18,7 +18,8 @@ public async void SingleAsync_With_Empty_Must_Return_None(int[] source) // Act var result = await wrapped - .SingleAsync, Wrap.AsyncEnumerator, int>(); + .SingleAsync, Wrap.AsyncEnumerator, int>() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -33,12 +34,13 @@ public async ValueTask SingleAsync_With_SingleAsync_Must_Return_Some(int[] sourc // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Single(); + var expected = Enumerable + .Single(source); // Act var result = await wrapped - .SingleAsync, Wrap.AsyncEnumerator, int>(); + .SingleAsync, Wrap.AsyncEnumerator, int>() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -56,7 +58,8 @@ public async void SingleAsync_With_Multiple_Must_Return_None(int[] source) // Act var result = await wrapped - .SingleAsync, Wrap.AsyncEnumerator, int>(); + .SingleAsync, Wrap.AsyncEnumerator, int>() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -75,7 +78,8 @@ public async void SingleAsync_Predicate_With_Empty_Must_Return_None(int[] source // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -90,13 +94,14 @@ public async ValueTask SingleAsync_Predicate_With_SingleAsync_Must_Return_Some(i // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Single(predicate); + var expected = Enumerable + .Single(source, predicate); // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -115,7 +120,8 @@ public async void SingleAsync_Predicate_With_Multiple_Must_Return_None(int[] sou // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -134,7 +140,8 @@ public async void SingleAsync_PredicateAt_With_Empty_Must_Return_None(int[] sour // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -149,14 +156,15 @@ public async ValueTask SingleAsync_PredicateAt_With_SingleAsync_Must_Return_Some // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Where(predicate) + var expected = Enumerable + .Where(source, predicate) .Single(); // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -175,7 +183,8 @@ public async void SingleAsync_PredicateAt_With_Multiple_Must_Return_None(int[] s // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -194,7 +203,8 @@ public async void SingleAsync_Selector_With_Empty_Must_Return_None(int[] source, // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -209,14 +219,15 @@ public async ValueTask SingleAsync_Selector_With_SingleAsync_Must_Return_Some(in // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Select(selector) + var expected = Enumerable + .Select(source, selector) .Single(); // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -235,7 +246,8 @@ public async void SingleAsync_Selector_With_Multiple_Must_Return_None(int[] sour // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -254,7 +266,8 @@ public async void SingleAsync_SelectorAt_With_Empty_Must_Return_None(int[] sourc // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -269,14 +282,15 @@ public async ValueTask SingleAsync_SelectorAt_With_SingleAsync_Must_Return_Some( // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Select(selector) + var expected = Enumerable + .Select(source, selector) .Single(); // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -295,7 +309,8 @@ public async void SingleAsync_SelectorAt_With_Multiple_Must_Return_None(int[] so // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -312,10 +327,11 @@ public async void SingleAsync_Predicate_Selector_With_Empty_Must_Return_None(int .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await AsyncValueEnumerableExtensions + .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) .Select(selector.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -330,16 +346,17 @@ public async ValueTask SingleAsync_Predicate_Selector_With_SingleAsync_Must_Retu // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = source - .Where(predicate) + var expected = Enumerable + .Where(source, predicate) .Select(selector) .Single(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await AsyncValueEnumerableExtensions + .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) .Select(selector.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Match( @@ -356,10 +373,11 @@ public async void SingleAsync_Predicate_Selector_With_Multiple_Must_Return_None( .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await AsyncValueEnumerableExtensions + .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) .Select(selector.AsAsync()) - .SingleAsync(); + .SingleAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -367,4 +385,4 @@ public async void SingleAsync_Predicate_Selector_With_Multiple_Must_Return_None( .EvaluateTrue(option => option.IsNone); } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs index 61c0066e4..34ae9626b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs @@ -46,7 +46,8 @@ public async ValueTask Where_Sum_Predicate_With_ValidData_Must_Succeed(int[] sou // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .SumAsync().ConfigureAwait(false); + .SumAsync() + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs index 6a2fff1d6..db2d5ba4d 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs @@ -46,7 +46,8 @@ public async ValueTask Where_Sum_Predicate_With_ValidData_Must_Succeed(int[] sou // Act var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) - .SumAsync(); + .SumAsync() + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs index 05f2cd04d..a308e525f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs @@ -48,7 +48,8 @@ public async ValueTask WhereSelect_Sum_Predicate_With_ValidData_Must_Succeed(int var result = await wrapped .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) .Select((item, _) => new ValueTask(item)) - .SumAsync().ConfigureAwait(false); + .SumAsync() +.ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs index 80903dfda..3f6622a06 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs @@ -45,7 +45,7 @@ public void Range_With_ValidData_Must_Succeed(int start, int count) public void Range_Skip_With_ValidData_Must_Succeed(int start, int count, int skip) { // Arrange - var expected = Enumerable.Range(start, count).Skip(skip); + var expected = Enumerable.Skip(Enumerable.Range(start, count), skip); // Act var result = AsyncValueEnumerable.Range(start, count).Skip(skip); @@ -61,7 +61,7 @@ public void Range_Skip_With_ValidData_Must_Succeed(int start, int count, int ski public void Range_Take_With_ValidData_Must_Succeed(int start, int count, int take) { // Arrange - var expected = Enumerable.Range(start, count).Take(take); + var expected = Enumerable.Take(Enumerable.Range(start, count), take); // Act var result = AsyncValueEnumerable.Range(start, count).Take(take); @@ -77,10 +77,12 @@ public void Range_Take_With_ValidData_Must_Succeed(int start, int count, int tak public async ValueTask Range_AnyAsync_With_ValidData_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.Range(start, count).Any(); + var expected = Enumerable.Any(Enumerable.Range(start, count)); // Act - var result = await AsyncValueEnumerable.Range(start, count).AnyAsync(); + var result = await AsyncValueEnumerable.Range(start, count) + .AnyAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -92,14 +94,13 @@ public async ValueTask Range_AnyAsync_With_ValidData_Must_Succeed(int start, int public async ValueTask Range_ContainsAsync_With_ValidData_Must_Succeed(int start, int count, int value) { // Arrange - var expected = Enumerable - .Range(start, count) - .Contains(value); + var expected = Enumerable.Contains(Enumerable.Range(start, count), value); // Act var result = await AsyncValueEnumerable .Range(start, count) - .ContainsAsync(value); + .ContainsAsync(value) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -111,10 +112,13 @@ public async ValueTask Range_ContainsAsync_With_ValidData_Must_Succeed(int start public async ValueTask Range_ToArray_With_ValidData_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.Range(start, count).ToArray(); + var expected = Enumerable.ToArray(Enumerable.Range(start, count)); // Act - var result = await AsyncValueEnumerable.Range(start, count).ToArrayAsync(); + var result = await AsyncValueEnumerable + .Range(start, count) + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -127,10 +131,13 @@ public async ValueTask Range_ToArray_With_ValidData_Must_Succeed(int start, int public async ValueTask Range_With_ToList_Must_Succeed(int start, int count) { // Arrange - var expected = Enumerable.Range(start, count).ToList(); + var expected = Enumerable.ToList(Enumerable.Range(start, count)); // Act - var result = await AsyncValueEnumerable.Range(start, count).ToListAsync(); + var result = await AsyncValueEnumerable + .Range(start, count) + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -139,4 +146,4 @@ public async ValueTask Range_With_ToList_Must_Succeed(int start, int count) .BeEqualTo(expected); } } -} \ No newline at end of file +} diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs index e1161af90..e5e2c35b5 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs @@ -81,7 +81,10 @@ public async ValueTask Repeat_All_With_ValidData_Must_Succeed(int value, int cou var expected = Enumerable.Repeat(value, count).All(item => false); // Act - var result = await AsyncValueEnumerable.Repeat(value, count).AllAsync(item => false); + var result = await AsyncValueEnumerable + .Repeat(value, count) + .AllAsync(item => false) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -96,7 +99,10 @@ public async ValueTask Repeat_Any_With_ValidData_Must_Succeed(int value, int cou var expected = Enumerable.Repeat(value, count).Any(); // Act - var result = await AsyncValueEnumerable.Repeat(value, count).AnyAsync(); + var result = await AsyncValueEnumerable + .Repeat(value, count) + .AnyAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -111,7 +117,10 @@ public async ValueTask Repeat_ToArray_With_ValidData_Must_Succeed(int value, int var expected = Enumerable.Repeat(value, count).ToArray(); // Act - var result = await AsyncValueEnumerable.Repeat(value, count).ToArrayAsync(); + var result = await AsyncValueEnumerable + .Repeat(value, count) + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -127,7 +136,10 @@ public async ValueTask Repeat_ToList_With_ValidData_Must_Succeed(int value, int var expected = Enumerable.Repeat(value, count).ToList(); // Act - var result = await AsyncValueEnumerable.Repeat(value, count).ToListAsync(); + var result = await AsyncValueEnumerable + .Repeat(value, count) + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs index 768d49dff..acd451929 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs @@ -44,7 +44,8 @@ public async ValueTask Select_Sum_With_ValidData_Must_Succeed(int[] source) // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, int>((item, _) => new ValueTask(item)) - .SumAsync().ConfigureAwait(false); + .SumAsync() + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs index 43d36eb60..ad5f4b9e2 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs @@ -44,7 +44,8 @@ public async ValueTask Select_Sum_With_ValidData_Must_Succeed(int[] source) // Act var result = await wrapped .Select, Wrap.AsyncEnumerator, int, int>((item, _, _) => new ValueTask(item)) - .SumAsync().ConfigureAwait(false); + .SumAsync() + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs index f5caa098c..af58e47d7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs @@ -21,7 +21,8 @@ public async ValueTask AllAsync_With_ValidData_Must_Succeed(int[] source, Func, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); + .AllAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -42,7 +43,8 @@ public async ValueTask AllAsync_PredicateAt_With_ValidData_Must_Succeed(int[] so // Act var result = await wrapped - .AllAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); + .AllAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs index 30d04f623..87f2c297c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs @@ -21,7 +21,8 @@ public async ValueTask AnyAsync_With_ValidData_Must_Succeed(int[] source) // Act var result = await wrapped - .AnyAsync, Wrap.AsyncEnumerator, int>(); + .AnyAsync, Wrap.AsyncEnumerator, int>() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -41,7 +42,8 @@ public async ValueTask AnyAsync_Predicate_With_ValidData_Must_Succeed(int[] sour // Act var result = await wrapped - .AnyAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); + .AnyAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -62,7 +64,8 @@ public async ValueTask AnyAsync_PredicateAt_With_ValidData_Must_Succeed(int[] so // Act var result = await wrapped - .AnyAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); + .AnyAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs index 3b481a9f9..c2c39d1f8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs @@ -20,7 +20,8 @@ public async ValueTask ContainsAsync_ValueType_With_Null_And_NotContains_Must_Re // Act var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value); + .ContainsAsync, Wrap.AsyncEnumerator, int>(value) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -39,7 +40,8 @@ public async ValueTask ContainsAsync_ReferenceType_With_Null_And_NotContains_Mus // Act var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, string>(value); + .ContainsAsync, Wrap.AsyncEnumerator, string>(value) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -58,7 +60,8 @@ public async ValueTask ContainsAsync_ValueType_With_Null_And_Contains_Must_Retur // Act var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value); + .ContainsAsync, Wrap.AsyncEnumerator, int>(value) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -78,7 +81,8 @@ public async ValueTask ContainsAsync_ReferenceType_With_Null_And_Contains_Must_R // Act var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, string>(value); + .ContainsAsync, Wrap.AsyncEnumerator, string>(value) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -97,7 +101,8 @@ public async ValueTask ContainsAsync_With_DefaultComparer_And_NotContains_Must_R // Act var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value, EqualityComparer.Default); + .ContainsAsync, Wrap.AsyncEnumerator, int>(value, EqualityComparer.Default) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -116,7 +121,8 @@ public async ValueTask ContainsAsync_With_DefaultComparer_And_Contains_Must_Retu // Act var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value, EqualityComparer.Default); + .ContainsAsync, Wrap.AsyncEnumerator, int>(value, EqualityComparer.Default) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -136,7 +142,8 @@ public async ValueTask ContainsAsync_With_Comparer_And_NotContains_Must_ReturnFa // Act var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value, TestComparer.Instance); + .ContainsAsync, Wrap.AsyncEnumerator, int>(value, TestComparer.Instance) + .ConfigureAwait(false); // Assert _ = result.Must() @@ -155,7 +162,8 @@ public async ValueTask ContainsAsync_With_Comparer_And_Contains_Must_ReturnTrue( // Act var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value, TestComparer.Instance); + .ContainsAsync, Wrap.AsyncEnumerator, int>(value, TestComparer.Instance) + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs index acd226fa8..51835524a 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs @@ -44,7 +44,8 @@ public async ValueTask Distinct_ToArrayAsync_With_ValidData_Must_Succeed(int[] s // Act var result = await wrapped .Distinct, Wrap.AsyncEnumerator, int>() - .ToArrayAsync(); + .ToArrayAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -68,7 +69,8 @@ public async ValueTask Distinct_ToArrayAsync_MemoryPool_With_ValidData_Must_Succ // Act var result = await wrapped .Distinct, Wrap.AsyncEnumerator, int>() - .ToArrayAsync(pool); + .ToArrayAsync(pool) + .ConfigureAwait(false); // Assert _ = result @@ -90,7 +92,8 @@ public async ValueTask Distinct_ToListAsync_With_ValidData_Must_Succeed(int[] so // Act var result = await wrapped .Distinct, Wrap.AsyncEnumerator, int>() - .ToListAsync(); + .ToListAsync() + .ConfigureAwait(false); // Assert _ = result.Must() @@ -113,7 +116,8 @@ public async ValueTask Distinct_SumAsync_With_ValidData_Must_Succeed(int[] sourc // Act var result = await wrapped .Distinct, Wrap.AsyncEnumerator, int>() - .SumAsync().ConfigureAwait(false); + .SumAsync() + .ConfigureAwait(false); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index 00e0c5fa3..1cf02f6a4 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -324,6 +324,28 @@ public MemoryDistinctEnumerable Distinct(IEqualityComparer? co => source.Distinct(comparer); #endregion + + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + { + comparer ??= EqualityComparer.Default; + + var enumerator = GetEnumerator(); + using var otherEnumerator = other.GetEnumerator(); + while (true) + { + var thisEnded = !enumerator.MoveNext(); + var otherEnded = !otherEnumerator.MoveNext(); + + if (thisEnded != otherEnded) + return false; + + if (thisEnded) + return true; + + if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) + return false; + } + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index 5c2b97bd2..0ba7b0c09 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -230,6 +230,28 @@ public SpanDistinctEnumerable Distinct(IEqualityComparer? comp => source.Distinct(comparer); #endregion + + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + { + comparer ??= EqualityComparer.Default; + + var enumerator = GetEnumerator(); + using var otherEnumerator = other.GetEnumerator(); + while (true) + { + var thisEnded = !enumerator.MoveNext(); + var otherEnded = !otherEnumerator.MoveNext(); + + if (thisEnded != otherEnded) + return false; + + if (thisEnded) + return true; + + if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) + return false; + } + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs index 254d1b658..58e228e38 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs @@ -6,11 +6,12 @@ namespace NetFabric.Hyperlinq public static class ListBindings { // List is simply converted to ArraySegment and share its IValueEnumerable wrapper. - // It's not converted to ReadOnlySpan because its enumerators cannot be casted to IEnumerable, restricting its use. + // It's not converted to ReadOnlySpan because its enumerables cannot be casted to IEnumerable, restricting its use. // It's not converted to ReadOnlyMemory because it's less efficient in enumerables (it has to call .Span on each iteration). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ArrayExtensions.ArraySegmentValueEnumerable AsValueEnumerable(this List source) => source.AsArraySegment().AsValueEnumerable(); + } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 208efae2d..c1d537c74 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -5,7 +5,7 @@ NetFabric.Hyperlinq NetFabric.Hyperlinq High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays, Memory and Span. - 3.0.0-beta42 + 3.0.0-beta43 Icon.png LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance From 117928fbb7b794f2641a13f0cf6eb58f718aba7e Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Fri, 5 Mar 2021 10:55:49 +0000 Subject: [PATCH 11/61] 3.0.0-beta44 --- NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index c1d537c74..44eca9da9 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -5,7 +5,7 @@ NetFabric.Hyperlinq NetFabric.Hyperlinq High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays, Memory and Span. - 3.0.0-beta43 + 3.0.0-beta44 Icon.png LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance From 89c364f09ee6d262f854d3056279adb092a0c53c Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Fri, 5 Mar 2021 13:35:18 +0000 Subject: [PATCH 12/61] Fix sentence --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 46b3f6064..1769dc95e 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ using System.Linq; using NetFabric.Hyperlinq; // add this directive ``` -- Use the methods `AsValueEnumerable()`or `AsAsyncValueEnumerable()` to make any collection usable with `NetFabric.Hyperlinq`. This includes arrays, `Memory<>`, `ReadOnlyMemory<>`, BCL collections, and any other implementation of `IEnumerable<>` or `IAsyncEnumerable<>`. It's not required for `Span<>` and `ReadOnlySpan<>`. +- Use the methods `AsValueEnumerable()` to make any collection usable with `NetFabric.Hyperlinq`. This includes arrays, `Memory<>`, `ReadOnlyMemory<>`, `Span<>`, `ReadOnlySpan<>`, BCL collections, and any other implementation of `IEnumerable<>`. Use `AsAsyncValueEnumerable()` for any implementation of `IAsyncEnumerable<>`. ``` csharp public static void Example(IReadOnlyList list) From c65f579c51345ecbf594be57dd75ac47ac8d5a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Fri, 5 Mar 2021 20:35:22 +0000 Subject: [PATCH 13/61] Add NetFabric.Hyperlinq.Immutable project (#343) --- .../NetFabric.Hyperlinq.Immutable.csproj | 56 +++++++++++++++++++ NetFabric.Hyperlinq.sln | 9 ++- .../Generic/{List.cs => ListExtensions.cs} | 2 +- ...leArray.cs => ImmutableArrayExtensions.cs} | 1 - ...ry.cs => ImmutableDictionaryExtensions.cs} | 0 ...shSet.cs => ImmutableHashSetExtensions.cs} | 0 ...ableList.cs => ImmutableListExtensions.cs} | 0 ...leQueue.cs => ImmutableQueueExtensions.cs} | 0 ...=> ImmutableSortedDictionaryExtensions.cs} | 0 ...leStack.cs => ImmutableStackExtensions.cs} | 0 .../NetFabric.Hyperlinq.csproj | 6 -- NetFabric.Hyperlinq/Utils/ListExtensions.cs | 10 ++-- README.md | 2 + 13 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/{List.cs => ListExtensions.cs} (94%) rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/{ImmutableArray.cs => ImmutableArrayExtensions.cs} (97%) rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/{ImmutableDictionary.cs => ImmutableDictionaryExtensions.cs} (100%) rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/{ImmutableHashSet.cs => ImmutableHashSetExtensions.cs} (100%) rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/{ImmutableList.cs => ImmutableListExtensions.cs} (100%) rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/{ImmutableQueue.cs => ImmutableQueueExtensions.cs} (100%) rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/{ImmutableSortedDictionary.cs => ImmutableSortedDictionaryExtensions.cs} (100%) rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/{ImmutableStack.cs => ImmutableStackExtensions.cs} (100%) diff --git a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj new file mode 100644 index 000000000..7d32a6d02 --- /dev/null +++ b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj @@ -0,0 +1,56 @@ + + + + net461;netstandard2.0 + NetFabric.Hyperlinq.Immutable + NetFabric.Hyperlinq.Immutable + High performance LINQ implementation with minimal heap allocations. Supports all collections in System.Collections.Immutable. + 1.0.0-beta01 + Icon.png + LICENSE + netfabric, hyperlinq, linq, enumeration, extensions, performance + true + enable + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + + + + + + diff --git a/NetFabric.Hyperlinq.sln b/NetFabric.Hyperlinq.sln index 4ac9d838d..77877123b 100644 --- a/NetFabric.Hyperlinq.sln +++ b/NetFabric.Hyperlinq.sln @@ -12,13 +12,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig .gitattributes = .gitattributes .gitignore = .gitignore + coverlet.runsettings = coverlet.runsettings Directory.Build.props = Directory.Build.props .github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml global.json = global.json + Icon.png = Icon.png LICENSE = LICENSE NuGet.config = NuGet.config README.md = README.md - coverlet.runsettings = coverlet.runsettings EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Benchmarks", "NetFabric.Hyperlinq.Benchmarks\NetFabric.Hyperlinq.Benchmarks.csproj", "{02EE275F-6E2D-444A-AB1F-9BCD02DEA204}" @@ -29,6 +30,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.SourceG EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Abstractions", "NetFabric.Hyperlinq.Abstractions\NetFabric.Hyperlinq.Abstractions.csproj", "{6981E761-E698-437D-AF63-0E80844B7D41}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Immutable", "NetFabric.Hyperlinq.Immutable\NetFabric.Hyperlinq.Immutable.csproj", "{6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -59,6 +62,10 @@ Global {6981E761-E698-437D-AF63-0E80844B7D41}.Debug|Any CPU.Build.0 = Debug|Any CPU {6981E761-E698-437D-AF63-0E80844B7D41}.Release|Any CPU.ActiveCfg = Release|Any CPU {6981E761-E698-437D-AF63-0E80844B7D41}.Release|Any CPU.Build.0 = Release|Any CPU + {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs similarity index 94% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs index 58e228e38..d16617689 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs @@ -3,7 +3,7 @@ namespace NetFabric.Hyperlinq { - public static class ListBindings + public static partial class ListExtensions { // List is simply converted to ArraySegment and share its IValueEnumerable wrapper. // It's not converted to ReadOnlySpan because its enumerables cannot be casted to IEnumerable, restricting its use. diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArrayExtensions.cs similarity index 97% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArrayExtensions.cs index debe79407..5304b8aed 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArrayExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Immutable; -using System.Net.Http.Headers; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 44eca9da9..4d8de444e 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -76,10 +76,4 @@ - - - - - - diff --git a/NetFabric.Hyperlinq/Utils/ListExtensions.cs b/NetFabric.Hyperlinq/Utils/ListExtensions.cs index 2ca2708f1..2416db961 100644 --- a/NetFabric.Hyperlinq/Utils/ListExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/ListExtensions.cs @@ -5,14 +5,14 @@ namespace NetFabric.Hyperlinq { - static class ListExtensions + public static partial class ListExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ArraySegment AsArraySegment(this List source) + internal static ArraySegment AsArraySegment(this List source) => new(source.GetItems(), 0, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Span AsSpan(this List source) + internal static Span AsSpan(this List source) #if NET5_0_OR_GREATER => CollectionsMarshal.AsSpan(source); #else @@ -20,11 +20,11 @@ public static Span AsSpan(this List source) #endif [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Memory AsMemory(this List source) + internal static Memory AsMemory(this List source) => source.GetItems().AsMemory().Slice(0, source.Count); - public static List AsList(this TSource[] source) + internal static List AsList(this TSource[] source) { var result = new List(); var layout = Unsafe.As, ListLayout>(ref result); diff --git a/README.md b/README.md index 1769dc95e..1383e56dd 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,8 @@ public static void Example(IReadOnlyList list) } ``` +- `Netfabric.Hyperlinq` contains special versions of `AsValueEnumerable()` for better performance with all collections in the `System.Collections.Immutable` namespace. Projects targetting .NET Framework, `netcoreapp2.1` or `netstandard2.0`, require the addition of the [`NetFabric.Hyperlinq.Immutable` NuGet package](https://www.nuget.org/packages/NetFabric.Hyperlinq.Immutable/) dependency. + - All enumerables returned by `NetFabric.Hyperlinq` are compatible with `System.Linq`. `OrderByDescending()` is not yet available in `Netfabric.Hyperlinq` but can still be used without requiring any conversion: From 099a2dda4a69060a91a9ea1b6067a3e18a33f387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Sat, 6 Mar 2021 18:53:54 +0000 Subject: [PATCH 14/61] Add bindings for collections in System.Collections.Generic (#344) --- .../Collections/Generic/Dictionary.Tests.cs | 67 +++++++++++++++++++ .../Collections/Generic/HashSet.Tests.cs | 28 ++++++++ .../Collections/Generic/LinkedList.Tests.cs | 28 ++++++++ .../System/Collections/Generic/List.Tests.cs | 4 +- .../Generic/PriorityQueue.Tests.cs | 33 +++++++++ .../System/Collections/Generic/Queue.Tests.cs | 28 ++++++++ .../Generic/SortedDictionary.Tests.cs | 67 +++++++++++++++++++ .../Collections/Generic/SortedSet.Tests.cs | 28 ++++++++ .../System/Collections/Generic/Stack.Tests.cs | 28 ++++++++ .../Immutable/ImmutableArray.Tests.cs | 4 +- .../Immutable/ImmutableDictionary.Tests.cs | 3 +- .../Immutable/ImmutableHashSet.Tests.cs | 2 +- .../Immutable/ImmutableList.Tests.cs | 2 +- .../Immutable/ImmutableQueue.Tests.cs | 2 +- .../ImmutableSortedDictionary.Tests.cs | 3 +- .../Immutable/ImmutableStack.Tests.cs | 3 +- .../Generic/DictionaryExtensions.cs | 47 +++++++++++++ .../Collections/Generic/HashSetExtensions.cs | 24 +++++++ .../Generic/LinkedListExtensions.cs | 24 +++++++ .../Collections/Generic/ListExtensions.cs | 40 ++++++++++- .../Generic/PriorityQueueExtensions.cs | 29 ++++++++ .../Collections/Generic/QueueExtensions.cs | 24 +++++++ .../Generic/SortedDictionaryExtensions.cs | 47 +++++++++++++ .../Generic/SortedSetExtensions.cs | 24 +++++++ .../Collections/Generic/StackExtensions.cs | 24 +++++++ .../ImmutableDictionaryExtensions.cs | 1 + .../Immutable/ImmutableHashSetExtensions.cs | 1 + .../Immutable/ImmutableListExtensions.cs | 1 + .../Immutable/ImmutableQueueExtensions.cs | 2 + .../ImmutableSortedDictionaryExtensions.cs | 1 + .../Immutable/ImmutableStackExtensions.cs | 2 + NetFabric.Hyperlinq/Utils/ListExtensions.cs | 59 ---------------- 32 files changed, 607 insertions(+), 73 deletions(-) create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Dictionary.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSet.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedList.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueue.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Queue.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionary.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSet.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Stack.Tests.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Utils/ListExtensions.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Dictionary.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Dictionary.Tests.cs new file mode 100644 index 000000000..da7634e75 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Dictionary.Tests.cs @@ -0,0 +1,67 @@ +using NetFabric.Assertive; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Generic +{ + public class DictionaryTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_Dictionary_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = source.ToDictionary(item => item); + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, Dictionary.Enumerator, Dictionary.Enumerator, KeyValuePair, DictionaryExtensions.GetEnumerator, DictionaryExtensions.GetEnumerator>>() + .BeEnumerableOf>() + .BeEqualTo(wrapped); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_Dictionary_KeyCollection_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = source.ToDictionary(item => item).Keys; + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType.KeyCollection, Dictionary.KeyCollection.Enumerator, Dictionary.KeyCollection.Enumerator, int, DictionaryExtensions.GetEnumerator, DictionaryExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_Dictionary_ValueCollection_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = source.ToDictionary(item => item).Values; + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType.ValueCollection, Dictionary.ValueCollection.Enumerator, Dictionary.ValueCollection.Enumerator, int, DictionaryExtensions.GetEnumerator, DictionaryExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSet.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSet.Tests.cs new file mode 100644 index 000000000..4c9380d26 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSet.Tests.cs @@ -0,0 +1,28 @@ +using NetFabric.Assertive; +using System.Collections.Generic; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Generic +{ + public class HashSetTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_HashSet_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = new HashSet(source); + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, HashSet.Enumerator, HashSet.Enumerator, int, HashSetExtensions.GetEnumerator, HashSetExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedList.Tests.cs new file mode 100644 index 000000000..8c64acfcd --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedList.Tests.cs @@ -0,0 +1,28 @@ +using NetFabric.Assertive; +using System.Collections.Generic; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Generic +{ + public class LinkedListTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_LinkedList_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = new LinkedList(source); + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, LinkedList.Enumerator, LinkedList.Enumerator, int, LinkedListExtensions.GetEnumerator, LinkedListExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs index fa8c023a4..09510ab21 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs @@ -24,8 +24,8 @@ public void AsValueEnumerable_With_List_Must_ReturnWrapper(int[] source) _ = result.Must() .BeOfType>() .BeEnumerableOf() - .BeEqualTo(source, testRefStructs: false); - _ = result.SequenceEqual(source).Must().BeTrue(); + .BeEqualTo(wrapped, testRefStructs: false); + _ = result.SequenceEqual(wrapped).Must().BeTrue(); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueue.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueue.Tests.cs new file mode 100644 index 000000000..a26e370ad --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueue.Tests.cs @@ -0,0 +1,33 @@ +#if NET60_OR_GREATER + +using NetFabric.Assertive; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Generic +{ + public class PriorityQueueTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_PriorityQueue_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = new PriorityQueue(source.Select(item => (item, 0))); + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, PriorityQueue.Enumerator, PriorityQueue.Enumerator, int, PriorityQueueExtensions.GetEnumerator, PriorityQueueExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + } +} + +#endif diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Queue.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Queue.Tests.cs new file mode 100644 index 000000000..b8632d9b1 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Queue.Tests.cs @@ -0,0 +1,28 @@ +using NetFabric.Assertive; +using System.Collections.Generic; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Generic +{ + public class QueueTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_Queue_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = new Queue(source); + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, Queue.Enumerator, Queue.Enumerator, int, QueueExtensions.GetEnumerator, QueueExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionary.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionary.Tests.cs new file mode 100644 index 000000000..d035b2de2 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionary.Tests.cs @@ -0,0 +1,67 @@ +using NetFabric.Assertive; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Generic +{ + public class SortedDictionaryTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_SortedDictionary_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = new SortedDictionary(source.ToDictionary(item => item)); + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, SortedDictionary.Enumerator, SortedDictionary.Enumerator, KeyValuePair, SortedDictionaryExtensions.GetEnumerator, SortedDictionaryExtensions.GetEnumerator>>() + .BeEnumerableOf>() + .BeEqualTo(wrapped); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_SortedDictionary_KeyCollection_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = new SortedDictionary(source.ToDictionary(item => item)).Keys; + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType.KeyCollection, SortedDictionary.KeyCollection.Enumerator, SortedDictionary.KeyCollection.Enumerator, int, SortedDictionaryExtensions.GetEnumerator, SortedDictionaryExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_SortedDictionary_ValueCollection_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = new SortedDictionary(source.ToDictionary(item => item)).Values; + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType.ValueCollection, SortedDictionary.ValueCollection.Enumerator, SortedDictionary.ValueCollection.Enumerator, int, SortedDictionaryExtensions.GetEnumerator, SortedDictionaryExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSet.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSet.Tests.cs new file mode 100644 index 000000000..de3cd6fa6 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSet.Tests.cs @@ -0,0 +1,28 @@ +using NetFabric.Assertive; +using System.Collections.Generic; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Generic +{ + public class SortedSetTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_SortedSet_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = new SortedSet(source); + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, SortedSet.Enumerator, SortedSet.Enumerator, int, SortedSetExtensions.GetEnumerator, SortedSetExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Stack.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Stack.Tests.cs new file mode 100644 index 000000000..3483133e8 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Stack.Tests.cs @@ -0,0 +1,28 @@ +using NetFabric.Assertive; +using System.Collections.Generic; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Generic +{ + public class StackTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_Stack_Must_ReturnWrapper(int[] source) + { + // Arrange + var wrapped = new Stack(source); + + // Act + var result = wrapped.AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, Stack.Enumerator, Stack.Enumerator, int, StackExtensions.GetEnumerator, StackExtensions.GetEnumerator>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs index a6a47df45..d21e7e9a2 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs @@ -23,8 +23,8 @@ public void AsValueEnumerable_With_ImmutableArray_Must_ReturnWrapper(int[] sourc _ = result.Must() .BeOfType>() .BeEnumerableOf() - .BeEqualTo(source, testRefStructs: false); - result.SequenceEqual(source).Must().BeTrue(); + .BeEqualTo(wrapped, testRefStructs: false); + result.SequenceEqual(wrapped).Must().BeTrue(); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs index 873100528..44afc4031 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs @@ -16,7 +16,6 @@ public void AsValueEnumerable_With_ImmutableDictionary_Must_ReturnWrapper(int[] { // Arrange var wrapped = source.ToImmutableDictionary(item => item, default); - var expected = source.ToDictionary(item => item); // Act var result = wrapped.AsValueEnumerable(); @@ -25,7 +24,7 @@ public void AsValueEnumerable_With_ImmutableDictionary_Must_ReturnWrapper(int[] _ = result.Must() .BeOfType, ImmutableDictionary.Enumerator, ImmutableDictionary.Enumerator, KeyValuePair, ImmutableDictionaryExtensions.GetEnumerator, ImmutableDictionaryExtensions.GetEnumerator>>() .BeEnumerableOf>() - .BeEqualTo(expected); + .BeEqualTo(wrapped); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs index b09af691f..8b8c86381 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs @@ -22,7 +22,7 @@ public void AsValueEnumerable_With_ImmutableHashSet_Must_ReturnWrapper(int[] sou _ = result.Must() .BeOfType, ImmutableHashSet.Enumerator, ImmutableHashSet.Enumerator, int, ImmutableHashSetExtensions.GetEnumerator, ImmutableHashSetExtensions.GetEnumerator>>() .BeEnumerableOf() - .BeEqualTo(source); + .BeEqualTo(wrapped); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs index 52f311575..159ca6cbb 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs @@ -22,7 +22,7 @@ public void AsValueEnumerable_With_ImmutableList_Must_ReturnWrapper(int[] source _ = result.Must() .BeOfType, ImmutableList.Enumerator, ImmutableList.Enumerator, int, ImmutableListExtensions.GetEnumerator, ImmutableListExtensions.GetEnumerator>>() .BeEnumerableOf() - .BeEqualTo(source); + .BeEqualTo(wrapped); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs index cb5170afe..9537f752c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs @@ -22,7 +22,7 @@ public void AsValueEnumerable_With_ImmutableQueue_Must_ReturnWrapper(int[] sourc _ = result.Must() .BeOfType, ValueEnumerator, ImmutableQueue.Enumerator, int, ImmutableQueueExtensions.GetEnumerator, ImmutableQueueExtensions.GetEnumerator2>>() .BeEnumerableOf() - .BeEqualTo(source); + .BeEqualTo(wrapped); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs index b6fb4c7da..167ad7adc 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs @@ -17,7 +17,6 @@ public void AsValueEnumerable_With_ImmutableSortedDictionry_Must_ReturnWrapper(i // Arrange var dictionary = source.ToDictionary(item => item); var wrapped = ImmutableSortedDictionary.CreateRange(default, dictionary); - var expected = new SortedDictionary(dictionary); // Act var result = wrapped.AsValueEnumerable(); @@ -26,7 +25,7 @@ public void AsValueEnumerable_With_ImmutableSortedDictionry_Must_ReturnWrapper(i _ = result.Must() .BeOfType, ImmutableSortedDictionary.Enumerator, ImmutableSortedDictionary.Enumerator, KeyValuePair, ImmutableSortedDictionaryExtensions.GetEnumerator, ImmutableSortedDictionaryExtensions.GetEnumerator>>() .BeEnumerableOf>() - .BeEqualTo(expected); + .BeEqualTo(wrapped); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs index c4968d930..6c3f96577 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs @@ -15,7 +15,6 @@ public void AsValueEnumerable_With_ImmutableStack_Must_ReturnWrapper(int[] sourc { // Arrange var wrapped = ImmutableStack.Create(source); - var expected = new Stack(source); // Act var result = wrapped.AsValueEnumerable(); @@ -24,7 +23,7 @@ public void AsValueEnumerable_With_ImmutableStack_Must_ReturnWrapper(int[] sourc _ = result.Must() .BeOfType, ValueEnumerator, ImmutableStack.Enumerator, int, ImmutableStackExtensions.GetEnumerator, ImmutableStackExtensions.GetEnumerator2>>() .BeEnumerableOf() - .BeEqualTo(expected); + .BeEqualTo(wrapped); } } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs new file mode 100644 index 000000000..404d18218 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static class DictionaryExtensions + { + // Dictionary is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + // Same for Dictionary.KeyCollection and Dictionary.ValueCollection + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable, Dictionary.Enumerator, Dictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this Dictionary source) + where TKey : notnull + => ReadOnlyCollectionExtensions.AsValueEnumerable, Dictionary.Enumerator, KeyValuePair, GetEnumerator>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable.KeyCollection, Dictionary.KeyCollection.Enumerator, Dictionary.KeyCollection.Enumerator, TKey, GetEnumerator, GetEnumerator> AsValueEnumerable(this Dictionary.KeyCollection source) + where TKey : notnull + => ReadOnlyCollectionExtensions.AsValueEnumerable.KeyCollection, Dictionary.KeyCollection.Enumerator, TKey, GetEnumerator>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable.ValueCollection, Dictionary.ValueCollection.Enumerator, Dictionary.ValueCollection.Enumerator, TValue, GetEnumerator, GetEnumerator> AsValueEnumerable(this Dictionary.ValueCollection source) + where TKey : notnull + => ReadOnlyCollectionExtensions.AsValueEnumerable.ValueCollection, Dictionary.ValueCollection.Enumerator, TValue, GetEnumerator>(source); + + [StructLayout(LayoutKind.Auto)] + public readonly struct GetEnumerator + : IFunction, Dictionary.Enumerator> + , IFunction.KeyCollection, Dictionary.KeyCollection.Enumerator> + , IFunction.ValueCollection, Dictionary.ValueCollection.Enumerator> + where TKey : notnull + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary.Enumerator Invoke(Dictionary source) + => source.GetEnumerator(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary.KeyCollection.Enumerator Invoke(Dictionary.KeyCollection source) + => source.GetEnumerator(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary.ValueCollection.Enumerator Invoke(Dictionary.ValueCollection source) + => source.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs new file mode 100644 index 000000000..369e75988 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static class HashSetExtensions + { + // HashSet is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable, HashSet.Enumerator, HashSet.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this HashSet source) + => ReadOnlyCollectionExtensions.AsValueEnumerable, HashSet.Enumerator, TSource, GetEnumerator>(source); + + [StructLayout(LayoutKind.Auto)] + public readonly struct GetEnumerator + : IFunction, HashSet.Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public HashSet.Enumerator Invoke(HashSet source) + => source.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs new file mode 100644 index 000000000..f14f1d7c7 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static class LinkedListExtensions + { + // LinkedList is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable, LinkedList.Enumerator, LinkedList.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this LinkedList source) + => ReadOnlyCollectionExtensions.AsValueEnumerable, LinkedList.Enumerator, TSource, GetEnumerator>(source); + + [StructLayout(LayoutKind.Auto)] + public readonly struct GetEnumerator + : IFunction, LinkedList.Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public LinkedList.Enumerator Invoke(LinkedList source) + => source.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs index d16617689..2343f0ba2 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs @@ -1,9 +1,11 @@ +using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace NetFabric.Hyperlinq { - public static partial class ListExtensions + public static class ListExtensions { // List is simply converted to ArraySegment and share its IValueEnumerable wrapper. // It's not converted to ReadOnlySpan because its enumerables cannot be casted to IEnumerable, restricting its use. @@ -13,5 +15,41 @@ public static partial class ListExtensions public static ArrayExtensions.ArraySegmentValueEnumerable AsValueEnumerable(this List source) => source.AsArraySegment().AsValueEnumerable(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static ArraySegment AsArraySegment(this List source) + => new(source.GetItems(), 0, source.Count); + + internal static List AsList(this TSource[] source) + { + // ReSharper disable once HeapView.ObjectAllocation.Evident + var result = new List(); + var layout = Unsafe.As, ListLayout>(ref result); + layout.items = source; + layout.size = source.Length; + result.Capacity = source.Length; + return result; + } + + // ReSharper disable once ClassNeverInstantiated.Local +#if NET5_0_OR_GREATER + [SkipLocalsInit] +#endif + class ListLayout + { + public TSource[]? items; + +#if !NETCOREAPP3_0_OR_GREATER +#pragma warning disable IDE0051 // Remove unused private members +#pragma warning disable 169 + readonly object? syncRoot; +#pragma warning restore 169 +#pragma warning restore IDE0051 // Remove unused private members +#endif + public int size; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static TSource[] GetItems(this List source) + => Unsafe.As, ListLayout>(ref source).items ?? Array.Empty(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs new file mode 100644 index 000000000..042612cc9 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs @@ -0,0 +1,29 @@ +#if NET60_OR_GREATER + +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + + public static class PriorityQueueExtensions + { + // PriorityQueue is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable, PriorityQueue.Enumerator, PriorityQueue.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this PriorityQueue source) + => ReadOnlyCollectionExtensions.AsValueEnumerable, PriorityQueue.Enumerator, TSource, GetEnumerator>(source); + + [StructLayout(LayoutKind.Auto)] + public readonly struct GetEnumerator + : IFunction, PriorityQueue.Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public PriorityQueue.Enumerator Invoke(PriorityQueue source) + => source.GetEnumerator(); + } + } +} + +#endif \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs new file mode 100644 index 000000000..6080caba0 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static class QueueExtensions + { + // Queue is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable, Queue.Enumerator, Queue.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this Queue source) + => ReadOnlyCollectionExtensions.AsValueEnumerable, Queue.Enumerator, TSource, GetEnumerator>(source); + + [StructLayout(LayoutKind.Auto)] + public readonly struct GetEnumerator + : IFunction, Queue.Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Queue.Enumerator Invoke(Queue source) + => source.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs new file mode 100644 index 000000000..ef820ddcc --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static class SortedDictionaryExtensions + { + // SortedDictionary is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + // Same for SortedDictionary.KeyCollection and SortedDictionary.ValueCollection + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable, SortedDictionary.Enumerator, SortedDictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedDictionary source) + where TKey : notnull + => ReadOnlyCollectionExtensions.AsValueEnumerable, SortedDictionary.Enumerator, KeyValuePair, GetEnumerator>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable.KeyCollection, SortedDictionary.KeyCollection.Enumerator, SortedDictionary.KeyCollection.Enumerator, TKey, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedDictionary.KeyCollection source) + where TKey : notnull + => ReadOnlyCollectionExtensions.AsValueEnumerable.KeyCollection, SortedDictionary.KeyCollection.Enumerator, TKey, GetEnumerator>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable.ValueCollection, SortedDictionary.ValueCollection.Enumerator, SortedDictionary.ValueCollection.Enumerator, TValue, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedDictionary.ValueCollection source) + where TKey : notnull + => ReadOnlyCollectionExtensions.AsValueEnumerable.ValueCollection, SortedDictionary.ValueCollection.Enumerator, TValue, GetEnumerator>(source); + + [StructLayout(LayoutKind.Auto)] + public readonly struct GetEnumerator + : IFunction, SortedDictionary.Enumerator> + , IFunction.KeyCollection, SortedDictionary.KeyCollection.Enumerator> + , IFunction.ValueCollection, SortedDictionary.ValueCollection.Enumerator> + where TKey : notnull + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SortedDictionary.Enumerator Invoke(SortedDictionary source) + => source.GetEnumerator(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SortedDictionary.KeyCollection.Enumerator Invoke(SortedDictionary.KeyCollection source) + => source.GetEnumerator(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SortedDictionary.ValueCollection.Enumerator Invoke(SortedDictionary.ValueCollection source) + => source.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs new file mode 100644 index 000000000..c5cedc01b --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static class SortedSetExtensions + { + // SortedSet is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable, SortedSet.Enumerator, SortedSet.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedSet source) + => ReadOnlyCollectionExtensions.AsValueEnumerable, SortedSet.Enumerator, TSource, GetEnumerator>(source); + + [StructLayout(LayoutKind.Auto)] + public readonly struct GetEnumerator + : IFunction, SortedSet.Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SortedSet.Enumerator Invoke(SortedSet source) + => source.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs new file mode 100644 index 000000000..ad56d19c5 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static class StackExtensions + { + // Stack is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyCollectionExtensions.ValueEnumerable, Stack.Enumerator, Stack.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this Stack source) + => ReadOnlyCollectionExtensions.AsValueEnumerable, Stack.Enumerator, TSource, GetEnumerator>(source); + + [StructLayout(LayoutKind.Auto)] + public readonly struct GetEnumerator + : IFunction, Stack.Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Stack.Enumerator Invoke(Stack source) + => source.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs index ddbbacf56..2a51d9fa9 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs @@ -19,6 +19,7 @@ public readonly struct GetEnumerator : IFunction, ImmutableDictionary.Enumerator> where TKey: notnull { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImmutableDictionary.Enumerator Invoke(ImmutableDictionary source) => source.GetEnumerator(); } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs index c3f1cdd7c..7f899c11c 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs @@ -16,6 +16,7 @@ public static class ImmutableHashSetExtensions public readonly struct GetEnumerator : IFunction, ImmutableHashSet.Enumerator> { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImmutableHashSet.Enumerator Invoke(ImmutableHashSet source) => source.GetEnumerator(); } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs index e60a32bd5..f759387ca 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs @@ -16,6 +16,7 @@ public static class ImmutableListExtensions public readonly struct GetEnumerator : IFunction, ImmutableList.Enumerator> { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImmutableList.Enumerator Invoke(ImmutableList source) => source.GetEnumerator(); } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs index 569daa154..e58289c03 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs @@ -19,6 +19,7 @@ public static class ImmutableQueueExtensions public readonly struct GetEnumerator : IFunction, ValueEnumerator> { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerator Invoke(ImmutableQueue source) => new(((IEnumerable)source).GetEnumerator()); } @@ -27,6 +28,7 @@ public ValueEnumerator Invoke(ImmutableQueue source) public readonly struct GetEnumerator2 : IFunction, ImmutableQueue.Enumerator> { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImmutableQueue.Enumerator Invoke(ImmutableQueue source) => source.GetEnumerator(); } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs index 0d94acc82..c336609af 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs @@ -19,6 +19,7 @@ public readonly struct GetEnumerator : IFunction, ImmutableSortedDictionary.Enumerator> where TKey: notnull { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImmutableSortedDictionary.Enumerator Invoke(ImmutableSortedDictionary source) => source.GetEnumerator(); } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs index 95de76a42..a153a1d07 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs @@ -19,6 +19,7 @@ public static class ImmutableStackExtensions public readonly struct GetEnumerator : IFunction, ValueEnumerator> { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerator Invoke(ImmutableStack source) => new(((IEnumerable)source).GetEnumerator()); } @@ -27,6 +28,7 @@ public ValueEnumerator Invoke(ImmutableStack source) public readonly struct GetEnumerator2 : IFunction, ImmutableStack.Enumerator> { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImmutableStack.Enumerator Invoke(ImmutableStack source) => source.GetEnumerator(); } diff --git a/NetFabric.Hyperlinq/Utils/ListExtensions.cs b/NetFabric.Hyperlinq/Utils/ListExtensions.cs deleted file mode 100644 index 2416db961..000000000 --- a/NetFabric.Hyperlinq/Utils/ListExtensions.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ListExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ArraySegment AsArraySegment(this List source) - => new(source.GetItems(), 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static Span AsSpan(this List source) -#if NET5_0_OR_GREATER - => CollectionsMarshal.AsSpan(source); -#else - => source.GetItems().AsSpan().Slice(0, source.Count); -#endif - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static Memory AsMemory(this List source) - => source.GetItems().AsMemory().Slice(0, source.Count); - - - internal static List AsList(this TSource[] source) - { - var result = new List(); - var layout = Unsafe.As, ListLayout>(ref result); - layout.items = source; - layout.size = source.Length; - result.Capacity = source.Length; - return result; - } - - // ReSharper disable once ClassNeverInstantiated.Local -#if NET5_0_OR_GREATER - [SkipLocalsInit] -#endif - class ListLayout - { - public TSource[]? items; - -#if !NETCOREAPP3_0_OR_GREATER -#pragma warning disable IDE0051 // Remove unused private members -#pragma warning disable 169 - readonly object? syncRoot; -#pragma warning restore 169 -#pragma warning restore IDE0051 // Remove unused private members -#endif - public int size; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TSource[] GetItems(this List source) - => Unsafe.As, ListLayout>(ref source).items!; - } -} From 245967032d08d1b1acc378a80a71e224eb97ed86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Mon, 8 Mar 2021 22:51:45 +0000 Subject: [PATCH 15/61] Update benchmarks (#345) * Update benchmarks * Fix * Update benchmark results * Extend AsValueEnumerable and AsAsyncValueEnumerable to more scenarios * Update benchmark results * Update benchmark results * Fixes * Update benchmark results * Remove unnecessary benchmark --- Benchmarks/AllBenchmarks.md | 78 ++- Benchmarks/AnyBenchmarks.md | 69 ++- Benchmarks/AnyPredicateBenchmarks.md | 69 ++- Benchmarks/ArrayIterationBenchmarks.md | 35 +- Benchmarks/ContainsBenchmarks.md | 49 +- Benchmarks/ContainsComparerBenchmarks.md | 67 +-- Benchmarks/CountBenchmarks.md | 63 ++- Benchmarks/DistinctBenchmarks.md | 65 +-- Benchmarks/ElementAtBenchmarks.md | 67 +-- Benchmarks/EmptyBenchmarks.md | 25 +- Benchmarks/FirstBenchmarks.md | 67 +-- Benchmarks/IterationBenchmarks.md | 28 - Benchmarks/RangeBenchmarks.md | 27 +- Benchmarks/RangeToArrayBenchmarks.md | 30 +- Benchmarks/RepeatBenchmarks.md | 28 +- Benchmarks/RepeatToArrayBenchmarks.md | 32 +- Benchmarks/ReturnBenchmarks.md | 19 +- Benchmarks/SelectBenchmarks.md | 66 ++- Benchmarks/SelectCountBenchmarks.md | 83 ++- Benchmarks/SelectManyBenchmarks.md | 45 +- Benchmarks/SelectSumBenchmarks.md | 57 +- Benchmarks/SelectToArrayBenchmarks.md | 80 ++- Benchmarks/SelectToListBenchmarks.md | 80 +-- Benchmarks/SingleBenchmarks.md | 45 +- Benchmarks/SkipTakeBenchmarks.md | 95 ++-- Benchmarks/SumBenchmarks.md | 57 +- Benchmarks/ToArrayBenchmarks.md | 59 +-- Benchmarks/ToListBenchmarks.md | 81 +-- Benchmarks/WhereBenchmarks.md | 79 +-- Benchmarks/WhereCountBenchmarks.md | 65 +-- Benchmarks/WhereFirstBenchmarks.md | 71 ++- Benchmarks/WhereSelectBenchmarks.md | 79 +-- Benchmarks/WhereSelectCountBenchmarks.md | 63 ++- Benchmarks/WhereSingleBenchmarks.md | 71 ++- Benchmarks/WhereToArrayBenchmarks.md | 63 ++- Benchmarks/WhereToListBenchmarks.md | 63 ++- Directory.Build.props | 1 + .../AsyncFunctionWrapper.cs | 10 + .../FunctionInWrapper.cs | 3 + .../FunctionWrapper.cs | 11 + .../ValueEnumerable.cs | 12 +- .../Benchmarks/AllBenchmarks.cs | 36 +- .../Benchmarks/AnyBenchmarks.cs | 36 +- .../Benchmarks/AnyPredicateBenchmarks.cs | 36 +- .../Benchmarks/ArrayIterationBenchmarks.cs | 46 +- .../Benchmarks/ContainsBenchmarks.cs | 186 +++---- .../Benchmarks/ContainsComparerBenchmarks.cs | 48 +- .../Benchmarks/CountBenchmarks.cs | 36 +- .../Benchmarks/DistinctBenchmarks.cs | 38 +- .../Benchmarks/ElementAtBenchmarks.cs | 46 +- .../Benchmarks/FirstBenchmarks.cs | 46 +- .../Benchmarks/IterationBenchmarks.cs | 72 --- .../Benchmarks/SelectBenchmarks.cs | 500 ++++++++++-------- .../Benchmarks/SelectCountBenchmarks.cs | 45 +- .../Benchmarks/SelectManyBenchmarks.cs | 32 +- .../Benchmarks/SelectSumBenchmarks.cs | 325 ++++++------ .../Benchmarks/SelectToArrayBenchmarks.cs | 52 +- .../Benchmarks/SelectToListBenchmarks.cs | 45 +- .../Benchmarks/SingleBenchmarks.cs | 34 +- .../Benchmarks/SkipTakeBenchmarks.cs | 32 +- .../Benchmarks/SumBenchmarks.cs | 274 +++++----- .../Benchmarks/ToArrayBenchmarks.cs | 34 +- .../Benchmarks/ToListBenchmarks.cs | 44 +- .../Benchmarks/WhereBenchmarks.cs | 61 ++- .../Benchmarks/WhereCountBenchmarks.cs | 30 +- .../Benchmarks/WhereFirstBenchmarks.cs | 46 +- .../Benchmarks/WhereSelectBenchmarks.cs | 137 ++++- .../Benchmarks/WhereSelectCountBenchmarks.cs | 74 +-- .../Benchmarks/WhereSingleBenchmarks.cs | 46 +- .../Benchmarks/WhereToArrayBenchmarks.cs | 44 +- .../Benchmarks/WhereToListBenchmarks.cs | 44 +- NetFabric.Hyperlinq.Benchmarks/Program.cs | 12 +- .../Utils/TestAsyncEnumerable.cs | 20 +- .../Utils/TestCollection.cs | 57 +- .../Utils/TestEnumerable.cs | 36 +- .../Utils/TestList.cs | 40 +- NetFabric.Hyperlinq.Benchmarks/Utils/Utils.cs | 6 + .../Count.ValueReadOnlyCollection.Tests.cs | 4 +- .../Sum/Sum.ValueReadOnlyCollection.Tests.cs | 8 +- ...ValueEnumerable'1.AsyncEnumerable.Tests.cs | 56 ++ ...Enumerable'1.AsyncValueEnumerable.Tests.cs | 56 ++ ...alueEnumerable'6.AsyncEnumerable.Tests.cs} | 55 +- ...Enumerable'6.AsyncValueEnumerable.Tests.cs | 84 +++ ...ncValueEnumerable.AsyncEnumerable.Tests.cs | 145 ----- ...ueEnumerable.AsyncValueEnumerable.Tests.cs | 41 -- ...> AsValueEnumerable'6.Enumerable.Tests.cs} | 0 ...eEnumerable'6.ReadOnlyCollection.Tests.cs} | 0 ...> AsValueEnumerable.ArraySegment.Tests.cs} | 0 .../AsValueEnumerable.ReadOnlyList.Tests.cs | 2 +- ...AsValueEnumerable.ReadOnlyMemory.Tests.cs} | 0 ...> AsValueEnumerable.ReadOnlySpan.Tests.cs} | 0 ...AsValueEnumerable.ValueEnumerable.Tests.cs | 25 +- .../ToArray.ValueReadOnlyCollection.Tests.cs | 28 +- .../ToList.ValueReadOnlyCollection.Tests.cs | 16 +- ...ElementAt.ValueReadOnlyCollection.Tests.cs | 36 +- .../First.ValueReadOnlyCollection.Tests.cs | 24 +- .../Single.ValueReadOnlyCollection.Tests.cs | 36 +- .../Where.ValueReadOnlyCollection.Tests.cs | 8 +- .../WhereAt.ValueReadOnlyCollection.Tests.cs | 8 +- ...ereSelect.ValueReadOnlyCollection.Tests.cs | 8 +- .../Skip.ValueReadOnlyCollection.Tests.cs | 2 +- .../Take.ValueReadOnlyCollection.Tests.cs | 4 +- .../Select.ValueReadOnlyCollection.Tests.cs | 8 +- .../SelectAt.ValueReadOnlyCollection.Tests.cs | 8 +- .../All/All.ValueReadOnlyCollection.Tests.cs | 8 +- .../Any/Any.ValueReadOnlyCollection.Tests.cs | 12 +- .../Contains.ValueReadOnlyCollection.Tests.cs | 32 +- .../Utils/Wrappers/Wrap.AsAsyncEnumerable.cs | 16 +- .../Wrappers/Wrap.AsAsyncValueEnumerable.cs | 15 +- .../Utils/Wrappers/Wrap.AsCollection.cs | 4 +- .../Utils/Wrappers/Wrap.AsEnumerable.cs | 16 + .../Utils/Wrappers/Wrap.AsList.cs | 1 + .../Wrappers/Wrap.AsReadOnlyCollection.cs | 11 + .../Utils/Wrappers/Wrap.AsReadOnlyList.cs | 4 + .../Utils/Wrappers/Wrap.AsValueCollection.cs | 15 + .../Utils/Wrappers/Wrap.AsValueEnumerable.cs | 16 +- .../Utils/Wrappers/Wrap.AsValueList.cs | 7 + .../Wrap.AsValueReadOnlyCollection.cs | 15 + .../Wrappers/Wrap.AsValueReadOnlyList.cs | 7 + .../Utils/Wrappers/Wrap.AsyncEnumerator.cs | 7 +- .../Utils/Wrappers/Wrap.Enumerator.cs | 11 +- .../Aggregation/Sum/Sum.ReadOnlyList.cs | 2 +- ...sAsyncValueEnumerable'1.AsyncEnumerable.cs | 103 ++++ ...cValueEnumerable'1.AsyncValueEnumerable.cs | 93 ++++ ...sAsyncValueEnumerable'6.AsyncEnumerable.cs | 170 ++++++ ...cValueEnumerable'6.AsyncValueEnumerable.cs | 170 ++++++ .../AsAsyncValueEnumerable.AsyncEnumerable.cs | 85 --- ...yncValueEnumerable.AsyncValueEnumerable.cs | 15 - .../AsAsyncValueEnumerable.ValueEnumerable.cs | 80 --- .../AsyncValueEnumerator.cs | 35 ++ .../AsValueEnumerable'1.Enumerable.cs | 7 + .../AsValueEnumerable'1.ReadOnlyCollection.cs | 10 + .../AsValueEnumerable'1.ValueEnumerable.cs | 95 ++++ ...lueEnumerable'1.ValueReadOnlyCollection.cs | 144 +++++ .../AsValueEnumerable'6.Enumerable.cs | 7 + .../AsValueEnumerable'6.ReadOnlyCollection.cs | 6 + .../AsValueEnumerable'6.ValueEnumerable.cs | 172 ++++++ ...lueEnumerable'6.ValueReadOnlyCollection.cs | 224 ++++++++ .../AsValueEnumerable.ReadOnlyList.cs | 8 +- .../AsValueEnumerable.ReadOnlyMemory.cs | 2 +- .../AsValueEnumerable.ReadOnlySpan.cs | 2 +- .../AsValueEnumerable.ValueEnumerable.cs | 15 - .../AsValueEnumerable.ValuesReadOnlyList.cs | 269 ++++++++++ .../NetFabric.Hyperlinq.csproj | 5 +- .../SelectMany/SelectMany.ArraySegment.cs | 4 +- .../SelectMany/SelectMany.ReadOnlyList.cs | 4 +- .../SelectMany/SelectMany.ReadOnlyMemory.cs | 4 +- .../SelectMany/SelectMany.ValueEnumerable.cs | 4 +- .../Quantifier/Any/Any.ReadOnlySpan.cs | 10 +- .../Quantifier/Any/Any.Span.cs | 10 +- .../ContainsVector.ReadOnlySpan.cs | 2 +- .../ContainsVector/ContainsVector.Span.cs | 2 +- README.md | 173 +++--- 153 files changed, 4613 insertions(+), 3031 deletions(-) delete mode 100644 Benchmarks/IterationBenchmarks.md delete mode 100644 NetFabric.Hyperlinq.Benchmarks/Benchmarks/IterationBenchmarks.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs rename NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/{AsAsyncValueEnumerable.ValueEnumerable.Tests.cs => AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs} (50%) create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.Tests.cs rename NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/{AsValueEnumerable'6.Enumerable.cs => AsValueEnumerable'6.Enumerable.Tests.cs} (100%) rename NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/{AsValueEnumerable'6.ReadOnlyCollection.cs => AsValueEnumerable'6.ReadOnlyCollection.Tests.cs} (100%) rename NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/{AsValueEnumerable.ArraySegment.cs => AsValueEnumerable.ArraySegment.Tests.cs} (100%) rename NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/{AsValueEnumerable.ReadOnlyMemory.cs => AsValueEnumerable.ReadOnlyMemory.Tests.cs} (100%) rename NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/{AsValueEnumerable.ReadOnlySpan.cs => AsValueEnumerable.ReadOnlySpan.Tests.cs} (100%) create mode 100644 NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsyncValueEnumerator.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs diff --git a/Benchmarks/AllBenchmarks.md b/Benchmarks/AllBenchmarks.md index 6c57d8713..79479cd75 100644 --- a/Benchmarks/AllBenchmarks.md +++ b/Benchmarks/AllBenchmarks.md @@ -4,52 +4,50 @@ [AllBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs) ### References: -- Linq: 5.0.0-preview.7.20364.11 -- System.Linq.Async: [4.1.1](https://www.nuget.org/packages/System.Linq.Async/4.1.1) -- System.Interactive: [4.1.1](https://www.nuget.org/packages/System.Interactive/4.1.1) -- System.Interactive.Async: [4.1.1](https://www.nuget.org/packages/System.Interactive.Async/4.1.1) -- StructLinq: [0.19.2](https://www.nuget.org/packages/StructLinq/0.19.2) -- NetFabric.Hyperlinq: [3.0.0-beta26](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta26) +- Linq: 5.0.3 +- System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) +- System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) +- System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) +- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=5.0.100-preview.7.20366.6 - [Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.36411, CoreFX 5.0.20.36411), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.0 (CoreCLR 5.0.20.36411, CoreFX 5.0.20.36411), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 528.0 ns | 5.57 ns | 4.94 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 191.4 ns | 1.67 ns | 1.56 ns | 0.36 | 0.00 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 166.2 ns | 1.88 ns | 1.76 ns | 0.32 | 0.00 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 215.8 ns | 2.12 ns | 1.99 ns | 0.41 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 737.5 ns | 6.24 ns | 5.84 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 199.4 ns | 2.30 ns | 1.92 ns | 0.27 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 741.2 ns | 6.95 ns | 6.50 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 233.7 ns | 3.46 ns | 3.24 ns | 0.32 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 737.0 ns | 6.21 ns | 5.80 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 401.4 ns | 3.81 ns | 3.18 ns | 0.54 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,176.1 ns | 25.71 ns | 21.47 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 331.5 ns | 3.55 ns | 3.32 ns | 0.15 | 0.00 | 0.0191 | - | - | 40 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 570.6 ns | 5.53 ns | 5.18 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 523.1 ns | 4.70 ns | 4.40 ns | 0.92 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 572.8 ns | 5.56 ns | 5.20 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 520.5 ns | 7.43 ns | 6.59 ns | 0.91 | 0.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 572.2 ns | 3.72 ns | 3.11 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 376.9 ns | 2.50 ns | 2.22 ns | 0.66 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,114.6 ns | 19.98 ns | 18.69 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 358.6 ns | 2.02 ns | 1.88 ns | 0.17 | 0.00 | 0.0305 | - | - | 64 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 587.8 ns | 1.31 ns | 1.10 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 192.6 ns | 0.41 ns | 0.37 ns | 0.33 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 744.7 ns | 1.03 ns | 0.92 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 198.2 ns | 0.44 ns | 0.34 ns | 0.27 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 745.6 ns | 2.88 ns | 2.55 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 200.8 ns | 1.18 ns | 0.98 ns | 0.27 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 749.5 ns | 6.41 ns | 6.00 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 978.6 ns | 2.46 ns | 2.30 ns | 1.31 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,159.0 ns | 3.01 ns | 2.82 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 317.9 ns | 0.81 ns | 0.75 ns | 0.15 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 589.4 ns | 3.72 ns | 3.11 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 538.8 ns | 1.38 ns | 1.23 ns | 0.91 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 587.3 ns | 1.53 ns | 1.44 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 514.3 ns | 2.35 ns | 1.83 ns | 0.88 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 537.9 ns | 1.32 ns | 1.10 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 925.7 ns | 2.96 ns | 2.31 ns | 1.72 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,057.2 ns | 3.16 ns | 2.95 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 345.4 ns | 0.48 ns | 0.45 ns | 0.17 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/AnyBenchmarks.md b/Benchmarks/AnyBenchmarks.md index 9d80926bb..fbe4e7b45 100644 --- a/Benchmarks/AnyBenchmarks.md +++ b/Benchmarks/AnyBenchmarks.md @@ -4,51 +4,50 @@ [AnyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 8.7865 ns | 0.0358 ns | 0.0318 ns | 1.000 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 0.0000 ns | 0.0000 ns | 0.0000 ns | 0.000 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 0.5244 ns | 0.0186 ns | 0.0165 ns | 0.060 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 0.2542 ns | 0.0066 ns | 0.0059 ns | 0.029 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 20.5024 ns | 0.1154 ns | 0.1023 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 12.4688 ns | 0.0330 ns | 0.0293 ns | 0.61 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.8538 ns | 0.0168 ns | 0.0140 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 4.6245 ns | 0.0119 ns | 0.0105 ns | 0.95 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.5336 ns | 0.0157 ns | 0.0139 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.7812 ns | 0.0093 ns | 0.0087 ns | 0.32 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 66.4073 ns | 0.3688 ns | 0.3080 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 60.3088 ns | 0.1136 ns | 0.1007 ns | 0.91 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 18.3779 ns | 0.0678 ns | 0.0634 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 10.5758 ns | 0.0991 ns | 0.0828 ns | 0.58 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.9100 ns | 0.0256 ns | 0.0239 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.7918 ns | 0.0128 ns | 0.0107 ns | 0.36 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.5565 ns | 0.0178 ns | 0.0158 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.8166 ns | 0.0157 ns | 0.0139 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 62.4382 ns | 0.1938 ns | 0.1618 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 62.1935 ns | 0.1632 ns | 0.1363 ns | 1.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 9.399 ns | 0.0537 ns | 0.0419 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.945 ns | 0.0236 ns | 0.0209 ns | 0.85 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 20.241 ns | 0.0537 ns | 0.0502 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 10.652 ns | 0.0210 ns | 0.0164 ns | 0.53 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 4.684 ns | 0.0171 ns | 0.0160 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.330 ns | 0.0272 ns | 0.0255 ns | 1.78 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 5.399 ns | 0.0244 ns | 0.0229 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.548 ns | 0.0258 ns | 0.0452 ns | 0.29 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 67.638 ns | 0.2277 ns | 0.2130 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 64.182 ns | 0.1641 ns | 0.1281 ns | 0.95 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 17.738 ns | 0.0473 ns | 0.0369 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 9.871 ns | 0.0625 ns | 0.0554 ns | 0.56 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.702 ns | 0.0219 ns | 0.0194 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.799 ns | 0.0076 ns | 0.0067 ns | 0.38 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 5.409 ns | 0.0167 ns | 0.0139 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.807 ns | 0.0114 ns | 0.0107 ns | 0.33 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 65.851 ns | 1.3129 ns | 2.4007 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 63.001 ns | 0.1889 ns | 0.1767 ns | 0.94 | 0.05 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/AnyPredicateBenchmarks.md b/Benchmarks/AnyPredicateBenchmarks.md index 9ef69d1eb..31ce239d6 100644 --- a/Benchmarks/AnyPredicateBenchmarks.md +++ b/Benchmarks/AnyPredicateBenchmarks.md @@ -4,51 +4,50 @@ [AnyPredicateBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 557.44 ns | 1.160 ns | 1.028 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 187.98 ns | 0.259 ns | 0.230 ns | 0.34 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 189.53 ns | 0.548 ns | 0.458 ns | 0.34 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 190.13 ns | 0.451 ns | 0.422 ns | 0.34 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 739.29 ns | 1.522 ns | 1.349 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 203.08 ns | 0.430 ns | 0.359 ns | 0.27 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 737.14 ns | 1.366 ns | 1.211 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 241.16 ns | 0.724 ns | 0.677 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 738.33 ns | 1.090 ns | 1.020 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 393.22 ns | 0.587 ns | 0.549 ns | 0.53 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,142.07 ns | 4.926 ns | 4.607 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 80.78 ns | 0.161 ns | 0.150 ns | 0.04 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 581.65 ns | 0.687 ns | 0.609 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 585.81 ns | 2.005 ns | 1.674 ns | 1.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 585.45 ns | 4.103 ns | 3.426 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 535.46 ns | 1.845 ns | 1.725 ns | 0.91 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 515.11 ns | 1.186 ns | 1.109 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 349.71 ns | 0.985 ns | 0.873 ns | 0.68 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,060.41 ns | 4.440 ns | 3.936 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 86.05 ns | 0.537 ns | 0.449 ns | 0.04 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 540.87 ns | 1.515 ns | 1.182 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 191.82 ns | 0.300 ns | 0.251 ns | 0.35 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 775.48 ns | 1.497 ns | 1.250 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 198.03 ns | 0.750 ns | 0.585 ns | 0.26 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 745.08 ns | 1.510 ns | 1.413 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 204.31 ns | 4.074 ns | 4.184 ns | 0.27 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 745.18 ns | 2.165 ns | 1.808 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 605.35 ns | 1.579 ns | 1.477 ns | 0.81 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,179.82 ns | 5.170 ns | 4.836 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 89.24 ns | 0.240 ns | 0.224 ns | 0.04 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 587.15 ns | 1.060 ns | 0.992 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 539.20 ns | 3.402 ns | 2.656 ns | 0.92 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 536.71 ns | 1.205 ns | 1.068 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 550.71 ns | 11.016 ns | 12.686 ns | 1.03 | 0.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 538.66 ns | 4.845 ns | 4.046 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 605.80 ns | 2.073 ns | 1.618 ns | 1.12 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,073.97 ns | 4.513 ns | 4.001 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 86.68 ns | 1.010 ns | 0.789 ns | 0.04 | 0.00 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 9f43bfd0b..0a8544489 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -4,33 +4,34 @@ [ArrayIterationBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | -|----------------------------- |--------- |----------:|----------:|----------:|------:|--------:| -| Foreach | 10000000 | 5.994 ms | 0.1155 ms | 0.1024 ms | 1.00 | 0.00 | -| For | 10000000 | 4.917 ms | 0.0722 ms | 0.0675 ms | 0.82 | 0.02 | -| For_Unsafe | 10000000 | 6.019 ms | 0.0699 ms | 0.0654 ms | 1.01 | 0.02 | -| ForAdamczewski | 10000000 | 4.764 ms | 0.0291 ms | 0.0272 ms | 0.80 | 0.02 | -| ForAdamczewskiUnsafe | 10000000 | 4.169 ms | 0.0829 ms | 0.0921 ms | 0.70 | 0.03 | -| Span | 10000000 | 4.720 ms | 0.0553 ms | 0.0491 ms | 0.79 | 0.02 | -| Memory | 10000000 | 6.107 ms | 0.0278 ms | 0.0260 ms | 1.02 | 0.02 | -| ArraySegment_Foreach | 10000000 | 28.274 ms | 0.0372 ms | 0.0311 ms | 4.73 | 0.08 | -| ArraySegment_For | 10000000 | 5.948 ms | 0.0457 ms | 0.0381 ms | 0.99 | 0.02 | -| ArraySegment_Wrapper_Foreach | 10000000 | 6.136 ms | 0.0263 ms | 0.0219 ms | 1.03 | 0.02 | +| Method | Count | Mean | Error | StdDev | Ratio | +|----------------------------- |--------- |----------:|----------:|----------:|------:| +| Foreach | 10000000 | 5.695 ms | 0.0092 ms | 0.0086 ms | 1.00 | +| For | 10000000 | 4.515 ms | 0.0097 ms | 0.0086 ms | 0.79 | +| For_Unsafe | 10000000 | 4.460 ms | 0.0114 ms | 0.0107 ms | 0.78 | +| ForAdamczewski | 10000000 | 4.371 ms | 0.0168 ms | 0.0149 ms | 0.77 | +| ForAdamczewskiUnsafe | 10000000 | 3.878 ms | 0.0153 ms | 0.0128 ms | 0.68 | +| Span | 10000000 | 4.459 ms | 0.0083 ms | 0.0069 ms | 0.78 | +| Memory | 10000000 | 5.725 ms | 0.0208 ms | 0.0184 ms | 1.01 | +| ArraySegment_Foreach | 10000000 | 28.060 ms | 0.0959 ms | 0.0748 ms | 4.93 | +| ArraySegment_For | 10000000 | 5.701 ms | 0.0169 ms | 0.0150 ms | 1.00 | +| ArraySegment_Wrapper_Foreach | 10000000 | 14.684 ms | 0.0342 ms | 0.0320 ms | 2.58 | diff --git a/Benchmarks/ContainsBenchmarks.md b/Benchmarks/ContainsBenchmarks.md index 1de327e5b..b4d98a14b 100644 --- a/Benchmarks/ContainsBenchmarks.md +++ b/Benchmarks/ContainsBenchmarks.md @@ -4,28 +4,51 @@ [ContainsBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs) ### References: -- Linq: 5.0.2 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta34](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta34) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=5.0.200-preview.20614.14 - [Host] : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 Categories=Array +Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|-------------------- |------ |---------:|---------:|---------:|------:|--------:|------:|------:|------:|----------:| -| Linq_Array | 100 | 55.27 ns | 1.138 ns | 1.479 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | 100 | 49.53 ns | 1.536 ns | 4.528 ns | 0.89 | 0.04 | - | - | - | - | -| Hyperlinq_Span | 100 | 96.52 ns | 1.965 ns | 3.442 ns | 1.76 | 0.09 | - | - | - | - | -| Hyperlinq_Span_SIMD | 100 | 19.46 ns | 0.264 ns | 0.449 ns | 0.35 | 0.01 | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 40.31 ns | 0.211 ns | 0.176 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 30.98 ns | 0.124 ns | 0.103 ns | 0.77 | 0.00 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 24.17 ns | 0.108 ns | 0.096 ns | 0.60 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 654.06 ns | 1.947 ns | 1.520 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 342.42 ns | 0.897 ns | 0.795 ns | 0.52 | 0.00 | 0.0191 | - | - | 40 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 34.21 ns | 0.205 ns | 0.171 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 38.02 ns | 0.124 ns | 0.110 ns | 1.11 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 35.23 ns | 0.169 ns | 0.150 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 37.38 ns | 0.183 ns | 0.153 ns | 1.06 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,083.85 ns | 5.835 ns | 5.172 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,436.75 ns | 3.264 ns | 2.726 ns | 0.69 | 0.00 | 0.0191 | - | - | 40 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 416.22 ns | 1.444 ns | 1.280 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 530.67 ns | 7.926 ns | 7.414 ns | 1.27 | 0.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 33.91 ns | 0.148 ns | 0.131 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 34.34 ns | 0.523 ns | 0.489 ns | 1.01 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 32.59 ns | 0.119 ns | 0.112 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 35.85 ns | 0.358 ns | 0.317 ns | 1.10 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,931.08 ns | 5.581 ns | 4.947 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,092.36 ns | 22.838 ns | 21.363 ns | 1.08 | 0.01 | 0.0305 | - | - | 64 B | diff --git a/Benchmarks/ContainsComparerBenchmarks.md b/Benchmarks/ContainsComparerBenchmarks.md index 7d6ad1322..dabeee64c 100644 --- a/Benchmarks/ContainsComparerBenchmarks.md +++ b/Benchmarks/ContainsComparerBenchmarks.md @@ -4,49 +4,50 @@ [ContainsComparerBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------- |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 568.2 ns | 2.19 ns | 2.05 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 241.1 ns | 0.68 ns | 0.60 ns | 0.42 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 192.6 ns | 0.76 ns | 0.71 ns | 0.34 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 219.4 ns | 0.81 ns | 0.72 ns | 0.39 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 744.5 ns | 1.64 ns | 1.37 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 257.5 ns | 0.97 ns | 0.91 ns | 0.35 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 772.5 ns | 1.48 ns | 1.32 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 254.0 ns | 0.42 ns | 0.38 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 743.8 ns | 1.89 ns | 1.68 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 401.6 ns | 0.75 ns | 0.62 ns | 0.54 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,139.1 ns | 5.52 ns | 4.61 ns | 1.00 | 0.0191 | - | - | 40 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 563.4 ns | 1.60 ns | 1.25 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 564.5 ns | 1.90 ns | 1.78 ns | 1.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 563.9 ns | 2.11 ns | 1.87 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 565.1 ns | 1.37 ns | 1.22 ns | 1.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 562.8 ns | 1.59 ns | 1.41 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 376.3 ns | 1.97 ns | 1.75 ns | 0.67 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,030.0 ns | 3.80 ns | 3.37 ns | 1.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 571.7 ns | 2.71 ns | 2.41 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 220.4 ns | 0.81 ns | 0.71 ns | 0.39 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 763.3 ns | 6.91 ns | 6.12 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 327.9 ns | 0.96 ns | 0.85 ns | 0.43 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 757.2 ns | 3.71 ns | 3.47 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 331.4 ns | 0.65 ns | 0.54 ns | 0.44 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 756.8 ns | 2.23 ns | 1.97 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 684.0 ns | 3.06 ns | 2.87 ns | 0.90 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,183.8 ns | 7.23 ns | 6.41 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,415.5 ns | 3.39 ns | 3.01 ns | 0.65 | 0.0191 | - | - | 40 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 569.8 ns | 2.71 ns | 2.40 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 571.1 ns | 2.82 ns | 2.64 ns | 1.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 572.3 ns | 3.82 ns | 3.38 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 570.8 ns | 2.84 ns | 2.65 ns | 1.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 572.3 ns | 3.40 ns | 3.18 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 698.5 ns | 2.32 ns | 2.05 ns | 1.22 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,013.6 ns | 6.11 ns | 5.42 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,038.9 ns | 5.39 ns | 4.50 ns | 1.01 | 0.0305 | - | - | 64 B | diff --git a/Benchmarks/CountBenchmarks.md b/Benchmarks/CountBenchmarks.md index 2f898d4bb..d7b4d7151 100644 --- a/Benchmarks/CountBenchmarks.md +++ b/Benchmarks/CountBenchmarks.md @@ -4,58 +4,57 @@ [CountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |--------------:|----------:|----------:|-------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 8.9989 ns | 0.0181 ns | 0.0141 ns | 1.000 | 0.00 | - | - | - | - | -| StructLinq_Array | Array | 100 | 0.9332 ns | 0.0091 ns | 0.0081 ns | 0.104 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 0.0000 ns | 0.0000 ns | 0.0000 ns | 0.000 | 0.00 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 0.2514 ns | 0.0047 ns | 0.0041 ns | 0.028 | 0.00 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 0.0000 ns | 0.0000 ns | 0.0000 ns | 0.000 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 9.3451 ns | 0.0531 ns | 0.0471 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Array | Array | 100 | 0.5892 ns | 0.0115 ns | 0.0102 ns | 0.06 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.4762 ns | 0.0154 ns | 0.0136 ns | 0.80 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 339.9804 ns | 0.7672 ns | 0.6801 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 591.7192 ns | 1.8374 ns | 1.6288 ns | 1.74 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 147.5369 ns | 0.3168 ns | 0.2963 ns | 0.43 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 371.9204 ns | 1.3762 ns | 1.2873 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 598.6976 ns | 3.1483 ns | 2.9449 ns | 1.61 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 141.0301 ns | 0.3586 ns | 0.3179 ns | 0.38 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.6490 ns | 0.0391 ns | 0.0305 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Value | Collection_Value | 100 | 619.6203 ns | 0.9017 ns | 0.7530 ns | 133.29 | 0.89 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 4.1855 ns | 0.0207 ns | 0.0184 ns | 0.90 | 0.01 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 4.5363 ns | 0.0178 ns | 0.0157 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Value | Collection_Value | 100 | 598.3502 ns | 2.1699 ns | 1.9236 ns | 131.90 | 0.65 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.6839 ns | 0.0158 ns | 0.0140 ns | 1.69 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.3257 ns | 0.0091 ns | 0.0085 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Value | List_Value | 100 | 2.3656 ns | 0.0092 ns | 0.0086 ns | 0.44 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.5443 ns | 0.0211 ns | 0.0176 ns | 0.29 | 0.00 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 5.2798 ns | 0.0244 ns | 0.0228 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Value | List_Value | 100 | 2.7498 ns | 0.0396 ns | 0.0331 ns | 0.52 | 0.01 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.5510 ns | 0.0117 ns | 0.0104 ns | 0.29 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,041.1344 ns | 3.3812 ns | 2.8234 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,187.2774 ns | 1.6964 ns | 1.5038 ns | 0.58 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,063.9368 ns | 6.4213 ns | 5.0133 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,202.7993 ns | 3.1090 ns | 2.7560 ns | 0.58 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 248.8358 ns | 1.4702 ns | 1.3033 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 384.4841 ns | 2.5870 ns | 2.1603 ns | 1.55 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 254.0431 ns | 0.7041 ns | 0.5880 ns | 1.02 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 265.1278 ns | 0.7708 ns | 0.7210 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 389.1150 ns | 1.3920 ns | 1.2339 ns | 1.47 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 257.5446 ns | 1.0796 ns | 0.9570 ns | 0.97 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.6522 ns | 0.0152 ns | 0.0127 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 383.2519 ns | 0.8476 ns | 0.7928 ns | 82.37 | 0.32 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.5303 ns | 0.0101 ns | 0.0090 ns | 0.33 | 0.00 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.5106 ns | 0.0228 ns | 0.0202 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 390.2365 ns | 1.4122 ns | 1.1793 ns | 86.50 | 0.47 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.5762 ns | 0.0077 ns | 0.0065 ns | 0.35 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.4791 ns | 0.0141 ns | 0.0125 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Reference | List_Reference | 100 | 383.6696 ns | 0.7411 ns | 0.6932 ns | 70.01 | 0.20 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.5162 ns | 0.0048 ns | 0.0043 ns | 0.28 | 0.00 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 5.2694 ns | 0.0240 ns | 0.0212 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Reference | List_Reference | 100 | 389.6645 ns | 2.3961 ns | 2.1241 ns | 73.95 | 0.54 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.6639 ns | 0.0215 ns | 0.0168 ns | 0.32 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,948.7201 ns | 7.2494 ns | 6.0535 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,786.5839 ns | 2.9349 ns | 2.6017 ns | 0.92 | 0.00 | 0.0191 | - | - | 40 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,970.4167 ns | 6.2231 ns | 5.8211 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,811.8537 ns | 2.0555 ns | 1.8222 ns | 0.92 | 0.00 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/DistinctBenchmarks.md b/Benchmarks/DistinctBenchmarks.md index 18a3b1bee..977c1269d 100644 --- a/Benchmarks/DistinctBenchmarks.md +++ b/Benchmarks/DistinctBenchmarks.md @@ -4,58 +4,59 @@ [DistinctBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |---------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 2.909 μs | 0.0101 μs | 0.0094 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Array | Array | 100 | 2.459 μs | 0.0091 μs | 0.0076 μs | 0.84 | 1.4000 | - | - | 2928 B | -| Hyperlinq_Array | Array | 100 | 1.601 μs | 0.0039 μs | 0.0037 μs | 0.55 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 1.557 μs | 0.0034 μs | 0.0032 μs | 0.54 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.669 μs | 0.0026 μs | 0.0023 μs | 0.57 | - | - | - | - | +| Linq_Array | Array | 100 | 2.946 μs | 0.0232 μs | 0.0217 μs | 1.00 | 2.0599 | - | - | 4312 B | +| StructLinq_Array | Array | 100 | 1.271 μs | 0.0033 μs | 0.0026 μs | 0.43 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 1.520 μs | 0.0063 μs | 0.0052 μs | 0.52 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 1.463 μs | 0.0050 μs | 0.0047 μs | 0.50 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.545 μs | 0.0047 μs | 0.0044 μs | 0.52 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.190 μs | 0.0064 μs | 0.0057 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.272 μs | 0.0076 μs | 0.0067 μs | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.651 μs | 0.0029 μs | 0.0026 μs | 0.52 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.273 μs | 0.0077 μs | 0.0068 μs | 1.00 | 2.0599 | - | - | 4312 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.138 μs | 0.0127 μs | 0.0119 μs | 0.65 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.492 μs | 0.0042 μs | 0.0037 μs | 0.46 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 3.170 μs | 0.0118 μs | 0.0105 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 2.245 μs | 0.0123 μs | 0.0115 μs | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.575 μs | 0.0047 μs | 0.0044 μs | 0.50 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 3.267 μs | 0.0078 μs | 0.0073 μs | 1.00 | 2.0599 | - | - | 4312 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 2.157 μs | 0.0122 μs | 0.0114 μs | 0.66 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.484 μs | 0.0032 μs | 0.0028 μs | 0.45 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 3.214 μs | 0.0092 μs | 0.0086 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_List_Value | List_Value | 100 | 1.445 μs | 0.0041 μs | 0.0034 μs | 0.45 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.922 μs | 0.0041 μs | 0.0036 μs | 0.60 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 3.273 μs | 0.0100 μs | 0.0078 μs | 1.00 | 2.0599 | - | - | 4312 B | +| StructLinq_List_Value | List_Value | 100 | 1.463 μs | 0.0052 μs | 0.0049 μs | 0.45 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.869 μs | 0.0025 μs | 0.0019 μs | 0.57 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.912 μs | 0.0213 μs | 0.0189 μs | 1.00 | 2.0905 | - | - | 4400 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.850 μs | 0.0157 μs | 0.0131 μs | 0.61 | 0.0305 | - | - | 72 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.863 μs | 0.0375 μs | 0.0332 μs | 1.00 | 2.0599 | - | - | 4328 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.634 μs | 0.0108 μs | 0.0090 μs | 0.59 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.891 μs | 0.0121 μs | 0.0113 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1.594 μs | 0.0035 μs | 0.0031 μs | 0.55 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.134 μs | 0.0053 μs | 0.0049 μs | 0.74 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.911 μs | 0.0097 μs | 0.0086 μs | 1.00 | 2.0599 | - | - | 4312 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1.726 μs | 0.0113 μs | 0.0105 μs | 0.59 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1.901 μs | 0.0121 μs | 0.0101 μs | 0.65 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 2.885 μs | 0.0106 μs | 0.0094 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1.584 μs | 0.0026 μs | 0.0024 μs | 0.55 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.126 μs | 0.0089 μs | 0.0083 μs | 0.74 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 2.897 μs | 0.0096 μs | 0.0085 μs | 1.00 | 2.0599 | - | - | 4312 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1.724 μs | 0.0111 μs | 0.0104 μs | 0.60 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.940 μs | 0.0053 μs | 0.0047 μs | 0.67 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 2.869 μs | 0.0117 μs | 0.0098 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_List_Reference | List_Reference | 100 | 1.589 μs | 0.0053 μs | 0.0047 μs | 0.55 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.879 μs | 0.0047 μs | 0.0042 μs | 0.65 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 2.913 μs | 0.0181 μs | 0.0151 μs | 1.00 | 2.0599 | - | - | 4312 B | +| StructLinq_List_Reference | List_Reference | 100 | 1.776 μs | 0.0073 μs | 0.0069 μs | 0.61 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.847 μs | 0.0075 μs | 0.0070 μs | 0.63 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.882 μs | 0.0441 μs | 0.0368 μs | 1.00 | 2.0905 | - | - | 4400 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5.114 μs | 0.0120 μs | 0.0113 μs | 0.65 | 0.0534 | - | - | 112 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.864 μs | 0.0220 μs | 0.0206 μs | 1.00 | 2.0599 | - | - | 4328 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4.945 μs | 0.0087 μs | 0.0077 μs | 0.63 | 0.0153 | - | - | 40 B | diff --git a/Benchmarks/ElementAtBenchmarks.md b/Benchmarks/ElementAtBenchmarks.md index 6710af6c0..7e9c3d193 100644 --- a/Benchmarks/ElementAtBenchmarks.md +++ b/Benchmarks/ElementAtBenchmarks.md @@ -4,49 +4,50 @@ [ElementAtBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------- |-------------------------- |------ |-------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 23.360 ns | 0.0504 ns | 0.0447 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 5.306 ns | 0.0090 ns | 0.0084 ns | 0.23 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 5.032 ns | 0.0040 ns | 0.0031 ns | 0.22 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 6.595 ns | 0.0121 ns | 0.0113 ns | 0.28 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 359.232 ns | 0.5723 ns | 0.4779 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 137.595 ns | 0.2246 ns | 0.1991 ns | 0.38 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 317.957 ns | 5.4123 ns | 4.5195 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 143.821 ns | 0.2611 ns | 0.2443 ns | 0.45 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 10.390 ns | 0.0256 ns | 0.0227 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 6.672 ns | 0.0243 ns | 0.0215 ns | 0.64 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,078.866 ns | 4.3966 ns | 4.1125 ns | 1.00 | 0.0191 | - | - | 40 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 231.469 ns | 0.3659 ns | 0.3243 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 241.359 ns | 1.1134 ns | 1.0415 ns | 1.04 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 231.936 ns | 0.3911 ns | 0.3659 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 255.067 ns | 0.8164 ns | 0.7237 ns | 1.10 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 10.386 ns | 0.0318 ns | 0.0282 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 6.670 ns | 0.0148 ns | 0.0132 ns | 0.64 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,945.874 ns | 4.9947 ns | 4.4276 ns | 1.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 19.74 ns | 0.048 ns | 0.043 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 12.87 ns | 0.032 ns | 0.027 ns | 0.65 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 339.30 ns | 6.647 ns | 6.528 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 132.51 ns | 0.342 ns | 0.320 ns | 0.39 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 344.81 ns | 4.847 ns | 4.296 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 137.91 ns | 0.423 ns | 0.375 ns | 0.40 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 10.51 ns | 0.048 ns | 0.040 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 442.80 ns | 0.648 ns | 0.574 ns | 42.12 | 0.18 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,057.40 ns | 5.870 ns | 5.203 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,245.70 ns | 3.073 ns | 2.874 ns | 0.61 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 233.42 ns | 1.091 ns | 0.967 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 254.48 ns | 0.651 ns | 0.577 ns | 1.09 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 236.25 ns | 1.363 ns | 1.275 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 242.72 ns | 3.945 ns | 3.690 ns | 1.03 | 0.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 10.55 ns | 0.056 ns | 0.052 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 316.26 ns | 1.433 ns | 1.340 ns | 29.98 | 0.18 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,934.77 ns | 6.463 ns | 6.046 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,813.34 ns | 3.933 ns | 3.679 ns | 0.94 | 0.00 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/EmptyBenchmarks.md b/Benchmarks/EmptyBenchmarks.md index bd0c0f3c9..d2ed3c2ea 100644 --- a/Benchmarks/EmptyBenchmarks.md +++ b/Benchmarks/EmptyBenchmarks.md @@ -4,28 +4,29 @@ [EmptyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/EmptyBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------------- |------------ |----------:|----------:|----------:|------:|------:|------:|------:|----------:| -| Linq_Empty | Empty | 6.261 ns | 0.0193 ns | 0.0151 ns | 1.00 | - | - | - | - | -| Hyperlinq_Empty | Empty | 1.429 ns | 0.0070 ns | 0.0054 ns | 0.23 | - | - | - | - | -| | | | | | | | | | | -| Linq_Empty_Async | Empty_Async | 40.172 ns | 0.0809 ns | 0.0717 ns | 1.00 | - | - | - | - | -| Hyperlinq_Empty_Async | Empty_Async | 21.537 ns | 0.0361 ns | 0.0282 ns | 0.54 | - | - | - | - | +| Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------------- |------------ |-----------:|----------:|----------:|------:|------:|------:|------:|----------:| +| Linq_Empty | Empty | 6.3048 ns | 0.0285 ns | 0.0238 ns | 1.000 | - | - | - | - | +| Hyperlinq_Empty | Empty | 0.0330 ns | 0.0057 ns | 0.0051 ns | 0.005 | - | - | - | - | +| | | | | | | | | | | +| Linq_Empty_Async | Empty_Async | 40.5115 ns | 0.2056 ns | 0.1924 ns | 1.00 | - | - | - | - | +| Hyperlinq_Empty_Async | Empty_Async | 21.9399 ns | 0.1051 ns | 0.0932 ns | 0.54 | - | - | - | - | diff --git a/Benchmarks/FirstBenchmarks.md b/Benchmarks/FirstBenchmarks.md index 7838c85ea..e11003dd1 100644 --- a/Benchmarks/FirstBenchmarks.md +++ b/Benchmarks/FirstBenchmarks.md @@ -4,49 +4,50 @@ [FirstBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------- |-------------------------- |------ |-----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 21.426 ns | 0.0585 ns | 0.0547 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 4.999 ns | 0.0220 ns | 0.0195 ns | 0.23 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 5.013 ns | 0.0061 ns | 0.0054 ns | 0.23 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 6.534 ns | 0.0105 ns | 0.0093 ns | 0.30 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 23.940 ns | 0.0419 ns | 0.0350 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 14.134 ns | 0.0313 ns | 0.0277 ns | 0.59 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 25.161 ns | 0.0654 ns | 0.0611 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 15.751 ns | 0.0248 ns | 0.0220 ns | 0.63 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 12.900 ns | 0.0202 ns | 0.0179 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 7.295 ns | 0.0195 ns | 0.0183 ns | 0.57 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 115.584 ns | 0.2322 ns | 0.1939 ns | 1.00 | 0.0191 | - | - | 40 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 20.376 ns | 0.0777 ns | 0.0689 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 24.218 ns | 0.0607 ns | 0.0538 ns | 1.19 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 21.360 ns | 0.0450 ns | 0.0399 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 16.310 ns | 0.1366 ns | 0.1066 ns | 0.76 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 12.909 ns | 0.0265 ns | 0.0222 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 7.257 ns | 0.0133 ns | 0.0111 ns | 0.56 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 111.250 ns | 0.1898 ns | 0.1776 ns | 1.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 21.81 ns | 0.085 ns | 0.071 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 13.40 ns | 0.035 ns | 0.033 ns | 0.61 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 24.64 ns | 0.105 ns | 0.093 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.55 ns | 0.029 ns | 0.025 ns | 0.63 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 25.32 ns | 0.090 ns | 0.075 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 18.55 ns | 0.030 ns | 0.028 ns | 0.73 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 12.96 ns | 0.172 ns | 0.144 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 22.25 ns | 0.075 ns | 0.066 ns | 1.72 | 0.02 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 119.08 ns | 0.366 ns | 0.325 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 75.23 ns | 0.256 ns | 0.226 ns | 0.63 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 20.84 ns | 0.134 ns | 0.118 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 15.79 ns | 0.077 ns | 0.064 ns | 0.76 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 21.51 ns | 0.090 ns | 0.084 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 15.61 ns | 0.084 ns | 0.070 ns | 0.73 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 12.89 ns | 0.022 ns | 0.018 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 21.34 ns | 0.056 ns | 0.044 ns | 1.66 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 112.02 ns | 0.289 ns | 0.256 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 77.45 ns | 0.186 ns | 0.174 ns | 0.69 | 0.00 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/IterationBenchmarks.md b/Benchmarks/IterationBenchmarks.md deleted file mode 100644 index e728f5c75..000000000 --- a/Benchmarks/IterationBenchmarks.md +++ /dev/null @@ -1,28 +0,0 @@ -## IterationBenchmarks - -### Source -[IterationBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/IterationBenchmarks.cs) - -### References: -- Linq: 4.8.4300.0 -- System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) -- System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) -- System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) - -### Results: -``` ini - -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT - -Job=.NET Core 5.0 Runtime=.NET Core 5.0 - -``` -| Method | Count | Mean | Error | StdDev | Ratio | -|------- |---------- |---------:|---------:|---------:|------:| -| LT | 100000000 | 51.32 ms | 0.108 ms | 0.096 ms | 1.00 | -| LTE | 100000000 | 51.30 ms | 0.079 ms | 0.066 ms | 1.00 | diff --git a/Benchmarks/RangeBenchmarks.md b/Benchmarks/RangeBenchmarks.md index fd0b0484e..c62f87ab3 100644 --- a/Benchmarks/RangeBenchmarks.md +++ b/Benchmarks/RangeBenchmarks.md @@ -4,29 +4,30 @@ [RangeBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------------- |------------ |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Range | Range | 100 | 417.46 ns | 1.612 ns | 1.258 ns | 1.00 | 0.0191 | - | - | 40 B | -| StructLinq_Range | Range | 100 | 33.49 ns | 0.058 ns | 0.049 ns | 0.08 | - | - | - | - | -| Hyperlinq_Range | Range | 100 | 43.61 ns | 0.065 ns | 0.061 ns | 0.10 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Range_Async | Range_Async | 100 | 4,228.69 ns | 9.630 ns | 8.042 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Range_Async | Range_Async | 100 | 1,295.62 ns | 1.944 ns | 1.819 ns | 0.31 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------ |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| +| Linq | Range | 100 | 427.60 ns | 1.835 ns | 1.532 ns | 1.00 | 0.0191 | - | - | 40 B | +| StructLinq | Range | 100 | 33.82 ns | 0.101 ns | 0.090 ns | 0.08 | - | - | - | - | +| Hyperlinq | Range | 100 | 44.21 ns | 0.177 ns | 0.165 ns | 0.10 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Async | Range_Async | 100 | 4,269.81 ns | 15.076 ns | 14.103 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Range_Async | 100 | 1,285.13 ns | 5.782 ns | 4.514 ns | 0.30 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/RangeToArrayBenchmarks.md b/Benchmarks/RangeToArrayBenchmarks.md index 0a9b07ef3..8d49f5026 100644 --- a/Benchmarks/RangeToArrayBenchmarks.md +++ b/Benchmarks/RangeToArrayBenchmarks.md @@ -4,31 +4,31 @@ [RangeToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeToArrayBenchmarks.cs) ### References: -- Linq: 5.0.2 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta34](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta34) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=5.0.200-preview.20614.14 - [Host] : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------ |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 96.63 ns | 0.862 ns | 0.764 ns | 1.00 | 0.00 | 0.2218 | - | - | 464 B | -| StructLinq | Range | 100 | 99.00 ns | 0.820 ns | 0.640 ns | 1.03 | 0.01 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Range | 100 | 45.58 ns | 0.948 ns | 1.054 ns | 0.47 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq | Range | 100 | 62.69 ns | 0.764 ns | 0.677 ns | 0.65 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 119.78 ns | 2.043 ns | 1.911 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | -| Hyperlinq_Async | Range_Async | 100 | 122.04 ns | 0.868 ns | 0.769 ns | 1.02 | 0.02 | 0.2027 | - | - | 424 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------ |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq | Range | 100 | 87.87 ns | 0.644 ns | 0.570 ns | 1.00 | 0.2218 | - | - | 464 B | +| StructLinq | Range | 100 | 86.41 ns | 0.540 ns | 0.451 ns | 0.98 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Range | 100 | 35.38 ns | 0.474 ns | 0.421 ns | 0.40 | 0.2027 | - | - | 424 B | +| Hyperlinq | Range | 100 | 42.76 ns | 0.530 ns | 0.470 ns | 0.49 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | +| Linq_Async | Range_Async | 100 | 103.55 ns | 0.558 ns | 0.494 ns | 1.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Range_Async | 100 | 107.76 ns | 0.840 ns | 0.702 ns | 1.04 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/RepeatBenchmarks.md b/Benchmarks/RepeatBenchmarks.md index 8f62e2ef5..88c841efc 100644 --- a/Benchmarks/RepeatBenchmarks.md +++ b/Benchmarks/RepeatBenchmarks.md @@ -4,30 +4,30 @@ [RepeatBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatBenchmarks.cs) ### References: -- Linq: 5.0.2 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta34](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta34) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=5.0.200-preview.20614.14 - [Host] : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------- |------ |------------:|----------:|----------:|------------:|------:|-------:|------:|------:|----------:| -| Linq_Count | Repeat | 100 | 578.38 ns | 32.322 ns | 95.302 ns | 623.45 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq | Repeat | 100 | 57.71 ns | 0.545 ns | 0.455 ns | 57.55 ns | 0.10 | - | - | - | - | -| Hyperlinq | Repeat | 100 | 41.23 ns | 0.145 ns | 0.121 ns | 41.18 ns | 0.07 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 6,120.12 ns | 93.560 ns | 87.516 ns | 6,088.82 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Repeat_Async | 100 | 945.28 ns | 7.413 ns | 6.572 ns | 944.56 ns | 0.15 | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| +| Linq | Repeat | 100 | 405.32 ns | 1.427 ns | 1.192 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq | Repeat | 100 | 56.87 ns | 0.306 ns | 0.286 ns | 0.14 | - | - | - | - | +| Hyperlinq | Repeat | 100 | 144.72 ns | 0.432 ns | 0.404 ns | 0.36 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Async | Repeat_Async | 100 | 5,471.45 ns | 18.660 ns | 16.542 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Repeat_Async | 100 | 925.25 ns | 1.404 ns | 1.244 ns | 0.17 | - | - | - | - | diff --git a/Benchmarks/RepeatToArrayBenchmarks.md b/Benchmarks/RepeatToArrayBenchmarks.md index 52589e6ab..786ca962d 100644 --- a/Benchmarks/RepeatToArrayBenchmarks.md +++ b/Benchmarks/RepeatToArrayBenchmarks.md @@ -4,32 +4,32 @@ [RepeatToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatToArrayBenchmarks.cs) ### References: -- Linq: 5.0.2 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta34](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta34) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=5.0.200-preview.20614.14 - [Host] : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------- |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 140.08 ns | 2.839 ns | 2.915 ns | 1.00 | 0.00 | 0.2179 | - | - | 456 B | -| StructLinq | Repeat | 100 | 164.29 ns | 3.302 ns | 3.391 ns | 1.17 | 0.03 | 0.2141 | - | - | 448 B | -| LinqFaster_SIMD | Repeat | 100 | 36.61 ns | 0.810 ns | 1.053 ns | 0.26 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq | Repeat | 100 | 63.87 ns | 1.072 ns | 1.053 ns | 0.46 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_SIMD | Repeat | 100 | 52.59 ns | 0.871 ns | 0.815 ns | 0.38 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 162.26 ns | 3.103 ns | 3.048 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | -| Hyperlinq_Async | Repeat_Async | 100 | 178.38 ns | 1.134 ns | 0.947 ns | 1.10 | 0.02 | 0.2027 | - | - | 424 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------- |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq | Repeat | 100 | 94.97 ns | 0.552 ns | 0.461 ns | 1.00 | 0.2180 | - | - | 456 B | +| StructLinq | Repeat | 100 | 110.09 ns | 0.441 ns | 0.368 ns | 1.16 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Repeat | 100 | 26.88 ns | 0.414 ns | 0.367 ns | 0.28 | 0.2027 | - | - | 424 B | +| Hyperlinq | Repeat | 100 | 52.58 ns | 0.396 ns | 0.371 ns | 0.55 | 0.2027 | - | - | 424 B | +| Hyperlinq_SIMD | Repeat | 100 | 37.14 ns | 0.165 ns | 0.129 ns | 0.39 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | +| Linq_Async | Repeat_Async | 100 | 98.63 ns | 0.675 ns | 0.598 ns | 1.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Repeat_Async | 100 | 163.81 ns | 0.743 ns | 0.659 ns | 1.66 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/ReturnBenchmarks.md b/Benchmarks/ReturnBenchmarks.md index 142fef3ae..8aa284d6b 100644 --- a/Benchmarks/ReturnBenchmarks.md +++ b/Benchmarks/ReturnBenchmarks.md @@ -4,28 +4,29 @@ [ReturnBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReturnBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` | Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |----------------------- |------------- |----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Return | Return | 23.610 ns | 0.0936 ns | 0.0830 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_Return | Return | 8.642 ns | 0.0131 ns | 0.0116 ns | 0.37 | - | - | - | - | +| Linq_Return | Return | 24.887 ns | 0.1063 ns | 0.0888 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_Return | Return | 8.713 ns | 0.0220 ns | 0.0206 ns | 0.35 | - | - | - | - | | | | | | | | | | | | -| Linq_Return_Async | Return_Async | 54.968 ns | 0.1565 ns | 0.1387 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Return_Async | Return_Async | 41.785 ns | 0.1437 ns | 0.1274 ns | 0.76 | - | - | - | - | +| Linq_Return_Async | Return_Async | 54.678 ns | 1.0231 ns | 0.8544 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Return_Async | Return_Async | 42.313 ns | 0.1122 ns | 0.1049 ns | 0.77 | - | - | - | - | diff --git a/Benchmarks/SelectBenchmarks.md b/Benchmarks/SelectBenchmarks.md index 7ab7f5911..3f7a0cbfe 100644 --- a/Benchmarks/SelectBenchmarks.md +++ b/Benchmarks/SelectBenchmarks.md @@ -4,32 +4,64 @@ [SelectBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs) ### References: -- Linq: 5.0.2 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta33](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta33) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=5.0.200-preview.20614.14 - [Host] : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 Categories=Array +Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------- |------ |---------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | 100 | 642.1 ns | 2.04 ns | 1.81 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | 100 | 228.1 ns | 0.33 ns | 0.26 ns | 0.36 | - | - | - | - | -| Hyperlinq_Span_For | 100 | 170.3 ns | 1.06 ns | 0.99 ns | 0.27 | - | - | - | - | -| Hyperlinq_Span_Foreach | 100 | 202.8 ns | 0.68 ns | 0.60 ns | 0.32 | - | - | - | - | -| Hyperlinq_Span_SIMD | 100 | 411.2 ns | 2.49 ns | 2.33 ns | 0.64 | - | - | - | - | -| Hyperlinq_Memory_For | 100 | 344.4 ns | 2.31 ns | 2.05 ns | 0.54 | - | - | - | - | -| Hyperlinq_Memory_Foreach | 100 | 231.5 ns | 1.13 ns | 0.88 ns | 0.36 | - | - | - | - | -| Hyperlinq_Memory_SIMD | 100 | 451.4 ns | 2.79 ns | 2.61 ns | 0.70 | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 649.3 ns | 3.81 ns | 3.38 ns | 649.3 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 213.9 ns | 0.40 ns | 0.35 ns | 213.8 ns | 0.33 | 0.00 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 224.7 ns | 2.42 ns | 3.54 ns | 223.5 ns | 0.35 | 0.01 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 252.0 ns | 7.48 ns | 22.05 ns | 245.4 ns | 0.41 | 0.03 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 219.1 ns | 0.57 ns | 0.50 ns | 219.1 ns | 0.34 | 0.00 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 207.1 ns | 0.69 ns | 0.61 ns | 207.2 ns | 0.32 | 0.00 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 298.9 ns | 1.97 ns | 1.64 ns | 298.5 ns | 0.46 | 0.00 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 236.4 ns | 0.81 ns | 0.68 ns | 236.3 ns | 0.36 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,244.7 ns | 6.85 ns | 5.72 ns | 1,243.7 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 795.1 ns | 2.18 ns | 1.93 ns | 795.4 ns | 0.64 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 238.8 ns | 0.86 ns | 0.67 ns | 238.9 ns | 0.19 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,247.5 ns | 4.97 ns | 4.41 ns | 1,246.0 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 791.6 ns | 1.71 ns | 1.42 ns | 790.9 ns | 0.63 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 208.1 ns | 0.58 ns | 0.48 ns | 208.2 ns | 0.17 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,191.8 ns | 5.52 ns | 4.89 ns | 1,189.7 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 369.3 ns | 1.11 ns | 0.98 ns | 369.3 ns | 0.31 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value_For | List_Value | 100 | 396.5 ns | 1.39 ns | 1.16 ns | 396.5 ns | 0.33 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value_Foreach | List_Value | 100 | 413.4 ns | 1.93 ns | 1.71 ns | 413.1 ns | 0.35 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,335.0 ns | 33.17 ns | 31.03 ns | 8,338.7 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,470.6 ns | 17.71 ns | 14.79 ns | 6,471.6 ns | 0.78 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 975.0 ns | 3.38 ns | 3.16 ns | 974.2 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 517.4 ns | 2.24 ns | 1.99 ns | 517.5 ns | 0.53 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 529.0 ns | 4.08 ns | 3.61 ns | 528.2 ns | 0.54 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 975.0 ns | 4.34 ns | 3.85 ns | 975.4 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 566.8 ns | 2.68 ns | 2.24 ns | 565.9 ns | 0.58 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 592.6 ns | 1.66 ns | 1.47 ns | 592.2 ns | 0.61 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 958.7 ns | 6.11 ns | 5.10 ns | 957.0 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 567.4 ns | 2.49 ns | 2.08 ns | 566.6 ns | 0.59 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference_For | List_Reference | 100 | 401.4 ns | 1.10 ns | 1.03 ns | 401.4 ns | 0.42 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 434.3 ns | 0.92 ns | 0.77 ns | 434.2 ns | 0.45 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,852.8 ns | 27.00 ns | 22.54 ns | 7,850.5 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,290.5 ns | 9.09 ns | 8.06 ns | 6,292.2 ns | 0.80 | 0.00 | 0.0153 | - | - | 40 B | diff --git a/Benchmarks/SelectCountBenchmarks.md b/Benchmarks/SelectCountBenchmarks.md index 520b12d00..c8a5a260f 100644 --- a/Benchmarks/SelectCountBenchmarks.md +++ b/Benchmarks/SelectCountBenchmarks.md @@ -4,58 +4,57 @@ [SelectCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-------------:|-----------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 219.134 ns | 0.8228 ns | 0.6870 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 10.007 ns | 0.0146 ns | 0.0130 ns | 0.05 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 8.946 ns | 0.0141 ns | 0.0125 ns | 0.04 | 0.00 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 8.940 ns | 0.0145 ns | 0.0135 ns | 0.04 | 0.00 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 9.489 ns | 0.0204 ns | 0.0170 ns | 0.04 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 803.504 ns | 3.4588 ns | 3.0661 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 796.036 ns | 1.6843 ns | 1.4065 ns | 0.99 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 149.788 ns | 0.2333 ns | 0.2068 ns | 0.19 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 805.356 ns | 2.4730 ns | 2.3133 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 774.031 ns | 1.2887 ns | 1.0761 ns | 0.96 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 11.941 ns | 0.0139 ns | 0.0123 ns | 0.01 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 379.943 ns | 0.8789 ns | 0.7791 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Value | List_Value | 100 | 10.201 ns | 0.0244 ns | 0.0229 ns | 0.03 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 7.511 ns | 0.0271 ns | 0.0254 ns | 0.02 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,902.444 ns | 23.6333 ns | 19.7349 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,968.740 ns | 17.1138 ns | 14.2908 ns | 1.01 | 0.00 | 0.0610 | - | - | 136 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 594.794 ns | 0.9684 ns | 0.8585 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 566.260 ns | 0.9518 ns | 0.8903 ns | 0.95 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 258.161 ns | 0.8138 ns | 0.7613 ns | 0.43 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 597.569 ns | 3.9864 ns | 3.5338 ns | 1.000 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 572.285 ns | 1.3061 ns | 1.2217 ns | 0.958 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.136 ns | 0.0051 ns | 0.0043 ns | 0.007 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 360.074 ns | 1.2968 ns | 1.1495 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Reference | List_Reference | 100 | 526.575 ns | 7.2842 ns | 8.0964 ns | 1.47 | 0.02 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 7.479 ns | 0.0248 ns | 0.0207 ns | 0.02 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,636.721 ns | 29.1881 ns | 24.3733 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,940.788 ns | 23.7462 ns | 22.2122 ns | 1.04 | 0.00 | 0.0610 | - | - | 152 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-------------:|-----------:|-----------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 198.220 ns | 0.6773 ns | 0.6336 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 10.184 ns | 0.0197 ns | 0.0164 ns | 0.05 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 15.412 ns | 0.0319 ns | 0.0283 ns | 0.08 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 790.965 ns | 2.4941 ns | 2.2110 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 761.327 ns | 2.2745 ns | 1.7758 ns | 0.96 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 146.856 ns | 0.2308 ns | 0.2046 ns | 0.19 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 791.787 ns | 2.1413 ns | 1.8982 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 806.411 ns | 3.3071 ns | 2.9317 ns | 1.02 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 16.205 ns | 0.0335 ns | 0.0314 ns | 0.02 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 388.335 ns | 1.5311 ns | 1.4322 ns | 1.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Value | List_Value | 100 | 10.448 ns | 0.0232 ns | 0.0206 ns | 0.03 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 9.561 ns | 0.0320 ns | 0.0283 ns | 0.02 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,558.331 ns | 30.3258 ns | 28.3667 ns | 1.00 | 0.0458 | - | - | 104 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,207.574 ns | 2.9260 ns | 2.4434 ns | 0.14 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 550.957 ns | 2.0793 ns | 1.9450 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 547.387 ns | 3.0914 ns | 2.8917 ns | 0.99 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 259.798 ns | 0.8359 ns | 0.6980 ns | 0.47 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 597.908 ns | 1.6524 ns | 1.5457 ns | 1.000 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 545.517 ns | 1.9988 ns | 1.8697 ns | 0.912 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.182 ns | 0.0329 ns | 0.0292 ns | 0.007 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 431.165 ns | 1.2621 ns | 0.9854 ns | 1.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Reference | List_Reference | 100 | 534.272 ns | 2.3511 ns | 2.0842 ns | 1.24 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 9.931 ns | 0.0424 ns | 0.0354 ns | 0.02 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,927.773 ns | 35.8253 ns | 33.5110 ns | 1.00 | 0.0458 | - | - | 104 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,797.694 ns | 4.0443 ns | 3.5852 ns | 0.20 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/SelectManyBenchmarks.md b/Benchmarks/SelectManyBenchmarks.md index f7e46be29..9ab9aade6 100644 --- a/Benchmarks/SelectManyBenchmarks.md +++ b/Benchmarks/SelectManyBenchmarks.md @@ -4,48 +4,49 @@ [SelectManyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectManyBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------- |-------------------------- |------ |----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 3.416 μs | 0.0082 μs | 0.0073 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_Array | Array | 100 | 1.270 μs | 0.0012 μs | 0.0010 μs | 0.37 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.361 μs | 0.0021 μs | 0.0019 μs | 0.40 | - | - | - | - | +| Linq_Array | Array | 100 | 3.556 μs | 0.0119 μs | 0.0111 μs | 1.00 | 1.9569 | - | - | 4096 B | +| Hyperlinq_Array | Array | 100 | 1.226 μs | 0.0042 μs | 0.0035 μs | 0.34 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.381 μs | 0.0023 μs | 0.0021 μs | 0.39 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.631 μs | 0.0080 μs | 0.0067 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.505 μs | 0.0063 μs | 0.0053 μs | 0.97 | 2.3537 | - | - | 4928 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.817 μs | 0.0077 μs | 0.0065 μs | 1.00 | 1.9531 | - | - | 4096 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.439 μs | 0.0133 μs | 0.0111 μs | 0.90 | 2.3575 | - | - | 4936 B | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 3.730 μs | 0.0086 μs | 0.0080 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.454 μs | 0.0116 μs | 0.0103 μs | 0.93 | 2.3537 | - | - | 4928 B | +| Linq_Collection_Value | Collection_Value | 100 | 3.821 μs | 0.0122 μs | 0.0114 μs | 1.00 | 1.9531 | - | - | 4096 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.360 μs | 0.0157 μs | 0.0140 μs | 0.88 | 2.3575 | - | - | 4936 B | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 3.725 μs | 0.0064 μs | 0.0054 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_List_Value | List_Value | 100 | 1.331 μs | 0.0021 μs | 0.0016 μs | 0.36 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 3.754 μs | 0.0147 μs | 0.0130 μs | 1.00 | 1.9569 | - | - | 4096 B | +| Hyperlinq_List_Value | List_Value | 100 | 3.530 μs | 0.0093 μs | 0.0078 μs | 0.94 | 2.3537 | - | - | 4928 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 13.882 μs | 0.0308 μs | 0.0273 μs | 1.00 | 2.3804 | - | - | 4984 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 13.831 μs | 0.0353 μs | 0.0313 μs | 1.00 | 2.3346 | - | - | 4912 B | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 3.428 μs | 0.0070 μs | 0.0062 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1.497 μs | 0.0029 μs | 0.0026 μs | 0.44 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 3.596 μs | 0.0158 μs | 0.0148 μs | 1.00 | 1.9531 | - | - | 4096 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 3.201 μs | 0.0208 μs | 0.0185 μs | 0.89 | 2.3499 | - | - | 4920 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 3.426 μs | 0.0069 μs | 0.0058 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.487 μs | 0.0019 μs | 0.0017 μs | 0.43 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 3.545 μs | 0.0128 μs | 0.0113 μs | 1.00 | 1.9569 | - | - | 4096 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 3.193 μs | 0.0111 μs | 0.0098 μs | 0.90 | 2.3499 | - | - | 4920 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 3.430 μs | 0.0068 μs | 0.0061 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.327 μs | 0.0017 μs | 0.0016 μs | 0.39 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 3.528 μs | 0.0116 μs | 0.0103 μs | 1.00 | 1.9569 | - | - | 4096 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 3.620 μs | 0.0165 μs | 0.0146 μs | 1.03 | 2.3537 | - | - | 4928 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 13.511 μs | 0.0257 μs | 0.0215 μs | 1.00 | 2.3804 | - | - | 4984 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 13.608 μs | 0.0423 μs | 0.0375 μs | 1.00 | 2.3346 | - | - | 4912 B | diff --git a/Benchmarks/SelectSumBenchmarks.md b/Benchmarks/SelectSumBenchmarks.md index 2bae871ac..a384b3f00 100644 --- a/Benchmarks/SelectSumBenchmarks.md +++ b/Benchmarks/SelectSumBenchmarks.md @@ -4,29 +4,58 @@ [SelectSumBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs) ### References: -- Linq: 5.0.2 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta34](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta34) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=5.0.200-preview.20614.14 - [Host] : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 Categories=Array +Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|-------------------- |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | 100 | 667.37 ns | 6.329 ns | 7.773 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | 100 | 187.38 ns | 0.992 ns | 0.828 ns | 0.28 | - | - | - | - | -| Hyperlinq_Array | 100 | 173.83 ns | 2.209 ns | 1.845 ns | 0.26 | - | - | - | - | -| Hyperlinq_Span | 100 | 170.41 ns | 0.836 ns | 0.698 ns | 0.25 | - | - | - | - | -| Hyperlinq_Span_SIMD | 100 | 63.81 ns | 1.143 ns | 1.013 ns | 0.10 | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 654.18 ns | 3.445 ns | 2.877 ns | 653.02 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 181.81 ns | 0.777 ns | 0.689 ns | 181.78 ns | 0.28 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 198.64 ns | 0.591 ns | 0.493 ns | 198.51 ns | 0.30 | 0.00 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 66.12 ns | 0.259 ns | 0.242 ns | 66.06 ns | 0.10 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,157.21 ns | 7.054 ns | 5.891 ns | 1,158.61 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 824.79 ns | 16.388 ns | 32.348 ns | 808.26 ns | 0.73 | 0.03 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 205.29 ns | 0.779 ns | 0.651 ns | 205.36 ns | 0.18 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,196.57 ns | 5.153 ns | 4.568 ns | 1,197.16 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 781.53 ns | 1.587 ns | 1.239 ns | 781.40 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 241.25 ns | 0.687 ns | 0.609 ns | 241.33 ns | 0.20 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,215.92 ns | 5.309 ns | 4.433 ns | 1,214.85 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 343.30 ns | 1.155 ns | 1.080 ns | 343.05 ns | 0.28 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 638.69 ns | 1.304 ns | 1.089 ns | 638.68 ns | 0.53 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 9,248.73 ns | 32.956 ns | 29.215 ns | 9,246.09 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,832.96 ns | 3.763 ns | 3.142 ns | 2,832.44 ns | 0.31 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 931.83 ns | 3.446 ns | 3.055 ns | 932.08 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 575.52 ns | 1.889 ns | 1.578 ns | 575.47 ns | 0.62 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 547.15 ns | 2.083 ns | 1.847 ns | 546.84 ns | 0.59 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 972.85 ns | 4.653 ns | 4.352 ns | 970.63 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 580.05 ns | 2.791 ns | 2.610 ns | 579.80 ns | 0.60 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 541.45 ns | 2.817 ns | 2.497 ns | 540.77 ns | 0.56 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 967.52 ns | 3.570 ns | 3.165 ns | 967.75 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 573.72 ns | 2.226 ns | 1.973 ns | 573.90 ns | 0.59 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 638.77 ns | 2.185 ns | 1.825 ns | 639.27 ns | 0.66 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,606.46 ns | 23.219 ns | 20.583 ns | 8,604.72 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,493.55 ns | 8.193 ns | 7.664 ns | 3,492.49 ns | 0.41 | 0.00 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/SelectToArrayBenchmarks.md b/Benchmarks/SelectToArrayBenchmarks.md index a3b139a00..d7a998884 100644 --- a/Benchmarks/SelectToArrayBenchmarks.md +++ b/Benchmarks/SelectToArrayBenchmarks.md @@ -9,12 +9,12 @@ - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta39](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta39) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET Core SDK=6.0.100-preview.1.21103.13 [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT @@ -23,42 +23,40 @@ Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cor Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 267.88 ns | 2.668 ns | 2.365 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | -| StructLinq_Array | Array | 100 | 273.06 ns | 4.607 ns | 4.084 ns | 1.02 | 0.01 | 0.2027 | - | - | 424 B | -| LinqFasterSIMD_Array | Array | 100 | 99.65 ns | 1.953 ns | 1.827 ns | 0.37 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 269.94 ns | 4.902 ns | 4.585 ns | 1.01 | 0.02 | 0.2027 | - | - | 424 B | -| Hyperlinq_Span | Array | 100 | 239.28 ns | 2.553 ns | 2.388 ns | 0.89 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Span_SIMD | Array | 100 | 109.47 ns | 1.910 ns | 1.693 ns | 0.41 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Memory | Array | 100 | 274.17 ns | 5.390 ns | 5.991 ns | 1.02 | 0.02 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,285.51 ns | 25.581 ns | 26.270 ns | 1.00 | 0.00 | 0.5913 | - | - | 1240 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,129.23 ns | 8.712 ns | 7.723 ns | 0.88 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 663.26 ns | 6.979 ns | 6.528 ns | 0.52 | 0.01 | 0.2022 | - | - | 424 B | -| Hyperlinq_Enumerable_Value_SIMD | Enumerable_Value | 100 | 700.52 ns | 9.899 ns | 10.591 ns | 0.55 | 0.01 | 0.2289 | - | - | 480 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,273.49 ns | 18.642 ns | 16.526 ns | 1.00 | 0.00 | 0.5913 | - | - | 1240 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,153.21 ns | 6.918 ns | 6.133 ns | 0.91 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 406.46 ns | 6.649 ns | 6.219 ns | 0.32 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 468.99 ns | 4.210 ns | 3.516 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Value | List_Value | 100 | 445.91 ns | 5.327 ns | 4.159 ns | 0.95 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 511.99 ns | 5.562 ns | 4.931 ns | 1.09 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 964.21 ns | 17.884 ns | 15.854 ns | 1.00 | 0.00 | 0.5922 | - | - | 1240 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 936.40 ns | 10.404 ns | 8.688 ns | 0.97 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,000.13 ns | 5.117 ns | 4.273 ns | 1.04 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference_SIMD | Enumerable_Reference | 100 | 978.08 ns | 6.965 ns | 6.515 ns | 1.02 | 0.02 | 0.2441 | - | - | 512 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 958.07 ns | 11.892 ns | 9.930 ns | 1.00 | 0.00 | 0.5922 | - | - | 1240 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 938.89 ns | 9.194 ns | 7.178 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 645.53 ns | 8.129 ns | 7.604 ns | 0.67 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 470.57 ns | 6.943 ns | 6.155 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Reference | List_Reference | 100 | 942.82 ns | 5.208 ns | 4.066 ns | 2.01 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 483.23 ns | 3.540 ns | 3.312 ns | 1.03 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 9,811.24 ns | 52.535 ns | 49.142 ns | ? | ? | 0.8087 | - | - | 1712 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 9,564.61 ns | 61.404 ns | 57.437 ns | ? | ? | 0.8240 | - | - | 1728 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|-----------:|-----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 266.30 ns | 0.996 ns | 0.883 ns | 266.33 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | +| StructLinq_Array | Array | 100 | 230.11 ns | 0.430 ns | 0.402 ns | 230.07 ns | 0.86 | 0.00 | 0.2027 | - | - | 424 B | +| LinqFasterSIMD_Array | Array | 100 | 61.06 ns | 0.906 ns | 0.848 ns | 61.18 ns | 0.23 | 0.00 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 228.43 ns | 4.636 ns | 6.795 ns | 225.50 ns | 0.87 | 0.03 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array_SIMD | Array | 100 | 80.84 ns | 0.477 ns | 0.422 ns | 80.85 ns | 0.30 | 0.00 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,087.02 ns | 4.618 ns | 4.320 ns | 1,086.41 ns | 1.00 | 0.00 | 0.5913 | - | - | 1240 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,027.28 ns | 3.503 ns | 3.105 ns | 1,026.13 ns | 0.95 | 0.00 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 577.04 ns | 7.168 ns | 6.354 ns | 574.94 ns | 0.53 | 0.01 | 0.2022 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,016.00 ns | 4.421 ns | 3.919 ns | 1,015.71 ns | 1.00 | 0.00 | 0.5913 | - | - | 1240 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,003.42 ns | 3.857 ns | 3.608 ns | 1,003.91 ns | 0.99 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 329.29 ns | 6.231 ns | 10.238 ns | 326.48 ns | 0.33 | 0.01 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 450.50 ns | 1.984 ns | 1.856 ns | 450.73 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Value | List_Value | 100 | 420.33 ns | 0.768 ns | 0.600 ns | 420.47 ns | 0.93 | 0.00 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 710.39 ns | 2.213 ns | 2.070 ns | 710.80 ns | 1.58 | 0.01 | 0.2022 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 9,100.44 ns | 173.408 ns | 269.975 ns | 8,970.54 ns | 1.00 | 0.00 | 0.7935 | - | - | 1680 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,243.73 ns | 5.176 ns | 4.588 ns | 3,242.45 ns | 0.36 | 0.01 | 0.5646 | - | - | 1184 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 880.15 ns | 17.540 ns | 38.502 ns | 859.06 ns | 1.00 | 0.00 | 0.5922 | - | - | 1240 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 848.52 ns | 2.958 ns | 2.622 ns | 848.33 ns | 0.97 | 0.04 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 870.31 ns | 4.246 ns | 3.764 ns | 870.27 ns | 1.00 | 0.04 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 809.89 ns | 4.995 ns | 4.428 ns | 809.57 ns | 1.00 | 0.00 | 0.5922 | - | - | 1240 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 817.48 ns | 3.859 ns | 3.421 ns | 817.35 ns | 1.01 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 603.54 ns | 2.087 ns | 1.952 ns | 603.40 ns | 0.75 | 0.00 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 411.50 ns | 3.098 ns | 2.587 ns | 411.04 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Reference | List_Reference | 100 | 864.78 ns | 6.857 ns | 6.079 ns | 864.46 ns | 2.10 | 0.02 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 725.33 ns | 1.868 ns | 1.656 ns | 725.76 ns | 1.76 | 0.01 | 0.2022 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 9,888.42 ns | 33.364 ns | 29.576 ns | 9,880.00 ns | 1.00 | 0.00 | 0.7935 | - | - | 1680 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,841.00 ns | 11.640 ns | 10.318 ns | 4,841.20 ns | 0.49 | 0.00 | 0.5798 | - | - | 1224 B | diff --git a/Benchmarks/SelectToListBenchmarks.md b/Benchmarks/SelectToListBenchmarks.md index ebc17ede4..7570cac33 100644 --- a/Benchmarks/SelectToListBenchmarks.md +++ b/Benchmarks/SelectToListBenchmarks.md @@ -4,56 +4,56 @@ [SelectToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_List | Array | 100 | 313.9 ns | 0.99 ns | 0.87 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | -| StructLinq_List | Array | 100 | 259.8 ns | 0.65 ns | 0.61 ns | 0.83 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_List | Array | 100 | 222.9 ns | 0.43 ns | 0.36 ns | 0.71 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_Span | Array | 100 | 221.4 ns | 0.86 ns | 0.77 ns | 0.71 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_Memory | Array | 100 | 202.7 ns | 0.68 ns | 0.57 ns | 0.65 | 0.00 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,079.1 ns | 2.63 ns | 2.46 ns | 1.00 | 0.00 | 0.6065 | - | - | 1272 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,032.1 ns | 3.91 ns | 3.47 ns | 0.96 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 617.7 ns | 0.95 ns | 0.88 ns | 0.57 | 0.00 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,117.5 ns | 3.96 ns | 3.31 ns | 1.00 | 0.00 | 0.6065 | - | - | 1272 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,029.1 ns | 3.21 ns | 3.00 ns | 0.92 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 252.1 ns | 1.15 ns | 1.08 ns | 0.23 | 0.00 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 504.9 ns | 1.24 ns | 1.03 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Value | List_Value | 100 | 442.3 ns | 0.88 ns | 0.78 ns | 0.88 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 385.6 ns | 1.02 ns | 0.91 ns | 0.76 | 0.00 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 883.2 ns | 2.55 ns | 2.26 ns | 1.00 | 0.00 | 0.6075 | - | - | 1272 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 872.5 ns | 1.61 ns | 1.43 ns | 0.99 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 953.2 ns | 1.67 ns | 1.39 ns | 1.08 | 0.00 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 919.5 ns | 1.37 ns | 1.07 ns | 1.00 | 0.00 | 0.6075 | - | - | 1272 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 857.0 ns | 1.77 ns | 1.65 ns | 0.93 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 604.9 ns | 4.90 ns | 4.34 ns | 0.66 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 458.1 ns | 1.16 ns | 1.03 ns | 1.00 | 0.00 | 0.2446 | - | - | 512 B | -| StructLinq_List_Reference | List_Reference | 100 | 875.1 ns | 1.77 ns | 1.48 ns | 1.91 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 389.0 ns | 1.96 ns | 1.64 ns | 0.85 | 0.00 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 9,480.1 ns | 14.18 ns | 12.57 ns | ? | ? | 0.6256 | - | - | 1320 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 9,036.1 ns | 22.12 ns | 19.61 ns | ? | ? | 0.6256 | - | - | 1336 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|-----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 253.61 ns | 1.216 ns | 1.078 ns | 253.58 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | +| StructLinq_Array | Array | 100 | 240.35 ns | 0.978 ns | 0.867 ns | 240.29 ns | 0.95 | 0.00 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 233.42 ns | 0.858 ns | 0.803 ns | 233.15 ns | 0.92 | 0.00 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array_SIMD | Array | 100 | 92.40 ns | 0.458 ns | 0.406 ns | 92.34 ns | 0.36 | 0.00 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,041.43 ns | 3.515 ns | 3.116 ns | 1,040.74 ns | 1.00 | 0.00 | 0.6065 | - | - | 1272 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,063.21 ns | 4.399 ns | 3.899 ns | 1,063.23 ns | 1.02 | 0.00 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 608.65 ns | 5.087 ns | 4.248 ns | 608.84 ns | 0.58 | 0.00 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,080.18 ns | 5.664 ns | 5.021 ns | 1,079.65 ns | 1.00 | 0.00 | 0.6065 | - | - | 1272 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,014.86 ns | 3.208 ns | 2.679 ns | 1,015.04 ns | 0.94 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 254.47 ns | 0.771 ns | 0.684 ns | 254.55 ns | 0.24 | 0.00 | 0.2179 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 476.58 ns | 8.462 ns | 12.403 ns | 471.41 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Value | List_Value | 100 | 404.32 ns | 1.011 ns | 0.946 ns | 404.40 ns | 0.84 | 0.02 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 716.97 ns | 2.596 ns | 2.301 ns | 717.30 ns | 1.49 | 0.04 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 862.70 ns | 2.807 ns | 2.488 ns | 863.12 ns | 1.00 | 0.00 | 0.6075 | - | - | 1272 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 862.81 ns | 2.362 ns | 1.973 ns | 862.31 ns | 1.00 | 0.00 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 928.89 ns | 5.865 ns | 5.486 ns | 927.72 ns | 1.08 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 888.21 ns | 16.842 ns | 34.403 ns | 871.97 ns | 1.00 | 0.00 | 0.6075 | - | - | 1272 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 811.46 ns | 4.436 ns | 3.704 ns | 812.39 ns | 0.88 | 0.04 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 604.53 ns | 3.046 ns | 2.850 ns | 604.67 ns | 0.66 | 0.03 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 488.13 ns | 1.409 ns | 1.318 ns | 487.52 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Reference | List_Reference | 100 | 809.28 ns | 2.379 ns | 2.226 ns | 809.99 ns | 1.66 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 736.16 ns | 14.615 ns | 20.961 ns | 726.79 ns | 1.52 | 0.05 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,239.23 ns | 5.002 ns | 4.177 ns | 3,239.25 ns | ? | ? | 0.5798 | - | - | 1216 B | +| | | | | | | | | | | | | | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,100.41 ns | 80.671 ns | 104.895 ns | 4,072.31 ns | ? | ? | 0.5951 | - | - | 1256 B | diff --git a/Benchmarks/SingleBenchmarks.md b/Benchmarks/SingleBenchmarks.md index cb629839e..81d4ab90d 100644 --- a/Benchmarks/SingleBenchmarks.md +++ b/Benchmarks/SingleBenchmarks.md @@ -4,53 +4,52 @@ [SingleBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 1 | 11.192 ns | 0.0386 ns | 0.0322 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 1 | 5.163 ns | 0.0090 ns | 0.0084 ns | 0.46 | 0.00 | - | - | - | - | -| Hyperlinq_Span | Array | 1 | 5.743 ns | 0.0095 ns | 0.0085 ns | 0.51 | 0.00 | - | - | - | - | -| Hyperlinq_Memory | Array | 1 | 7.674 ns | 0.0115 ns | 0.0096 ns | 0.69 | 0.00 | - | - | - | - | +| Linq_Array | Array | 1 | 11.808 ns | 0.2634 ns | 0.5011 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 1 | 13.928 ns | 0.0230 ns | 0.0192 ns | 1.20 | 0.05 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 1 | 22.396 ns | 0.0761 ns | 0.0635 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 1 | 15.166 ns | 0.0283 ns | 0.0236 ns | 0.68 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 1 | 23.083 ns | 0.1199 ns | 0.1062 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 1 | 16.547 ns | 0.0383 ns | 0.0359 ns | 0.72 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 1 | 22.736 ns | 0.0904 ns | 0.0845 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 1 | 22.084 ns | 0.0493 ns | 0.0437 ns | 0.97 | 0.00 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 1 | 23.476 ns | 0.4181 ns | 0.6986 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 1 | 18.673 ns | 0.0344 ns | 0.0322 ns | 0.79 | 0.03 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 1 | 7.208 ns | 0.0328 ns | 0.0291 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 1 | 7.339 ns | 0.0142 ns | 0.0133 ns | 1.02 | 0.00 | - | - | - | - | +| Linq_List_Value | List_Value | 1 | 7.425 ns | 0.0417 ns | 0.0348 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 1 | 22.084 ns | 0.0572 ns | 0.0507 ns | 2.97 | 0.02 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 1 | 86.784 ns | 0.1634 ns | 0.1448 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 1 | 89.296 ns | 0.1602 ns | 0.1420 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | | Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 1 | NA | NA | NA | ? | ? | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 1 | 18.076 ns | 0.1049 ns | 0.0930 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 1 | 19.090 ns | 0.0687 ns | 0.0643 ns | 1.06 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 1 | 17.964 ns | 0.0869 ns | 0.0813 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 1 | 15.953 ns | 0.0711 ns | 0.0630 ns | 0.89 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 1 | 18.010 ns | 0.1005 ns | 0.0891 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 1 | 19.315 ns | 0.0738 ns | 0.0654 ns | 1.07 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 1 | 18.071 ns | 0.1005 ns | 0.0891 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 1 | 16.254 ns | 0.0875 ns | 0.1864 ns | 0.91 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 1 | 7.222 ns | 0.0207 ns | 0.0183 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 1 | 7.424 ns | 0.0126 ns | 0.0099 ns | 1.03 | 0.00 | - | - | - | - | +| Linq_List_Reference | List_Reference | 1 | 7.401 ns | 0.1724 ns | 0.1693 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 1 | 22.010 ns | 0.0530 ns | 0.0496 ns | 2.97 | 0.07 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 1 | 85.182 ns | 0.0826 ns | 0.0772 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 1 | 84.754 ns | 0.2935 ns | 0.2602 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | | Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 1 | NA | NA | NA | ? | ? | - | - | - | - | Benchmarks with issues: diff --git a/Benchmarks/SkipTakeBenchmarks.md b/Benchmarks/SkipTakeBenchmarks.md index d3bb7b8bc..439aa3d75 100644 --- a/Benchmarks/SkipTakeBenchmarks.md +++ b/Benchmarks/SkipTakeBenchmarks.md @@ -4,63 +4,64 @@ [SkipTakeBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Skip | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |----- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 100 | 828.46 ns | 1.483 ns | 1.238 ns | 1.00 | 0.0458 | - | - | 96 B | -| StructLinq_Array | Array | 100 | 100 | 110.94 ns | 0.191 ns | 0.160 ns | 0.13 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 100 | 61.62 ns | 0.086 ns | 0.081 ns | 0.07 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 100 | 297.77 ns | 0.490 ns | 0.458 ns | 0.36 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 100 | 61.64 ns | 0.112 ns | 0.094 ns | 0.07 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 100 | 49.31 ns | 0.293 ns | 0.259 ns | 0.06 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 100 | 59.74 ns | 0.183 ns | 0.153 ns | 0.07 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 60.51 ns | 0.166 ns | 0.156 ns | 0.07 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,523.79 ns | 2.700 ns | 2.394 ns | 1.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 968.79 ns | 2.805 ns | 2.342 ns | 0.64 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 498.73 ns | 1.486 ns | 1.390 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,532.42 ns | 5.043 ns | 4.717 ns | 1.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 967.60 ns | 3.050 ns | 2.704 ns | 0.63 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 610.03 ns | 2.245 ns | 1.990 ns | 0.40 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 100 | 834.17 ns | 2.057 ns | 1.924 ns | 1.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Value | List_Value | 100 | 100 | 222.05 ns | 0.326 ns | 0.272 ns | 0.27 | - | - | - | - | -| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 401.71 ns | 0.787 ns | 0.697 ns | 0.48 | - | - | - | - | -| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 248.95 ns | 1.327 ns | 1.176 ns | 0.30 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 9,571.18 ns | 42.371 ns | 37.561 ns | 1.00 | 0.1221 | - | - | 256 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 5,312.43 ns | 16.175 ns | 14.338 ns | 0.56 | 0.0305 | - | - | 72 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,172.66 ns | 4.419 ns | 3.917 ns | 1.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 706.05 ns | 1.648 ns | 1.542 ns | 0.60 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 826.26 ns | 3.009 ns | 2.349 ns | 0.70 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,148.65 ns | 3.342 ns | 2.963 ns | 1.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 677.29 ns | 1.542 ns | 1.367 ns | 0.59 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 931.79 ns | 2.819 ns | 2.499 ns | 0.81 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 100 | 835.78 ns | 2.241 ns | 1.986 ns | 1.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Reference | List_Reference | 100 | 100 | 704.07 ns | 1.353 ns | 1.130 ns | 0.84 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 377.01 ns | 0.775 ns | 0.687 ns | 0.45 | - | - | - | - | -| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 222.71 ns | 0.466 ns | 0.389 ns | 0.27 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 9,561.55 ns | 38.920 ns | 36.406 ns | 1.00 | 0.1221 | - | - | 256 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 6,122.13 ns | 14.826 ns | 13.869 ns | 0.64 | 0.0534 | - | - | 112 B | +| Method | Categories | Skip | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |----- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 100 | 849.41 ns | 3.438 ns | 2.870 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| StructLinq_Array | Array | 100 | 100 | 116.34 ns | 2.178 ns | 3.927 ns | 0.14 | 0.01 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 100 | 144.20 ns | 0.462 ns | 0.386 ns | 0.17 | 0.00 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 100 | 179.67 ns | 0.847 ns | 0.708 ns | 0.21 | 0.00 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 100 | 80.75 ns | 0.520 ns | 0.461 ns | 0.10 | 0.00 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 100 | 172.12 ns | 0.463 ns | 0.361 ns | 0.20 | 0.00 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 100 | 226.10 ns | 0.961 ns | 0.852 ns | 0.27 | 0.00 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 176.70 ns | 0.371 ns | 0.329 ns | 0.21 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,494.65 ns | 3.827 ns | 3.196 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,022.35 ns | 20.233 ns | 33.244 ns | 0.70 | 0.03 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 447.26 ns | 1.050 ns | 0.931 ns | 0.30 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,491.03 ns | 3.881 ns | 3.440 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 997.75 ns | 3.011 ns | 2.350 ns | 0.67 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 551.51 ns | 2.405 ns | 2.132 ns | 0.37 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 100 | 795.02 ns | 5.166 ns | 4.314 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Value | List_Value | 100 | 100 | 224.83 ns | 0.397 ns | 0.310 ns | 0.28 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 245.96 ns | 0.985 ns | 0.921 ns | 0.31 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 219.36 ns | 0.923 ns | 0.771 ns | 0.28 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 9,739.61 ns | 26.639 ns | 23.615 ns | 1.00 | 0.00 | 0.0763 | - | - | 184 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 5,344.59 ns | 13.071 ns | 11.587 ns | 0.55 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,180.94 ns | 5.532 ns | 4.619 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 712.26 ns | 2.693 ns | 2.387 ns | 0.60 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 835.20 ns | 2.755 ns | 2.442 ns | 0.71 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,179.76 ns | 4.184 ns | 3.709 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 713.51 ns | 2.994 ns | 2.801 ns | 0.60 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 889.84 ns | 5.805 ns | 5.146 ns | 0.75 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 100 | 797.12 ns | 3.318 ns | 2.941 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Reference | List_Reference | 100 | 100 | 710.34 ns | 2.152 ns | 1.908 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 265.26 ns | 1.894 ns | 1.679 ns | 0.33 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 220.22 ns | 1.062 ns | 0.887 ns | 0.28 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 9,553.58 ns | 31.181 ns | 27.641 ns | 1.00 | 0.00 | 0.0763 | - | - | 184 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 6,700.30 ns | 19.039 ns | 16.878 ns | 0.70 | 0.00 | 0.0153 | - | - | 40 B | diff --git a/Benchmarks/SumBenchmarks.md b/Benchmarks/SumBenchmarks.md index eb0ebf6ae..78ef29451 100644 --- a/Benchmarks/SumBenchmarks.md +++ b/Benchmarks/SumBenchmarks.md @@ -4,29 +4,58 @@ [SumBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs) ### References: -- Linq: 5.0.2 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta34](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta34) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=5.0.200-preview.20614.14 - [Host] : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 Categories=Array +Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|--------------------- |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | 100 | 445.32 ns | 2.467 ns | 4.753 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | 100 | 62.74 ns | 0.297 ns | 0.248 ns | 0.14 | - | - | - | - | -| LinqFasterSIMD_Array | 100 | 12.16 ns | 0.072 ns | 0.067 ns | 0.03 | - | - | - | - | -| Hyperlinq_Array | 100 | 19.54 ns | 0.143 ns | 0.134 ns | 0.04 | - | - | - | - | -| Hyperlinq_Span | 100 | 19.53 ns | 0.138 ns | 0.129 ns | 0.04 | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 439.06 ns | 1.415 ns | 1.324 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 61.70 ns | 0.275 ns | 0.230 ns | 0.14 | - | - | - | - | +| LinqFasterSIMD_Array | Array | 100 | 12.18 ns | 0.033 ns | 0.030 ns | 0.03 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 23.31 ns | 0.081 ns | 0.076 ns | 0.05 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 626.31 ns | 4.614 ns | 3.853 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 613.05 ns | 2.688 ns | 2.383 ns | 0.98 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 217.91 ns | 0.335 ns | 0.297 ns | 0.35 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 629.35 ns | 6.732 ns | 6.297 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 614.08 ns | 1.502 ns | 1.254 ns | 0.98 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 218.77 ns | 0.326 ns | 0.305 ns | 0.35 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 630.95 ns | 2.247 ns | 1.876 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 221.11 ns | 0.569 ns | 0.476 ns | 0.35 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 218.26 ns | 0.609 ns | 0.540 ns | 0.35 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,103.14 ns | 6.460 ns | 5.726 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,250.68 ns | 2.283 ns | 2.024 ns | 0.59 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 413.93 ns | 2.534 ns | 2.116 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 389.11 ns | 1.314 ns | 1.165 ns | 0.94 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 414.19 ns | 2.253 ns | 1.997 ns | 1.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 412.53 ns | 1.369 ns | 1.143 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 389.06 ns | 0.867 ns | 0.724 ns | 0.94 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 410.67 ns | 2.361 ns | 2.209 ns | 1.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 413.93 ns | 1.624 ns | 1.356 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 390.65 ns | 1.376 ns | 1.287 ns | 0.94 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 217.56 ns | 0.706 ns | 0.661 ns | 0.53 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,903.89 ns | 6.329 ns | 5.610 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,932.12 ns | 4.151 ns | 3.883 ns | 1.02 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/ToArrayBenchmarks.md b/Benchmarks/ToArrayBenchmarks.md index 108cf7257..661fd5b88 100644 --- a/Benchmarks/ToArrayBenchmarks.md +++ b/Benchmarks/ToArrayBenchmarks.md @@ -4,56 +4,55 @@ [ToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 49.33 ns | 0.233 ns | 0.206 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Array | Array | 100 | 79.71 ns | 0.426 ns | 0.398 ns | 1.62 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 30.57 ns | 0.090 ns | 0.075 ns | 0.62 | 0.00 | 0.2027 | - | - | 424 B | -| Hyperlinq_Span | Array | 100 | 28.22 ns | 0.294 ns | 0.275 ns | 0.57 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Memory | Array | 100 | 30.64 ns | 0.181 ns | 0.160 ns | 0.62 | 0.00 | 0.2027 | - | - | 424 B | +| Linq_Array | Array | 100 | 49.55 ns | 0.656 ns | 0.582 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Array | Array | 100 | 79.60 ns | 0.239 ns | 0.200 ns | 1.61 | 0.02 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 37.57 ns | 0.124 ns | 0.110 ns | 0.76 | 0.01 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 887.10 ns | 2.480 ns | 2.071 ns | 1.00 | 0.00 | 0.5655 | - | - | 1184 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 900.66 ns | 1.904 ns | 1.687 ns | 1.02 | 0.00 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 517.63 ns | 1.854 ns | 1.644 ns | 0.58 | 0.00 | 0.2174 | - | - | 456 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 942.82 ns | 4.818 ns | 3.762 ns | 1.00 | 0.00 | 0.5646 | - | - | 1184 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 940.98 ns | 2.934 ns | 2.450 ns | 1.00 | 0.00 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 506.45 ns | 2.280 ns | 2.133 ns | 0.54 | 0.00 | 0.2213 | - | - | 464 B | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 43.34 ns | 0.245 ns | 0.204 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 893.50 ns | 2.616 ns | 2.184 ns | 20.62 | 0.10 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 59.69 ns | 0.736 ns | 0.652 ns | 1.38 | 0.02 | 0.2180 | - | - | 456 B | +| Linq_Collection_Value | Collection_Value | 100 | 43.92 ns | 0.171 ns | 0.143 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 886.16 ns | 3.552 ns | 3.323 ns | 20.17 | 0.07 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 132.67 ns | 1.076 ns | 1.007 ns | 3.02 | 0.02 | 0.2217 | - | - | 464 B | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 45.11 ns | 0.201 ns | 0.168 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Value | List_Value | 100 | 243.02 ns | 0.931 ns | 0.871 ns | 5.39 | 0.03 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 42.65 ns | 0.234 ns | 0.196 ns | 0.95 | 0.01 | 0.2027 | - | - | 424 B | +| Linq_List_Value | List_Value | 100 | 45.17 ns | 0.369 ns | 0.308 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Value | List_Value | 100 | 272.36 ns | 0.609 ns | 0.475 ns | 6.03 | 0.04 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 524.33 ns | 2.163 ns | 1.807 ns | 11.61 | 0.09 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 702.23 ns | 2.098 ns | 1.860 ns | 1.00 | 0.00 | 0.5655 | - | - | 1184 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 724.75 ns | 2.218 ns | 1.852 ns | 1.03 | 0.00 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 789.74 ns | 2.514 ns | 2.099 ns | 1.12 | 0.00 | 0.2174 | - | - | 456 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 717.70 ns | 3.132 ns | 2.777 ns | 1.00 | 0.00 | 0.5655 | - | - | 1184 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 691.29 ns | 3.306 ns | 2.930 ns | 0.96 | 0.00 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 794.63 ns | 4.396 ns | 3.897 ns | 1.11 | 0.01 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 43.89 ns | 0.609 ns | 0.569 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 725.74 ns | 2.660 ns | 2.488 ns | 16.54 | 0.22 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 49.80 ns | 0.642 ns | 0.570 ns | 1.13 | 0.02 | 0.2142 | - | - | 448 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 43.62 ns | 0.555 ns | 0.519 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 726.35 ns | 3.630 ns | 3.218 ns | 16.66 | 0.25 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 486.52 ns | 3.939 ns | 3.491 ns | 11.16 | 0.16 | 0.2289 | - | - | 480 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 44.96 ns | 0.119 ns | 0.100 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Reference | List_Reference | 100 | 719.31 ns | 2.610 ns | 2.442 ns | 16.00 | 0.07 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 45.09 ns | 0.962 ns | 0.853 ns | 1.00 | 0.02 | 0.2027 | - | - | 424 B | +| Linq_List_Reference | List_Reference | 100 | 45.43 ns | 0.153 ns | 0.136 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Reference | List_Reference | 100 | 681.49 ns | 3.162 ns | 2.803 ns | 15.00 | 0.08 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 555.79 ns | 2.546 ns | 2.126 ns | 12.24 | 0.05 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,661.99 ns | 3.493 ns | 3.268 ns | ? | ? | 0.5646 | - | - | 1184 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,648.08 ns | 4.695 ns | 4.162 ns | ? | ? | 0.5646 | - | - | 1184 B | | | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,308.43 ns | 6.064 ns | 5.375 ns | ? | ? | 0.5836 | - | - | 1224 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,283.01 ns | 5.415 ns | 4.800 ns | ? | ? | 0.5836 | - | - | 1224 B | diff --git a/Benchmarks/ToListBenchmarks.md b/Benchmarks/ToListBenchmarks.md index 9ed5fe136..2938195f5 100644 --- a/Benchmarks/ToListBenchmarks.md +++ b/Benchmarks/ToListBenchmarks.md @@ -4,56 +4,57 @@ [ToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 58.20 ns | 0.494 ns | 0.438 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Array | Array | 100 | 114.10 ns | 0.325 ns | 0.272 ns | 1.96 | 0.01 | 0.2180 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 49.57 ns | 0.138 ns | 0.122 ns | 0.85 | 0.01 | 0.2334 | - | - | 488 B | -| Hyperlinq_Span | Array | 100 | 160.62 ns | 0.449 ns | 0.420 ns | 2.76 | 0.02 | 0.2179 | - | - | 456 B | -| Hyperlinq_Memory | Array | 100 | 40.54 ns | 0.383 ns | 0.340 ns | 0.70 | 0.01 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 893.89 ns | 2.555 ns | 2.390 ns | 1.00 | 0.00 | 0.5808 | - | - | 1216 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 934.53 ns | 2.676 ns | 2.372 ns | 1.05 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 578.02 ns | 1.782 ns | 1.580 ns | 0.65 | 0.00 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 47.13 ns | 0.536 ns | 0.475 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 937.11 ns | 2.386 ns | 2.115 ns | 19.89 | 0.23 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 73.03 ns | 0.555 ns | 0.492 ns | 1.55 | 0.02 | 0.2333 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 48.27 ns | 0.462 ns | 0.409 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Value | List_Value | 100 | 249.82 ns | 2.383 ns | 2.230 ns | 5.18 | 0.05 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 50.51 ns | 0.480 ns | 0.426 ns | 1.05 | 0.02 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 647.78 ns | 1.861 ns | 1.650 ns | 1.00 | 0.00 | 0.5808 | - | - | 1216 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 736.91 ns | 1.475 ns | 1.380 ns | 1.14 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 781.32 ns | 2.815 ns | 2.198 ns | 1.21 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 48.58 ns | 0.450 ns | 0.399 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 727.74 ns | 1.335 ns | 1.183 ns | 14.98 | 0.12 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 97.13 ns | 0.461 ns | 0.432 ns | 2.00 | 0.02 | 0.2295 | - | - | 480 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 48.85 ns | 0.489 ns | 0.434 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Reference | List_Reference | 100 | 675.21 ns | 2.616 ns | 2.319 ns | 13.82 | 0.13 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 50.82 ns | 0.335 ns | 0.297 ns | 1.04 | 0.01 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,688.26 ns | 3.145 ns | 2.788 ns | ? | ? | 0.5798 | - | - | 1216 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,370.42 ns | 3.392 ns | 2.833 ns | ? | ? | 0.5989 | - | - | 1256 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 55.46 ns | 0.762 ns | 0.675 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Array | Array | 100 | 114.42 ns | 0.588 ns | 0.521 ns | 2.06 | 0.03 | 0.2180 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 46.29 ns | 0.394 ns | 0.329 ns | 0.84 | 0.01 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 879.10 ns | 3.996 ns | 3.337 ns | 1.00 | 0.00 | 0.5808 | - | - | 1216 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 950.25 ns | 7.034 ns | 6.235 ns | 1.08 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 535.21 ns | 1.916 ns | 1.698 ns | 0.61 | 0.00 | 0.2365 | - | - | 496 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 47.68 ns | 0.359 ns | 0.336 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 953.11 ns | 11.902 ns | 9.939 ns | 20.02 | 0.18 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 147.80 ns | 1.565 ns | 1.307 ns | 3.10 | 0.03 | 0.2370 | - | - | 496 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 49.68 ns | 0.454 ns | 0.402 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Value | List_Value | 100 | 252.02 ns | 0.966 ns | 0.904 ns | 5.07 | 0.04 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 613.03 ns | 3.689 ns | 3.270 ns | 12.34 | 0.15 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,375.78 ns | 10.666 ns | 9.455 ns | 1.00 | 0.00 | 0.5836 | - | - | 1224 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,694.93 ns | 8.596 ns | 7.620 ns | 0.71 | 0.00 | 0.5798 | - | - | 1216 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 658.08 ns | 3.375 ns | 2.992 ns | 1.00 | 0.00 | 0.5808 | - | - | 1216 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 696.58 ns | 3.669 ns | 3.064 ns | 1.06 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 807.41 ns | 4.501 ns | 4.210 ns | 1.23 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 47.90 ns | 0.709 ns | 0.592 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 743.68 ns | 3.335 ns | 2.956 ns | 15.53 | 0.18 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 492.61 ns | 1.405 ns | 1.245 ns | 10.29 | 0.14 | 0.2441 | - | - | 512 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 49.95 ns | 0.224 ns | 0.198 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Reference | List_Reference | 100 | 743.40 ns | 2.663 ns | 2.491 ns | 14.88 | 0.07 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 602.74 ns | 2.613 ns | 2.317 ns | 12.07 | 0.08 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,211.75 ns | 6.184 ns | 5.164 ns | 1.00 | 0.00 | 0.5836 | - | - | 1224 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,367.85 ns | 6.742 ns | 5.630 ns | 1.07 | 0.00 | 0.5989 | - | - | 1256 B | diff --git a/Benchmarks/WhereBenchmarks.md b/Benchmarks/WhereBenchmarks.md index bd7e15d15..1e93a8617 100644 --- a/Benchmarks/WhereBenchmarks.md +++ b/Benchmarks/WhereBenchmarks.md @@ -4,52 +4,59 @@ [WhereBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|-------------------------------- |--------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 476.2 ns | 3.07 ns | 2.56 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 265.0 ns | 0.52 ns | 0.44 ns | 0.56 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 271.2 ns | 2.27 ns | 1.90 ns | 0.57 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 326.3 ns | 4.87 ns | 4.06 ns | 0.69 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 368.9 ns | 5.80 ns | 5.42 ns | 0.77 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,348.2 ns | 2.99 ns | 2.65 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,202.2 ns | 2.45 ns | 2.29 ns | 0.89 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 262.4 ns | 0.87 ns | 0.82 ns | 0.19 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,386.8 ns | 2.80 ns | 2.34 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,244.6 ns | 4.08 ns | 3.82 ns | 0.90 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 272.1 ns | 0.74 ns | 0.62 ns | 0.20 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,341.1 ns | 5.56 ns | 4.93 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 660.3 ns | 3.05 ns | 2.71 ns | 0.49 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 592.8 ns | 1.64 ns | 1.54 ns | 0.44 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,003.0 ns | 2.76 ns | 2.45 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 714.5 ns | 1.51 ns | 1.41 ns | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 727.9 ns | 3.31 ns | 3.10 ns | 0.73 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,006.5 ns | 4.95 ns | 4.63 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 694.3 ns | 1.96 ns | 1.73 ns | 0.69 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 727.1 ns | 3.24 ns | 2.87 ns | 0.72 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,006.5 ns | 2.92 ns | 2.58 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 705.6 ns | 2.00 ns | 1.77 ns | 0.70 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 578.6 ns | 2.52 ns | 2.24 ns | 0.57 | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 482.2 ns | 2.83 ns | 2.36 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 265.0 ns | 1.64 ns | 1.46 ns | 0.55 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 268.2 ns | 0.82 ns | 0.73 ns | 0.56 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 266.8 ns | 1.06 ns | 0.88 ns | 0.55 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 292.4 ns | 5.44 ns | 5.08 ns | 0.61 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,400.0 ns | 6.33 ns | 5.28 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,270.8 ns | 7.32 ns | 6.49 ns | 0.91 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 269.4 ns | 1.07 ns | 1.00 ns | 0.19 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,386.5 ns | 6.28 ns | 4.91 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,220.8 ns | 3.54 ns | 3.13 ns | 0.88 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 300.0 ns | 1.66 ns | 1.56 ns | 0.22 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,393.3 ns | 4.63 ns | 4.11 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 612.6 ns | 2.87 ns | 2.54 ns | 0.44 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 700.7 ns | 2.21 ns | 1.96 ns | 0.50 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,300.8 ns | 15.66 ns | 13.88 ns | 1.00 | 0.0458 | - | - | 104 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,654.6 ns | 18.68 ns | 16.56 ns | 1.07 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 993.3 ns | 2.83 ns | 2.51 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 696.3 ns | 2.10 ns | 1.97 ns | 0.70 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 709.3 ns | 4.12 ns | 3.65 ns | 0.71 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 995.1 ns | 3.68 ns | 3.44 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 730.5 ns | 1.67 ns | 1.48 ns | 0.73 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 760.3 ns | 1.89 ns | 1.76 ns | 0.76 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 994.5 ns | 6.59 ns | 6.17 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 726.1 ns | 2.60 ns | 2.17 ns | 0.73 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 650.1 ns | 2.65 ns | 2.35 ns | 0.65 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,900.0 ns | 34.57 ns | 28.86 ns | 1.00 | 0.0458 | - | - | 104 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,680.1 ns | 52.87 ns | 41.27 ns | 0.96 | 0.0153 | - | - | 40 B | diff --git a/Benchmarks/WhereCountBenchmarks.md b/Benchmarks/WhereCountBenchmarks.md index 0a26f9f4e..0f814ff5e 100644 --- a/Benchmarks/WhereCountBenchmarks.md +++ b/Benchmarks/WhereCountBenchmarks.md @@ -4,58 +4,59 @@ [WhereCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 636.8 ns | 3.95 ns | 3.70 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | Array | 100 | 234.2 ns | 0.35 ns | 0.28 ns | 0.37 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 167.7 ns | 0.32 ns | 0.28 ns | 0.26 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 164.7 ns | 0.40 ns | 0.34 ns | 0.26 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 190.7 ns | 0.25 ns | 0.21 ns | 0.30 | - | - | - | - | +| Linq_Array | Array | 100 | 676.9 ns | 3.86 ns | 3.61 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 227.9 ns | 0.80 ns | 0.67 ns | 0.34 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 198.1 ns | 0.73 ns | 0.57 ns | 0.29 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 195.3 ns | 0.52 ns | 0.46 ns | 0.29 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 175.4 ns | 0.38 ns | 0.32 ns | 0.26 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,167.4 ns | 2.08 ns | 1.84 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,069.0 ns | 2.98 ns | 2.79 ns | 0.92 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 204.2 ns | 0.33 ns | 0.29 ns | 0.17 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,142.8 ns | 4.04 ns | 3.78 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,129.2 ns | 4.64 ns | 3.87 ns | 0.99 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 254.8 ns | 0.97 ns | 0.86 ns | 0.22 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,167.7 ns | 3.31 ns | 2.77 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,088.3 ns | 2.76 ns | 2.58 ns | 0.93 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 203.3 ns | 0.31 ns | 0.27 ns | 0.17 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,144.0 ns | 4.62 ns | 4.32 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,122.3 ns | 6.15 ns | 5.45 ns | 0.98 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 262.7 ns | 0.61 ns | 0.54 ns | 0.23 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,153.8 ns | 3.52 ns | 2.75 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Value | List_Value | 100 | 397.2 ns | 3.08 ns | 2.88 ns | 0.34 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 358.9 ns | 1.94 ns | 1.82 ns | 0.31 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 1,151.2 ns | 3.85 ns | 3.41 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 446.5 ns | 3.22 ns | 2.86 ns | 0.39 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 591.0 ns | 1.82 ns | 1.70 ns | 0.51 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,165.8 ns | 5.26 ns | 4.66 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,691.8 ns | 8.07 ns | 7.16 ns | 2.63 | 0.0610 | - | - | 136 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,131.5 ns | 5.79 ns | 5.42 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,373.4 ns | 6.91 ns | 6.12 ns | 1.58 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 771.0 ns | 2.55 ns | 2.13 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 599.0 ns | 2.97 ns | 2.48 ns | 0.78 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 565.4 ns | 2.37 ns | 1.85 ns | 0.73 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 779.2 ns | 4.05 ns | 3.79 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 667.9 ns | 3.40 ns | 3.18 ns | 0.86 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 572.9 ns | 1.84 ns | 1.64 ns | 0.74 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 772.4 ns | 3.35 ns | 2.97 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 585.3 ns | 3.35 ns | 3.14 ns | 0.76 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 565.4 ns | 1.26 ns | 1.18 ns | 0.73 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 773.6 ns | 3.83 ns | 3.19 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 655.9 ns | 1.85 ns | 1.64 ns | 0.85 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 576.3 ns | 2.26 ns | 2.12 ns | 0.75 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 768.5 ns | 4.69 ns | 4.16 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Reference | List_Reference | 100 | 585.7 ns | 3.06 ns | 2.86 ns | 0.76 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 372.9 ns | 0.55 ns | 0.49 ns | 0.49 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 781.2 ns | 4.21 ns | 3.94 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 658.1 ns | 2.69 ns | 2.39 ns | 0.84 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 612.7 ns | 1.73 ns | 1.45 ns | 0.78 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,064.2 ns | 4.18 ns | 3.70 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,883.8 ns | 9.57 ns | 8.49 ns | 2.85 | 0.0687 | - | - | 152 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,055.3 ns | 5.14 ns | 4.56 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,573.3 ns | 8.78 ns | 7.79 ns | 1.74 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/WhereFirstBenchmarks.md b/Benchmarks/WhereFirstBenchmarks.md index b514337ea..821bb81a9 100644 --- a/Benchmarks/WhereFirstBenchmarks.md +++ b/Benchmarks/WhereFirstBenchmarks.md @@ -4,54 +4,53 @@ [WhereFirstBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |---------:|--------:|--------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 178.8 ns | 0.53 ns | 0.47 ns | ? | ? | 0.0305 | - | - | 64 B | -| Hyperlinq_Span | Array | 100 | 200.7 ns | 0.37 ns | 0.33 ns | ? | ? | 0.0305 | - | - | 64 B | -| Hyperlinq_Memory | Array | 100 | 206.9 ns | 0.52 ns | 0.49 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 241.9 ns | 0.74 ns | 0.62 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 241.4 ns | 0.61 ns | 0.51 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 359.5 ns | 0.46 ns | 0.38 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 549.6 ns | 1.22 ns | 1.14 ns | ? | ? | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 563.2 ns | 4.59 ns | 4.29 ns | ? | ? | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 359.1 ns | 1.21 ns | 1.01 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 183.2 ns | 0.84 ns | 0.79 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 217.7 ns | 0.92 ns | 0.82 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 223.2 ns | 0.70 ns | 0.62 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 625.9 ns | 2.16 ns | 1.80 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,485.7 ns | 7.43 ns | 6.95 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 560.4 ns | 2.78 ns | 2.46 ns | ? | ? | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 553.1 ns | 3.00 ns | 2.81 ns | ? | ? | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 654.8 ns | 2.75 ns | 2.57 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,637.2 ns | 5.87 ns | 5.20 ns | ? | ? | 0.0496 | - | - | 104 B | Benchmarks with issues: WhereFirstBenchmarks.Linq_Array: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] @@ -59,9 +58,7 @@ Benchmarks with issues: WhereFirstBenchmarks.Linq_Collection_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereFirstBenchmarks.Linq_List_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereFirstBenchmarks.Linq_AsyncEnumerable_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Hyperlinq_AsyncEnumerable_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereFirstBenchmarks.Linq_Enumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereFirstBenchmarks.Linq_Collection_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereFirstBenchmarks.Linq_List_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereFirstBenchmarks.Linq_AsyncEnumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Hyperlinq_AsyncEnumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] diff --git a/Benchmarks/WhereSelectBenchmarks.md b/Benchmarks/WhereSelectBenchmarks.md index 2779023da..cee6e8fa8 100644 --- a/Benchmarks/WhereSelectBenchmarks.md +++ b/Benchmarks/WhereSelectBenchmarks.md @@ -4,52 +4,59 @@ [WhereSelectBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|-------------------------------- |--------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 640.4 ns | 3.21 ns | 2.84 ns | 1.00 | 0.0496 | - | - | 104 B | -| StructLinq_Array | Array | 100 | 381.8 ns | 1.63 ns | 1.36 ns | 0.60 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 352.3 ns | 1.15 ns | 1.02 ns | 0.55 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 369.2 ns | 1.12 ns | 1.05 ns | 0.58 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 412.5 ns | 1.53 ns | 1.35 ns | 0.64 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,569.9 ns | 6.34 ns | 5.93 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,353.8 ns | 3.07 ns | 2.87 ns | 0.86 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 385.8 ns | 0.86 ns | 0.80 ns | 0.25 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,516.2 ns | 2.88 ns | 2.69 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,337.8 ns | 2.35 ns | 1.83 ns | 0.88 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 403.9 ns | 2.13 ns | 1.99 ns | 0.27 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,512.4 ns | 2.71 ns | 2.53 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Value | List_Value | 100 | 773.6 ns | 2.41 ns | 2.01 ns | 0.51 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 777.2 ns | 1.50 ns | 1.33 ns | 0.51 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,272.0 ns | 3.50 ns | 3.10 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 844.9 ns | 1.79 ns | 1.59 ns | 0.66 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 875.6 ns | 1.50 ns | 1.25 ns | 0.69 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,268.0 ns | 4.18 ns | 3.70 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 864.3 ns | 1.90 ns | 1.48 ns | 0.68 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 820.6 ns | 2.38 ns | 2.11 ns | 0.65 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,233.5 ns | 4.33 ns | 3.61 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Reference | List_Reference | 100 | 845.7 ns | 3.21 ns | 2.84 ns | 0.69 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 743.3 ns | 1.70 ns | 1.42 ns | 0.60 | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 697.2 ns | 4.30 ns | 3.59 ns | 1.00 | 0.00 | 0.0496 | - | - | 104 B | +| StructLinq_Array | Array | 100 | 352.7 ns | 1.50 ns | 1.33 ns | 0.51 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 635.9 ns | 8.41 ns | 7.02 ns | 0.91 | 0.01 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 347.9 ns | 0.76 ns | 0.67 ns | 0.50 | 0.00 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 350.6 ns | 4.74 ns | 4.20 ns | 0.50 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,514.8 ns | 5.30 ns | 4.70 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,368.5 ns | 25.69 ns | 30.58 ns | 0.91 | 0.02 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 388.9 ns | 1.24 ns | 1.16 ns | 0.26 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,508.8 ns | 4.02 ns | 3.56 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,336.6 ns | 3.76 ns | 3.33 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 393.9 ns | 2.18 ns | 1.82 ns | 0.26 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,528.9 ns | 3.72 ns | 3.29 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Value | List_Value | 100 | 733.3 ns | 2.60 ns | 2.30 ns | 0.48 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 786.1 ns | 2.85 ns | 2.38 ns | 0.51 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,547.6 ns | 22.18 ns | 19.66 ns | 1.00 | 0.00 | 0.0839 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,511.1 ns | 25.67 ns | 22.76 ns | 1.17 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,222.2 ns | 2.52 ns | 2.23 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 912.5 ns | 2.92 ns | 2.44 ns | 0.75 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 843.7 ns | 4.50 ns | 3.76 ns | 0.69 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,200.7 ns | 5.00 ns | 4.44 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 871.8 ns | 2.53 ns | 2.12 ns | 0.73 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 937.9 ns | 3.48 ns | 2.90 ns | 0.78 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,257.7 ns | 3.14 ns | 2.78 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Reference | List_Reference | 100 | 900.6 ns | 2.82 ns | 2.50 ns | 0.72 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 840.8 ns | 7.53 ns | 6.29 ns | 0.67 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,301.6 ns | 14.40 ns | 12.77 ns | 1.00 | 0.00 | 0.0839 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,497.4 ns | 34.76 ns | 30.81 ns | 1.23 | 0.01 | 0.0153 | - | - | 40 B | diff --git a/Benchmarks/WhereSelectCountBenchmarks.md b/Benchmarks/WhereSelectCountBenchmarks.md index d92939e9c..4d6578c23 100644 --- a/Benchmarks/WhereSelectCountBenchmarks.md +++ b/Benchmarks/WhereSelectCountBenchmarks.md @@ -4,45 +4,50 @@ [WhereSelectCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------- |--------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 364.1 ns | 1.84 ns | 1.72 ns | 1.00 | 0.0496 | - | - | 104 B | -| Hyperlinq_Array | Array | 100 | 176.1 ns | 0.33 ns | 0.29 ns | 0.48 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 220.7 ns | 0.39 ns | 0.34 ns | 0.61 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 176.2 ns | 0.28 ns | 0.26 ns | 0.48 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,221.4 ns | 2.74 ns | 2.43 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 241.2 ns | 0.45 ns | 0.39 ns | 0.20 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,221.1 ns | 1.07 ns | 0.83 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 263.9 ns | 1.00 ns | 0.94 ns | 0.22 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,203.9 ns | 2.59 ns | 2.16 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Value | List_Value | 100 | 387.2 ns | 0.62 ns | 0.55 ns | 0.32 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 874.0 ns | 4.20 ns | 3.72 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 569.5 ns | 1.61 ns | 1.43 ns | 0.65 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 863.5 ns | 3.63 ns | 3.21 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 517.9 ns | 0.95 ns | 0.89 ns | 0.60 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 864.5 ns | 2.02 ns | 1.89 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 365.0 ns | 1.01 ns | 0.94 ns | 0.42 | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 311.0 ns | 1.27 ns | 1.13 ns | 1.00 | 0.0496 | - | - | 104 B | +| Hyperlinq_Array | Array | 100 | 179.1 ns | 0.41 ns | 0.39 ns | 0.58 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,230.8 ns | 4.24 ns | 3.97 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 260.2 ns | 0.85 ns | 0.79 ns | 0.21 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,211.5 ns | 2.55 ns | 2.39 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 216.4 ns | 0.99 ns | 0.87 ns | 0.18 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,204.5 ns | 3.22 ns | 2.86 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Value | List_Value | 100 | 641.8 ns | 1.79 ns | 1.67 ns | 0.53 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,789.2 ns | 8.70 ns | 7.71 ns | 1.00 | 0.0839 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,353.5 ns | 4.98 ns | 4.66 ns | 0.58 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 825.5 ns | 5.57 ns | 5.21 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 555.2 ns | 6.33 ns | 5.29 ns | 0.67 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 811.7 ns | 1.99 ns | 1.76 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 591.8 ns | 2.44 ns | 2.04 ns | 0.73 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 828.4 ns | 3.43 ns | 3.21 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 716.2 ns | 3.67 ns | 3.06 ns | 0.86 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,741.1 ns | 34.42 ns | 28.74 ns | 1.00 | 0.0839 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,554.6 ns | 6.29 ns | 5.25 ns | 0.62 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/WhereSingleBenchmarks.md b/Benchmarks/WhereSingleBenchmarks.md index 49041fc1e..93589eab3 100644 --- a/Benchmarks/WhereSingleBenchmarks.md +++ b/Benchmarks/WhereSingleBenchmarks.md @@ -4,54 +4,53 @@ [WhereSingleBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |---------:|--------:|--------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 200.5 ns | 0.44 ns | 0.36 ns | ? | ? | 0.0305 | - | - | 64 B | -| Hyperlinq_Span | Array | 100 | 200.5 ns | 0.72 ns | 0.67 ns | ? | ? | 0.0305 | - | - | 64 B | -| Hyperlinq_Memory | Array | 100 | 204.3 ns | 0.36 ns | 0.30 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 218.4 ns | 0.90 ns | 0.75 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 242.9 ns | 0.80 ns | 0.75 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 359.6 ns | 0.91 ns | 0.81 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 548.8 ns | 2.12 ns | 1.88 ns | ? | ? | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 524.4 ns | 1.42 ns | 1.33 ns | ? | ? | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 359.0 ns | 0.65 ns | 0.57 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 180.3 ns | 1.15 ns | 1.08 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 220.2 ns | 0.54 ns | 0.51 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 221.4 ns | 0.66 ns | 0.58 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 688.4 ns | 2.21 ns | 1.85 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,409.6 ns | 5.87 ns | 4.90 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 546.4 ns | 1.15 ns | 1.02 ns | ? | ? | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 521.9 ns | 1.43 ns | 1.34 ns | ? | ? | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 690.2 ns | 1.25 ns | 1.17 ns | ? | ? | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,545.9 ns | 5.21 ns | 4.62 ns | ? | ? | 0.0496 | - | - | 104 B | Benchmarks with issues: WhereSingleBenchmarks.Linq_Array: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] @@ -59,9 +58,7 @@ Benchmarks with issues: WhereSingleBenchmarks.Linq_Collection_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereSingleBenchmarks.Linq_List_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereSingleBenchmarks.Linq_AsyncEnumerable_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Hyperlinq_AsyncEnumerable_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereSingleBenchmarks.Linq_Enumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereSingleBenchmarks.Linq_Collection_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereSingleBenchmarks.Linq_List_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] WhereSingleBenchmarks.Linq_AsyncEnumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Hyperlinq_AsyncEnumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] diff --git a/Benchmarks/WhereToArrayBenchmarks.md b/Benchmarks/WhereToArrayBenchmarks.md index 49ef34978..4a7daec43 100644 --- a/Benchmarks/WhereToArrayBenchmarks.md +++ b/Benchmarks/WhereToArrayBenchmarks.md @@ -4,58 +4,57 @@ [WhereToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 408.4 ns | 0.82 ns | 0.68 ns | 1.00 | 0.3519 | - | - | 736 B | -| StructLinq_Array | Array | 100 | 385.2 ns | 0.94 ns | 0.78 ns | 0.94 | 0.1144 | - | - | 240 B | -| Hyperlinq_Array | Array | 100 | 471.4 ns | 1.16 ns | 1.03 ns | 1.15 | 0.1144 | - | - | 240 B | -| Hyperlinq_Span | Array | 100 | 479.2 ns | 2.08 ns | 1.94 ns | 1.17 | 0.1144 | - | - | 240 B | -| Hyperlinq_Memory | Array | 100 | 520.2 ns | 1.69 ns | 1.50 ns | 1.27 | 0.1144 | - | - | 240 B | +| Linq_Array | Array | 100 | 422.3 ns | 1.36 ns | 1.20 ns | 1.00 | 0.3519 | - | - | 736 B | +| StructLinq_Array | Array | 100 | 382.9 ns | 1.39 ns | 1.30 ns | 0.91 | 0.1144 | - | - | 240 B | +| Hyperlinq_Array | Array | 100 | 493.0 ns | 3.14 ns | 2.78 ns | 1.17 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,344.1 ns | 1.97 ns | 1.75 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,257.3 ns | 5.13 ns | 4.80 ns | 0.94 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 506.3 ns | 3.55 ns | 3.33 ns | 0.38 | 0.1144 | - | - | 240 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,224.2 ns | 8.59 ns | 7.17 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,209.0 ns | 2.97 ns | 2.32 ns | 0.99 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 539.5 ns | 2.89 ns | 2.71 ns | 0.44 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,221.0 ns | 2.79 ns | 2.47 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,252.3 ns | 3.72 ns | 3.30 ns | 1.03 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 573.2 ns | 9.72 ns | 8.61 ns | 0.47 | 0.1144 | - | - | 240 B | +| Linq_Collection_Value | Collection_Value | 100 | 1,210.4 ns | 7.42 ns | 6.94 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,205.9 ns | 4.23 ns | 3.96 ns | 1.00 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 522.0 ns | 1.40 ns | 1.24 ns | 0.43 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,205.2 ns | 2.78 ns | 2.46 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Value | List_Value | 100 | 787.0 ns | 1.58 ns | 1.48 ns | 0.65 | 0.1144 | - | - | 240 B | -| Hyperlinq_List_Value | List_Value | 100 | 864.1 ns | 5.16 ns | 4.57 ns | 0.72 | 0.1144 | - | - | 240 B | +| Linq_List_Value | List_Value | 100 | 1,234.6 ns | 2.62 ns | 2.19 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Value | List_Value | 100 | 746.1 ns | 1.91 ns | 1.59 ns | 0.60 | 0.1144 | - | - | 240 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,187.8 ns | 2.97 ns | 2.48 ns | 0.96 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,975.7 ns | 16.61 ns | 14.72 ns | 1.00 | 0.4578 | - | - | 960 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,089.1 ns | 13.45 ns | 11.92 ns | 1.02 | 0.4730 | - | - | 992 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,969.1 ns | 13.03 ns | 12.19 ns | 1.00 | 0.4578 | - | - | 960 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,744.0 ns | 6.22 ns | 5.82 ns | 0.63 | 0.3433 | - | - | 720 B | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 797.6 ns | 6.41 ns | 5.68 ns | 1.00 | 0.3710 | - | - | 776 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 806.1 ns | 1.28 ns | 1.07 ns | 1.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 891.9 ns | 2.48 ns | 2.07 ns | 1.12 | 0.1297 | - | - | 272 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 799.8 ns | 7.74 ns | 6.86 ns | 1.00 | 0.3710 | - | - | 776 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 820.6 ns | 4.80 ns | 4.01 ns | 1.03 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 902.3 ns | 2.42 ns | 2.27 ns | 1.13 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 792.7 ns | 12.23 ns | 9.55 ns | 1.00 | 0.3710 | - | - | 776 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 804.3 ns | 1.83 ns | 1.63 ns | 1.02 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 895.5 ns | 1.64 ns | 1.46 ns | 1.13 | 0.1297 | - | - | 272 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 824.0 ns | 10.71 ns | 10.02 ns | 1.00 | 0.3710 | - | - | 776 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 800.1 ns | 2.62 ns | 2.32 ns | 0.97 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 895.4 ns | 1.71 ns | 1.60 ns | 1.09 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 794.8 ns | 2.19 ns | 1.94 ns | 1.00 | 0.3710 | - | - | 776 B | -| StructLinq_List_Reference | List_Reference | 100 | 810.0 ns | 2.25 ns | 2.11 ns | 1.02 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 844.4 ns | 3.48 ns | 2.90 ns | 1.06 | 0.1144 | - | - | 240 B | +| Linq_List_Reference | List_Reference | 100 | 786.8 ns | 3.06 ns | 2.56 ns | 1.00 | 0.3710 | - | - | 776 B | +| StructLinq_List_Reference | List_Reference | 100 | 803.5 ns | 2.77 ns | 2.16 ns | 1.02 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,148.8 ns | 2.14 ns | 2.01 ns | 1.46 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,921.5 ns | 18.56 ns | 15.49 ns | 1.00 | 0.4578 | - | - | 960 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,269.7 ns | 14.95 ns | 13.98 ns | 1.06 | 0.4807 | - | - | 1008 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,849.0 ns | 16.69 ns | 15.61 ns | 1.00 | 0.4578 | - | - | 960 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,270.8 ns | 7.87 ns | 7.36 ns | 0.73 | 0.3586 | - | - | 760 B | diff --git a/Benchmarks/WhereToListBenchmarks.md b/Benchmarks/WhereToListBenchmarks.md index dbab1aea2..4e8e636c6 100644 --- a/Benchmarks/WhereToListBenchmarks.md +++ b/Benchmarks/WhereToListBenchmarks.md @@ -4,58 +4,57 @@ [WhereToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs) ### References: -- Linq: 4.8.4300.0 +- Linq: 5.0.3 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) - StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) -- NetFabric.Hyperlinq: [3.0.0-beta29](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta29) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042 +BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores - [Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT +.NET Core SDK=6.0.100-preview.1.21103.13 + [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT + .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT Job=.NET Core 5.0 Runtime=.NET Core 5.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 400.6 ns | 2.94 ns | 2.60 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | -| StructLinq_Array | Array | 100 | 431.3 ns | 5.80 ns | 4.85 ns | 1.08 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Array | Array | 100 | 514.6 ns | 4.31 ns | 3.82 ns | 1.28 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Span | Array | 100 | 505.9 ns | 5.18 ns | 4.85 ns | 1.26 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Memory | Array | 100 | 484.4 ns | 5.52 ns | 4.90 ns | 1.21 | 0.01 | 0.1297 | - | - | 272 B | +| Linq_Array | Array | 100 | 375.1 ns | 5.55 ns | 9.28 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | +| StructLinq_Array | Array | 100 | 410.1 ns | 1.43 ns | 1.27 ns | 1.09 | 0.03 | 0.1297 | - | - | 272 B | +| Hyperlinq_Array | Array | 100 | 456.5 ns | 2.38 ns | 1.99 ns | 1.22 | 0.03 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,340.7 ns | 15.61 ns | 13.84 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,269.4 ns | 10.89 ns | 9.10 ns | 0.95 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 592.3 ns | 9.60 ns | 8.51 ns | 0.44 | 0.01 | 0.1297 | - | - | 272 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,153.2 ns | 11.58 ns | 10.83 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,253.5 ns | 4.78 ns | 4.47 ns | 1.09 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 498.4 ns | 1.37 ns | 1.14 ns | 0.43 | 0.00 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,246.4 ns | 11.41 ns | 10.68 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,298.3 ns | 21.72 ns | 19.25 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 553.5 ns | 8.56 ns | 8.00 ns | 0.44 | 0.01 | 0.1297 | - | - | 272 B | +| Linq_Collection_Value | Collection_Value | 100 | 1,149.2 ns | 3.76 ns | 3.33 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,246.2 ns | 4.17 ns | 3.69 ns | 1.08 | 0.00 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 534.1 ns | 1.21 ns | 1.14 ns | 0.46 | 0.00 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,228.4 ns | 4.36 ns | 3.86 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Value | List_Value | 100 | 823.2 ns | 4.09 ns | 3.41 ns | 0.67 | 0.00 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Value | List_Value | 100 | 912.7 ns | 6.66 ns | 6.23 ns | 0.74 | 0.00 | 0.1297 | - | - | 272 B | +| Linq_List_Value | List_Value | 100 | 1,146.6 ns | 2.95 ns | 2.76 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Value | List_Value | 100 | 784.8 ns | 1.36 ns | 1.27 ns | 0.68 | 0.00 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,191.6 ns | 3.49 ns | 3.10 ns | 1.04 | 0.00 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,239.2 ns | 28.51 ns | 23.81 ns | 1.00 | 0.00 | 0.3586 | - | - | 752 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,028.3 ns | 40.70 ns | 33.98 ns | 0.97 | 0.00 | 0.3738 | - | - | 784 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,752.4 ns | 10.63 ns | 9.95 ns | 1.00 | 0.00 | 0.3586 | - | - | 752 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,836.1 ns | 5.23 ns | 4.37 ns | 0.57 | 0.00 | 0.3586 | - | - | 752 B | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 923.7 ns | 9.56 ns | 8.94 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 870.5 ns | 6.22 ns | 4.86 ns | 0.94 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 951.5 ns | 12.88 ns | 12.05 ns | 1.03 | 0.02 | 0.1450 | - | - | 304 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 765.5 ns | 8.02 ns | 7.11 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 823.5 ns | 3.46 ns | 3.24 ns | 1.08 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 882.2 ns | 2.51 ns | 2.35 ns | 1.15 | 0.01 | 0.1450 | - | - | 304 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 825.7 ns | 6.73 ns | 6.30 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 856.7 ns | 8.19 ns | 7.66 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 954.3 ns | 6.18 ns | 5.47 ns | 1.16 | 0.01 | 0.1450 | - | - | 304 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 752.3 ns | 4.44 ns | 4.16 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 824.1 ns | 2.11 ns | 1.76 ns | 1.09 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 899.8 ns | 6.27 ns | 5.56 ns | 1.20 | 0.01 | 0.1450 | - | - | 304 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,044.1 ns | 10.54 ns | 8.80 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Reference | List_Reference | 100 | 868.8 ns | 14.72 ns | 13.05 ns | 0.83 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 914.0 ns | 4.03 ns | 3.15 ns | 0.88 | 0.01 | 0.1297 | - | - | 272 B | +| Linq_List_Reference | List_Reference | 100 | 859.6 ns | 3.99 ns | 3.74 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | +| StructLinq_List_Reference | List_Reference | 100 | 818.0 ns | 2.88 ns | 2.56 ns | 0.95 | 0.00 | 0.1450 | - | - | 304 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,178.0 ns | 2.29 ns | 2.03 ns | 1.37 | 0.01 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,083.8 ns | 25.51 ns | 21.30 ns | 1.00 | 0.00 | 0.3586 | - | - | 752 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,889.0 ns | 23.42 ns | 20.76 ns | 1.13 | 0.00 | 0.3815 | - | - | 800 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,754.1 ns | 27.70 ns | 25.91 ns | 1.00 | 0.00 | 0.3586 | - | - | 752 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,324.2 ns | 6.54 ns | 5.80 ns | 0.75 | 0.00 | 0.3738 | - | - | 792 B | diff --git a/Directory.Build.props b/Directory.Build.props index c658797b2..3d49125fa 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,6 +6,7 @@ Copyright 2019-2021 Antao Almada 9.0 strict + enable diff --git a/NetFabric.Hyperlinq.Abstractions/AsyncFunctionWrapper.cs b/NetFabric.Hyperlinq.Abstractions/AsyncFunctionWrapper.cs index 32621771c..9ab29614a 100644 --- a/NetFabric.Hyperlinq.Abstractions/AsyncFunctionWrapper.cs +++ b/NetFabric.Hyperlinq.Abstractions/AsyncFunctionWrapper.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -12,6 +13,7 @@ public readonly struct AsyncFunctionWrapper public AsyncFunctionWrapper(Func> function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T arg, CancellationToken cancellationToken) => function(arg, cancellationToken); } @@ -24,6 +26,7 @@ public readonly struct AsyncFunctionWrapper public AsyncFunctionWrapper(Func> function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T1 arg1, T2 arg2, CancellationToken cancellationToken) => function(arg1, arg2, cancellationToken); } @@ -36,6 +39,7 @@ public readonly struct AsyncFunctionWrapper public AsyncFunctionWrapper(Func> function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T1 arg1, T2 arg2, T3 arg3, CancellationToken cancellationToken) => function(arg1, arg2, arg3, cancellationToken); } @@ -48,6 +52,7 @@ public readonly struct AsyncFunctionWrapper public AsyncFunctionWrapper(Func> function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, cancellationToken); } @@ -60,6 +65,7 @@ public readonly struct AsyncFunctionWrapper public AsyncFunctionWrapper(Func> function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, cancellationToken); } @@ -72,6 +78,7 @@ public readonly struct AsyncFunctionWrapper public AsyncFunctionWrapper(Func> function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, arg6, cancellationToken); } @@ -84,6 +91,7 @@ public readonly struct AsyncFunctionWrapper public AsyncFunctionWrapper(Func> function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, cancellationToken); } @@ -96,6 +104,7 @@ public readonly struct AsyncFunctionWrapper> function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, cancellationToken); } @@ -108,6 +117,7 @@ public readonly struct AsyncFunctionWrapper> function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, cancellationToken); } diff --git a/NetFabric.Hyperlinq.Abstractions/FunctionInWrapper.cs b/NetFabric.Hyperlinq.Abstractions/FunctionInWrapper.cs index 535c84056..3e8122c43 100644 --- a/NetFabric.Hyperlinq.Abstractions/FunctionInWrapper.cs +++ b/NetFabric.Hyperlinq.Abstractions/FunctionInWrapper.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -10,6 +11,7 @@ public readonly struct FunctionInWrapper public FunctionInWrapper(FunctionIn function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(in T arg) => function(arg); } @@ -22,6 +24,7 @@ public readonly struct FunctionInWrapper public FunctionInWrapper(FunctionIn function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(in T1 arg1, T2 arg2) => function(arg1, arg2); } diff --git a/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs b/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs index 2a27d163c..3ede4fad7 100644 --- a/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs +++ b/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -10,6 +11,7 @@ public readonly struct FunctionWrapper public FunctionWrapper(Func function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke() => function(); } @@ -22,6 +24,7 @@ public readonly struct FunctionWrapper public FunctionWrapper(Func function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T arg) => function(arg); } @@ -34,6 +37,7 @@ public readonly struct FunctionWrapper public FunctionWrapper(Func function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2) => function(arg1, arg2); } @@ -46,6 +50,7 @@ public readonly struct FunctionWrapper public FunctionWrapper(Func function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3) => function(arg1, arg2, arg3); } @@ -58,6 +63,7 @@ public readonly struct FunctionWrapper public FunctionWrapper(Func function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4) => function(arg1, arg2, arg3, arg4); } @@ -70,6 +76,7 @@ public readonly struct FunctionWrapper public FunctionWrapper(Func function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) => function(arg1, arg2, arg3, arg4, arg5); } @@ -82,6 +89,7 @@ public readonly struct FunctionWrapper public FunctionWrapper(Func function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) => function(arg1, arg2, arg3, arg4, arg5, arg6); } @@ -94,6 +102,7 @@ public readonly struct FunctionWrapper public FunctionWrapper(Func function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7); } @@ -106,6 +115,7 @@ public readonly struct FunctionWrapper public FunctionWrapper(Func function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); } @@ -118,6 +128,7 @@ public readonly struct FunctionWrapper function) => this.function = function ?? throw new ArgumentNullException(nameof(function)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); } diff --git a/NetFabric.Hyperlinq.Abstractions/ValueEnumerable.cs b/NetFabric.Hyperlinq.Abstractions/ValueEnumerable.cs index 70789c857..d4078c94f 100644 --- a/NetFabric.Hyperlinq.Abstractions/ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Abstractions/ValueEnumerable.cs @@ -5,9 +5,7 @@ namespace NetFabric.Hyperlinq { public interface IValueEnumerable : IEnumerable - where TEnumerator - : struct - , IEnumerator + where TEnumerator : struct, IEnumerator { [return: NotNull] new TEnumerator GetEnumerator(); } @@ -15,18 +13,14 @@ where TEnumerator public interface IValueReadOnlyCollection : IReadOnlyCollection , IValueEnumerable - where TEnumerator - : struct - , IEnumerator + where TEnumerator : struct, IEnumerator { } public interface IValueReadOnlyList : IReadOnlyList , IValueReadOnlyCollection - where TEnumerator - : struct - , IEnumerator + where TEnumerator : struct, IEnumerator { } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs index 91f301ab0..e15e21d4c 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs @@ -13,75 +13,65 @@ public class AllBenchmarks : RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public bool Linq_Array() - => Enumerable.All(array, _ => true); + => array.All(_ => true); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public bool Linq_Enumerable_Value() - => Enumerable.All(enumerableValue, _ => true); + => enumerableValue.All(_ => true); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public bool Linq_Collection_Value() - => Enumerable.All(collectionValue, _ => true); + => collectionValue.All(_ => true); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public bool Linq_List_Value() - => Enumerable.All(listValue, _ => true); + => listValue.All(_ => true); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.AllAsync(asyncEnumerableValue, _ => true); + => asyncEnumerableValue.AllAsync(_ => true); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public bool Linq_Enumerable_Reference() - => Enumerable.All(enumerableReference, _ => true); + => enumerableReference.All(_ => true); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public bool Linq_Collection_Reference() - => Enumerable.All(collectionReference, _ => true); + => collectionReference.All(_ => true); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public bool Linq_List_Reference() - => Enumerable.All(listReference, _ => true); + => listReference.All(_ => true); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.AllAsync(asyncEnumerableReference, _ => true); + => asyncEnumerableReference.AllAsync(_ => true); // --------------------------------------------------------------------- [BenchmarkCategory("Array")] [Benchmark] public bool Hyperlinq_Array() - => array.All(_ => true); - - [BenchmarkCategory("Array")] - [Benchmark] - public bool Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable().All(_ => true); - - [BenchmarkCategory("Array")] - [Benchmark] - public bool Hyperlinq_Memory() - => memory.AsValueEnumerable().All(_ => true); + => array.AsValueEnumerable().All(_ => true); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public bool Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .All(_ => true); [BenchmarkCategory("Collection_Value")] [Benchmark] public bool Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .All(_ => true); [BenchmarkCategory("List_Value")] @@ -95,7 +85,7 @@ public bool Hyperlinq_List_Value() [Benchmark] public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) + .AsAsyncValueEnumerable() .AllAsync((item, _) => new ValueTask((item & 0x01) == 0)); [BenchmarkCategory("Enumerable_Reference")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs index d74f888b4..af76c757e 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs @@ -13,75 +13,65 @@ public class AnyBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public bool Linq_Array() - => Enumerable.Any(array); + => array.Any(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public bool Linq_Enumerable_Value() - => Enumerable.Any(enumerableValue); + => enumerableValue.Any(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public bool Linq_Collection_Value() - => Enumerable.Any(collectionValue); + => collectionValue.Any(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public bool Linq_List_Value() - => Enumerable.Any(listValue); + => listValue.Any(); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.AnyAsync(asyncEnumerableValue); + => asyncEnumerableValue.AnyAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public bool Linq_Enumerable_Reference() - => Enumerable.Any(enumerableReference); + => enumerableReference.Any(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public bool Linq_Collection_Reference() - => Enumerable.Any(collectionReference); + => collectionReference.Any(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public bool Linq_List_Reference() - => Enumerable.Any(listReference); + => listReference.Any(); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.AnyAsync(asyncEnumerableReference); + => asyncEnumerableReference.AnyAsync(); // --------------------------------------------------------------------- [BenchmarkCategory("Array")] [Benchmark] public bool Hyperlinq_Array() - => array.Any(); - - [BenchmarkCategory("Array")] - [Benchmark] - public bool Hyperlinq_Span() - => array.AsSpan().Any(); - - [BenchmarkCategory("Array")] - [Benchmark] - public bool Hyperlinq_Memory() - => memory.AsValueEnumerable().Any(); + => array.AsValueEnumerable().Any(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public bool Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Any(); [BenchmarkCategory("Collection_Value")] [Benchmark] public bool Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Any(); [BenchmarkCategory("List_Value")] @@ -95,7 +85,7 @@ public bool Hyperlinq_List_Value() [Benchmark] public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) + .AsAsyncValueEnumerable() .AnyAsync(); [BenchmarkCategory("Enumerable_Reference")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs index c2d2c288b..107c5e4b6 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs @@ -13,75 +13,65 @@ public class AnyPredicateBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public bool Linq_Array() - => Enumerable.Any(array, _ => false); + => array.Any(_ => false); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public bool Linq_Enumerable_Value() - => Enumerable.Any(enumerableValue, _ => false); + => enumerableValue.Any(_ => false); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public bool Linq_Collection_Value() - => Enumerable.Any(collectionValue, _ => false); + => collectionValue.Any(_ => false); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public bool Linq_List_Value() - => Enumerable.Any(listValue, _ => false); + => listValue.Any(_ => false); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.AnyAsync(asyncEnumerableValue, _ => false); + => asyncEnumerableValue.AnyAsync(_ => false); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public bool Linq_Enumerable_Reference() - => Enumerable.Any(enumerableReference, _ => false); + => enumerableReference.Any(_ => false); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public bool Linq_Collection_Reference() - => Enumerable.Any(collectionReference, _ => false); + => collectionReference.Any(_ => false); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public bool Linq_List_Reference() - => Enumerable.Any(listReference, _ => false); + => listReference.Any(_ => false); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.AnyAsync(asyncEnumerableReference, _ => false); + => asyncEnumerableReference.AnyAsync(_ => false); // --------------------------------------------------------------------- [BenchmarkCategory("Array")] [Benchmark] public bool Hyperlinq_Array() - => array.Any(_ => false); - - [BenchmarkCategory("Array")] - [Benchmark] - public bool Hyperlinq_Span() - => array.AsSpan().Any(_ => false); - - [BenchmarkCategory("Array")] - [Benchmark] - public bool Hyperlinq_Memory() - => memory.AsValueEnumerable().Any(_ => false); + => array.AsValueEnumerable().Any(_ => false); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public bool Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Any(_ => false); [BenchmarkCategory("Collection_Value")] [Benchmark] public bool Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Any(_ => false); [BenchmarkCategory("List_Value")] @@ -95,7 +85,7 @@ public bool Hyperlinq_List_Value() [Benchmark] public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) + .AsAsyncValueEnumerable() .AnyAsync((item, _) => new ValueTask((item & 0x01) == 0)); [BenchmarkCategory("Enumerable_Reference")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs index 748e6e068..b0bbc8c95 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs @@ -33,7 +33,7 @@ public int Foreach() sum += item; return sum; } - + [Benchmark] public int For() { @@ -46,7 +46,7 @@ public int For() } return sum; } - + [Benchmark] public unsafe int For_Unsafe() { @@ -56,13 +56,13 @@ public unsafe int For_Unsafe() { for (var index = 0; index < end; index++) { - var item = array[index]; + var item = source[index]; sum += item; } } return sum; } - + [Benchmark] public int ForAdamczewski() { @@ -76,13 +76,13 @@ public int ForAdamczewski() long i2 = index + 1; var c = source[i1]; var d = source[i2]; - + sum1 += c; sum2 += d; } return sum1 + sum2; } - + [Benchmark] public unsafe int ForAdamczewskiUnsafe() { @@ -97,14 +97,14 @@ public unsafe int ForAdamczewskiUnsafe() long i2 = index + 1; var c = source[i1]; var d = source[i2]; - + sum1 += c; sum2 += d; } return sum1 + sum2; } } - + [Benchmark] public int Span() { @@ -117,7 +117,7 @@ public int Span() } return sum; } - + [Benchmark] public int Memory() { @@ -130,7 +130,7 @@ public int Memory() } return sum; } - + [Benchmark] public int ArraySegment_Foreach() { @@ -139,7 +139,7 @@ public int ArraySegment_Foreach() sum += item; return sum; } - + [Benchmark] public int ArraySegment_For() { @@ -149,7 +149,7 @@ public int ArraySegment_For() var sum = 0; for (var index = start; index < end; index++) { - var item = source[index]; + var item = source![index]; sum += item; } return sum; @@ -175,20 +175,28 @@ public ArraySegmentWrapper(in ArraySegment source) public Enumerator GetEnumerator() => new(source); - public struct Enumerator + public ref struct Enumerator { - readonly TSource[] array; + readonly ReadOnlySpan source; readonly int end; - int current; + int index; public Enumerator(in ArraySegment source) - => (array, end, current) = (source.Array!, source.Offset + source.Count - 1, -1); + { + this.source = source.Array.AsSpan().Slice(source.Offset, source.Count); + index = -1; + end = index + source.Count; + } - public TSource Current - => array[current]; + public readonly TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++current <= end; + => ++index <= end; } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs index 4a9ce38e4..58146ff60 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs @@ -13,47 +13,47 @@ public class ContainsBenchmarks : SequentialBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public bool Linq_Array() - => Enumerable.Contains(array, Count - 1); - - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark(Baseline = true)] - //public bool Linq_Enumerable_Value() - // => Enumerable.Contains(enumerableValue, Count - 1); - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark(Baseline = true)] - //public bool Linq_Collection_Value() - // => Enumerable.Contains(collectionValue, Count - 1); - - //[BenchmarkCategory("List_Value")] - //[Benchmark(Baseline = true)] - //public bool Linq_List_Value() - // => Enumerable.Contains(listValue, Count - 1); - - //[BenchmarkCategory("AsyncEnumerable_Value")] - //[Benchmark(Baseline = true)] - //public ValueTask Linq_AsyncEnumerable_Value() - // => AsyncEnumerable.ContainsAsync(asyncEnumerableValue, Count - 1); - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark(Baseline = true)] - //public bool Linq_Enumerable_Reference() - // => Enumerable.Contains(enumerableReference, Count - 1); - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark(Baseline = true)] - //public bool Linq_Collection_Reference() - // => Enumerable.Contains(collectionReference, Count - 1); - - //[BenchmarkCategory("List_Reference")] - //[Benchmark(Baseline = true)] - //public bool Linq_List_Reference() - // => Enumerable.Contains(listReference, Count - 1); - - //[BenchmarkCategory("AsyncEnumerable_Reference")] - //[Benchmark(Baseline = true)] - //public ValueTask Linq_AsyncEnumerable_Reference() - // => AsyncEnumerable.ContainsAsync(asyncEnumerableReference, Count - 1); + => array.Contains(Count - 1); + + [BenchmarkCategory("Enumerable_Value")] + [Benchmark(Baseline = true)] + public bool Linq_Enumerable_Value() + => enumerableValue.Contains(Count - 1); + + [BenchmarkCategory("Collection_Value")] + [Benchmark(Baseline = true)] + public bool Linq_Collection_Value() + => Enumerable.Contains(collectionValue, Count - 1); + + [BenchmarkCategory("List_Value")] + [Benchmark(Baseline = true)] + public bool Linq_List_Value() + => Enumerable.Contains(listValue, Count - 1); + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Value() + => asyncEnumerableValue.ContainsAsync(Count - 1); + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark(Baseline = true)] + public bool Linq_Enumerable_Reference() + => enumerableReference.Contains(Count - 1); + + [BenchmarkCategory("Collection_Reference")] + [Benchmark(Baseline = true)] + public bool Linq_Collection_Reference() + => collectionReference.Contains(Count - 1); + + [BenchmarkCategory("List_Reference")] + [Benchmark(Baseline = true)] + public bool Linq_List_Reference() + => listReference.Contains(Count - 1); + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Reference() + => asyncEnumerableReference.ContainsAsync(Count - 1); // --------------------------------------------------------------------- @@ -64,57 +64,61 @@ public bool Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] - public bool Hyperlinq_Span() - => array.AsSpan().Contains(Count - 1); + public bool Hyperlinq_Array_SIMD() + => array.AsValueEnumerable().ContainsVector(Count - 1); - [BenchmarkCategory("Array")] + [BenchmarkCategory("Enumerable_Value")] + [Benchmark] + public bool Hyperlinq_Enumerable_Value() + => enumerableValue.AsValueEnumerable() + .Contains(Count - 1); + + [BenchmarkCategory("Collection_Value")] + [Benchmark] + public bool Hyperlinq_Collection_Value() + => collectionValue.AsValueEnumerable() + .Contains(Count - 1); + + [BenchmarkCategory("List_Value")] + [Benchmark] + public bool Hyperlinq_List_Value() + => listValue + .AsValueEnumerable() + .Contains(Count - 1); + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public ValueTask Hyperlinq_AsyncEnumerable_Value() + => asyncEnumerableValue + .AsAsyncValueEnumerable() + .ContainsAsync(Count - 1); + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark] + public bool Hyperlinq_Enumerable_Reference() + => enumerableReference + .AsValueEnumerable() + .Contains(Count - 1); + + [BenchmarkCategory("Collection_Reference")] + [Benchmark] + public bool Hyperlinq_Collection_Reference() + => collectionReference + .AsValueEnumerable() + .Contains(Count - 1); + + [BenchmarkCategory("List_Reference")] + [Benchmark] + public bool Hyperlinq_List_Reference() + => listReference + .AsValueEnumerable() + .Contains(Count - 1); + + [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark] - public bool Hyperlinq_Span_SIMD() - => array.AsSpan().ContainsVector(Count - 1); - - //[BenchmarkCategory("Array")] - //[Benchmark] - //public bool Hyperlinq_Memory() - // => memory.AsValueEnumerable().Contains(Count - 1); - - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark] - //public bool Hyperlinq_Enumerable_Value() - // => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) - // .Contains(Count - 1); - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark] - //public bool Hyperlinq_Collection_Value() - // => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) - // .Contains(Count - 1); - - //[BenchmarkCategory("List_Value")] - //[Benchmark] - //public bool Hyperlinq_List_Value() - // => listValue - // .AsValueEnumerable() - // .Contains(Count - 1); - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark] - //public bool Hyperlinq_Enumerable_Reference() - // => enumerableReference - // .AsValueEnumerable() - // .Contains(Count - 1); - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark] - //public bool Hyperlinq_Collection_Reference() - // => collectionReference - // .AsValueEnumerable() - // .Contains(Count - 1); - - //[BenchmarkCategory("List_Reference")] - //[Benchmark] - //public bool Hyperlinq_List_Reference() - // => listReference - // .AsValueEnumerable() - // .Contains(Count - 1); + public ValueTask Hyperlinq_AsyncEnumerable_Reference() + => asyncEnumerableReference + .AsAsyncValueEnumerable() + .ContainsAsync(Count - 1); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs index 7984aa4f1..fd1563d9a 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs @@ -14,75 +14,65 @@ public class ContainsComparerBenchmarks: SequentialBenchmarksBase, IEqualityComp [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public bool Linq_Array() - => Enumerable.Contains(array, Count - 1, this); + => array.Contains(Count - 1, this); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public bool Linq_Enumerable_Value() - => Enumerable.Contains(enumerableValue, Count - 1, this); + => enumerableValue.Contains(Count - 1, this); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public bool Linq_Collection_Value() - => Enumerable.Contains(collectionValue, Count - 1, this); + => collectionValue.Contains(Count - 1, this); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public bool Linq_List_Value() - => Enumerable.Contains(listValue, Count - 1, this); + => listValue.Contains(Count - 1, this); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.ContainsAsync(asyncEnumerableValue, Count - 1, this); + => asyncEnumerableValue.ContainsAsync(Count - 1, this); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public bool Linq_Enumerable_Reference() - => Enumerable.Contains(enumerableReference, Count - 1, this); + => enumerableReference.Contains(Count - 1, this); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public bool Linq_Collection_Reference() - => Enumerable.Contains(collectionReference, Count - 1, this); + => collectionReference.Contains(Count - 1, this); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public bool Linq_List_Reference() - => Enumerable.Contains(listReference, Count - 1, this); + => listReference.Contains(Count - 1, this); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.ContainsAsync(asyncEnumerableReference, Count - 1, this); + => asyncEnumerableReference.ContainsAsync(Count - 1, this); // --------------------------------------------------------------------- [BenchmarkCategory("Array")] [Benchmark] public bool Hyperlinq_Array() - => array.Contains(Count - 1, this); - - [BenchmarkCategory("Array")] - [Benchmark] - public bool Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable().Contains(Count - 1, this); - - [BenchmarkCategory("Array")] - [Benchmark] - public bool Hyperlinq_Memory() - => memory.AsValueEnumerable().Contains(Count - 1, this); + => array.AsValueEnumerable().Contains(Count - 1, this); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public bool Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Contains(Count - 1, this); [BenchmarkCategory("Collection_Value")] [Benchmark] public bool Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Contains(Count - 1, this); [BenchmarkCategory("List_Value")] @@ -92,6 +82,13 @@ public bool Hyperlinq_List_Value() .AsValueEnumerable() .Contains(Count - 1, this); + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public ValueTask Hyperlinq_AsyncEnumerable_Value() + => asyncEnumerableValue + .AsAsyncValueEnumerable() + .ContainsAsync(Count - 1, this); + [BenchmarkCategory("Enumerable_Reference")] [Benchmark] public bool Hyperlinq_Enumerable_Reference() @@ -113,6 +110,13 @@ public bool Hyperlinq_List_Reference() .AsValueEnumerable() .Contains(Count - 1, this); + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public ValueTask Hyperlinq_AsyncEnumerable_Reference() + => asyncEnumerableReference + .AsAsyncValueEnumerable() + .ContainsAsync(Count - 1, this); + // --------------------------------------------------------------------- public bool Equals(int x, int y) diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs index 0db84d82d..e515aa10c 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs @@ -14,47 +14,47 @@ public class CountBenchmarks : RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() - => Enumerable.Count(array); + => array.Count(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Value() - => Enumerable.Count(enumerableValue); + => enumerableValue.Count(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int Linq_Collection_Value() - => Enumerable.Count(collectionValue); + => collectionValue.Count(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int Linq_List_Value() - => Enumerable.Count(listValue); + => listValue.Count(); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.CountAsync(asyncEnumerableValue); + => asyncEnumerableValue.CountAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Reference() - => Enumerable.Count(enumerableReference); + => enumerableReference.Count(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int Linq_Collection_Reference() - => Enumerable.Count(collectionReference); + => collectionReference.Count(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int Linq_List_Reference() - => Enumerable.Count(listReference); + => listReference.Count(); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.CountAsync(asyncEnumerableReference); + => asyncEnumerableReference.CountAsync(); // --------------------------------------------------------------------- @@ -112,28 +112,18 @@ public int StructLinq_List_Reference() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Array() - => array.Count(); - - [BenchmarkCategory("Array")] - [Benchmark] - public int Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable().Count(); - - [BenchmarkCategory("Array")] - [Benchmark] - public int Hyperlinq_Memory() - => memory.AsValueEnumerable().Count(); + => array.AsValueEnumerable().Count(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public int Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Count(); [BenchmarkCategory("Collection_Value")] [Benchmark] public int Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Count(); [BenchmarkCategory("List_Value")] @@ -147,7 +137,7 @@ public int Hyperlinq_List_Value() [Benchmark] public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) + .AsAsyncValueEnumerable() .CountAsync(); [BenchmarkCategory("Enumerable_Reference")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs index 0c5b8a7e5..e3da04835 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs @@ -16,7 +16,7 @@ public class DistinctBenchmarks : RandomBenchmarksBase public int Linq_Array() { var sum = 0; - foreach (var item in Enumerable.Distinct(array)) + foreach (var item in array.Distinct()) sum += item; return sum; } @@ -26,7 +26,7 @@ public int Linq_Array() public int Linq_Enumerable_Value() { var sum = 0; - foreach (var item in Enumerable.Distinct(enumerableValue)) + foreach (var item in enumerableValue.Distinct()) sum += item; return sum; } @@ -36,7 +36,7 @@ public int Linq_Enumerable_Value() public int Linq_Collection_Value() { var sum = 0; - foreach (var item in Enumerable.Distinct(collectionValue)) + foreach (var item in collectionValue.Distinct()) sum += item; return sum; } @@ -46,17 +46,17 @@ public int Linq_Collection_Value() public int Linq_List_Value() { var sum = 0; - foreach (var item in Enumerable.Distinct(listValue)) + foreach (var item in listValue.Distinct()) sum += item; return sum; } [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] - public async Task Linq_AsyncEnumerable_Value() + public async ValueTask Linq_AsyncEnumerable_Value() { var sum = 0; - await foreach (var item in AsyncEnumerable.Distinct(asyncEnumerableValue)) + await foreach (var item in asyncEnumerableValue.Distinct()) sum += item; return sum; } @@ -66,7 +66,7 @@ public async Task Linq_AsyncEnumerable_Value() public int Linq_Enumerable_Reference() { var sum = 0; - foreach (var item in Enumerable.Distinct(enumerableReference)) + foreach (var item in enumerableReference.Distinct()) sum += item; return sum; } @@ -76,7 +76,7 @@ public int Linq_Enumerable_Reference() public int Linq_Collection_Reference() { var sum = 0; - foreach (var item in Enumerable.Distinct(collectionReference)) + foreach (var item in collectionReference.Distinct()) sum += item; return sum; } @@ -86,17 +86,17 @@ public int Linq_Collection_Reference() public int Linq_List_Reference() { var sum = 0; - foreach (var item in Enumerable.Distinct(listReference)) + foreach (var item in listReference.Distinct()) sum += item; return sum; } [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] - public async Task Linq_AsyncEnumerable_Reference() + public async ValueTask Linq_AsyncEnumerable_Reference() { var sum = 0; - await foreach (var item in AsyncEnumerable.Distinct(asyncEnumerableReference)) + await foreach (var item in asyncEnumerableReference.Distinct()) sum += item; return sum; } @@ -108,7 +108,7 @@ public async Task Linq_AsyncEnumerable_Reference() public int StructLinq_Array() { var sum = 0; - foreach (var item in array.Distinct(x => x)) + foreach (var item in array.ToStructEnumerable().Distinct(x => x)) sum += item; return sum; } @@ -180,7 +180,7 @@ public int StructLinq_List_Reference() public int Hyperlinq_Array() { var sum = 0; - foreach (var item in array.Distinct()) + foreach (var item in array.AsValueEnumerable().Distinct()) sum += item; return sum; } @@ -210,7 +210,7 @@ public int Hyperlinq_Memory() public int Hyperlinq_Enumerable_Value() { var sum = 0; - foreach (var item in EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()).Distinct()) + foreach (var item in enumerableValue.AsValueEnumerable().Distinct()) sum += item; return sum; } @@ -220,7 +220,7 @@ public int Hyperlinq_Enumerable_Value() public int Hyperlinq_Collection_Value() { var sum = 0; - foreach (var item in ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()).Distinct()) + foreach (var item in collectionValue.AsValueEnumerable().Distinct()) sum += item; return sum; } @@ -237,10 +237,12 @@ public int Hyperlinq_List_Value() [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark] - public async Task Hyperlinq_AsyncEnumerable_Value() + public async ValueTask Hyperlinq_AsyncEnumerable_Value() { var sum = 0; - await foreach (var item in asyncEnumerableValue.AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)).Distinct()) + await foreach (var item in asyncEnumerableValue + .AsAsyncValueEnumerable() + .Distinct()) sum += item; return sum; } @@ -277,7 +279,7 @@ public int Hyperlinq_List_Reference() [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark] - public async Task Hyperlinq_AsyncEnumerable_Reference() + public async ValueTask Hyperlinq_AsyncEnumerable_Reference() { var sum = 0; await foreach (var item in asyncEnumerableReference.AsAsyncValueEnumerable().Distinct()) diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs index aaca139ed..d015f0d01 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs @@ -13,47 +13,47 @@ public class ElementAtBenchmarks: SequentialBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() - => Enumerable.ElementAt(array, Count - 1); + => array.ElementAt(Count - 1); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Value() - => Enumerable.ElementAt(enumerableValue, Count - 1); + => enumerableValue.ElementAt(Count - 1); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int Linq_Collection_Value() - => Enumerable.ElementAt(collectionValue, Count - 1); + => collectionValue.ElementAt(Count - 1); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int Linq_List_Value() - => Enumerable.ElementAt(listValue, Count - 1); + => listValue.ElementAt(Count - 1); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.ElementAtAsync(asyncEnumerableValue, Count - 1); + => asyncEnumerableValue.ElementAtAsync(Count - 1); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Reference() - => Enumerable.ElementAt(enumerableReference, Count - 1); + => enumerableReference.ElementAt(Count - 1); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int Linq_Collection_Reference() - => Enumerable.ElementAt(collectionReference, Count - 1); + => collectionReference.ElementAt(Count - 1); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int Linq_List_Reference() - => Enumerable.ElementAt(listReference, Count - 1); + => listReference.ElementAt(Count - 1); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.ElementAtAsync(asyncEnumerableReference, Count - 1); + => asyncEnumerableReference.ElementAtAsync(Count - 1); // --------------------------------------------------------------------- @@ -62,26 +62,16 @@ public ValueTask Linq_AsyncEnumerable_Reference() public Option Hyperlinq_Array() => array.AsValueEnumerable().ElementAt(Count - 1); - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable().ElementAt(Count - 1); - - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Memory() - => memory.AsValueEnumerable().ElementAt(Count - 1); - [BenchmarkCategory("Enumerable_Value")] [Benchmark] public Option Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .ElementAt(Count - 1); [BenchmarkCategory("Collection_Value")] [Benchmark] public Option Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .ElementAt(Count - 1); [BenchmarkCategory("List_Value")] @@ -91,6 +81,13 @@ public Option Hyperlinq_List_Value() .AsValueEnumerable() .ElementAt(Count - 1); + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public ValueTask> Hyperlinq_AsyncEnumerable_Value() + => asyncEnumerableValue + .AsAsyncValueEnumerable() + .ElementAtAsync(Count - 1); + [BenchmarkCategory("Enumerable_Reference")] [Benchmark] public Option Hyperlinq_Enumerable_Reference() @@ -111,5 +108,12 @@ public Option Hyperlinq_List_Reference() => listReference .AsValueEnumerable() .ElementAt(Count - 1); + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public ValueTask> Hyperlinq_AsyncEnumerable_Reference() + => asyncEnumerableReference + .AsAsyncValueEnumerable() + .ElementAtAsync(Count - 1); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs index 3144972a9..936de168d 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs @@ -13,47 +13,47 @@ public class FirstBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() - => Enumerable.First(array); + => array.First(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Value() - => Enumerable.First(enumerableValue); + => enumerableValue.First(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int Linq_Collection_Value() - => Enumerable.First(collectionValue); + => collectionValue.First(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int Linq_List_Value() - => Enumerable.First(listValue); + => listValue.First(); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.FirstAsync(asyncEnumerableValue); + => asyncEnumerableValue.FirstAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Reference() - => Enumerable.First(enumerableReference); + => enumerableReference.First(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int Linq_Collection_Reference() - => Enumerable.First(collectionReference); + => collectionReference.First(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int Linq_List_Reference() - => Enumerable.First(listReference); + => listReference.First(); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.FirstAsync(asyncEnumerableReference); + => asyncEnumerableReference.FirstAsync(); // --------------------------------------------------------------------- @@ -62,26 +62,16 @@ public ValueTask Linq_AsyncEnumerable_Reference() public Option Hyperlinq_Array() => array.AsValueEnumerable().First(); - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable().First(); - - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Memory() - => memory.AsValueEnumerable().First(); - [BenchmarkCategory("Enumerable_Value")] [Benchmark] public Option Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .First(); [BenchmarkCategory("Collection_Value")] [Benchmark] public Option Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .First(); [BenchmarkCategory("List_Value")] @@ -91,6 +81,13 @@ public Option Hyperlinq_List_Value() .AsValueEnumerable() .First(); + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public ValueTask> Hyperlinq_AsyncEnumerable_Value() + => asyncEnumerableValue + .AsAsyncValueEnumerable() + .FirstAsync(); + [BenchmarkCategory("Enumerable_Reference")] [Benchmark] public Option Hyperlinq_Enumerable_Reference() @@ -111,5 +108,12 @@ public Option Hyperlinq_List_Reference() => listReference .AsValueEnumerable() .First(); + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public ValueTask> Hyperlinq_AsyncEnumerable_Reference() + => asyncEnumerableReference + .AsAsyncValueEnumerable() + .FirstAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/IterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/IterationBenchmarks.cs deleted file mode 100644 index 43334c0d2..000000000 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/IterationBenchmarks.cs +++ /dev/null @@ -1,72 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; - -namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks -{ - [SimpleJob(RuntimeMoniker.NetCoreApp50)] - public class IterationBenchmarks - { - [Params(100_000_000)] - public int Count { get; set; } - - [Benchmark(Baseline = true)] - public int LT() - { - var sum = 0; - foreach (var item in new EnumerableLT(Count)) - sum += item; - return sum; - } - - [Benchmark] - public int LTE() - { - var sum = 0; - foreach (var item in new EnumerableLTE(Count)) - sum += item; - return sum; - } - - readonly struct EnumerableLT - { - readonly int count; - - public EnumerableLT(int count) => this.count = count; - - public Enumerator GetEnumerator() => new(count); - - public struct Enumerator - { - int current; - readonly int end; - - public Enumerator(int count) => (current, end) = (-1, count); - - public int Current => 1; - - public bool MoveNext() => ++current < end; - } - } - - readonly struct EnumerableLTE - { - readonly int count; - - public EnumerableLTE(int count) => this.count = count; - - public Enumerator GetEnumerator() => new(count); - - public struct Enumerator - { - int current; - readonly int end; - - public Enumerator(int count) => (current, end) = (-1, count - 1); - - public int Current => 1; - - public bool MoveNext() => ++current <= end; - } - } - } -} diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs index 333b4d398..c1baf3655 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs @@ -2,6 +2,8 @@ using BenchmarkDotNet.Configs; using StructLinq; using System; +using System.Linq; +using System.Threading.Tasks; namespace NetFabric.Hyperlinq.Benchmarks { @@ -14,70 +16,90 @@ public class SelectBenchmarks : RandomBenchmarksBase public int Linq_Array() { var sum = 0; - foreach (var item in System.Linq.Enumerable.Select(array, item => item)) + foreach (var item in array.Select(item => item)) sum += item; return sum; } - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark(Baseline = true)] - //public int Linq_Enumerable_Value() - //{ - // var sum = 0; - // foreach (var item in System.Linq.Enumerable.Select(enumerableValue, item => item)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark(Baseline = true)] - //public int Linq_Collection_Value() - //{ - // var sum = 0; - // foreach (var item in System.Linq.Enumerable.Select(collectionValue, item => item)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("List_Value")] - //[Benchmark(Baseline = true)] - //public int Linq_List_Value() - //{ - // var sum = 0; - // foreach (var item in System.Linq.Enumerable.Select(listValue, item => item)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark(Baseline = true)] - //public int Linq_Enumerable_Reference() - //{ - // var sum = 0; - // foreach (var item in System.Linq.Enumerable.Select(enumerableReference, item => item)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark(Baseline = true)] - //public int Linq_Collection_Reference() - //{ - // var sum = 0; - // foreach (var item in System.Linq.Enumerable.Select(collectionReference, item => item)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("List_Reference")] - //[Benchmark(Baseline = true)] - //public int Linq_List_Reference() - //{ - // var sum = 0; - // foreach (var item in System.Linq.Enumerable.Select(listReference, item => item)) - // sum += item; - // return sum; - //} + [BenchmarkCategory("Enumerable_Value")] + [Benchmark(Baseline = true)] + public int Linq_Enumerable_Value() + { + var sum = 0; + foreach (var item in enumerableValue.Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("Collection_Value")] + [Benchmark(Baseline = true)] + public int Linq_Collection_Value() + { + var sum = 0; + foreach (var item in collectionValue.Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("List_Value")] + [Benchmark(Baseline = true)] + public int Linq_List_Value() + { + var sum = 0; + foreach (var item in listValue.Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public async ValueTask Linq_AsyncEnumerable_Value() + { + var sum = 0; + await foreach (var item in asyncEnumerableValue.Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark(Baseline = true)] + public int Linq_Enumerable_Reference() + { + var sum = 0; + foreach (var item in enumerableReference.Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("Collection_Reference")] + [Benchmark(Baseline = true)] + public int Linq_Collection_Reference() + { + var sum = 0; + foreach (var item in collectionReference.Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("List_Reference")] + [Benchmark(Baseline = true)] + public int Linq_List_Reference() + { + var sum = 0; + foreach (var item in listReference.Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public async ValueTask Linq_AsyncEnumerable_Reference() + { + var sum = 0; + await foreach (var item in asyncEnumerableReference.Select(item => item)) + sum += item; + return sum; + } // ------------------- @@ -91,91 +113,91 @@ public int StructLinq_Array() return sum; } - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark] - //public int StructLinq_Enumerable_Value() - //{ - // var sum = 0; - // foreach (var item in enumerableValue.ToStructEnumerable().Select(item => item, x => x)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark] - //public int StructLinq_Collection_Value() - //{ - // var sum = 0; - // foreach (var item in collectionValue.ToStructEnumerable().Select(item => item, x => x)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("List_Value")] - //[Benchmark] - //public int StructLinq_List_Value() - //{ - // var sum = 0; - // foreach (var item in listValue.ToStructEnumerable().Select(item => item, x => x)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark] - //public int StructLinq_Enumerable_Reference() - //{ - // var sum = 0; - // foreach (var item in enumerableReference.ToStructEnumerable().Select(item => item, x => x)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark] - //public int StructLinq_Collection_Reference() - //{ - // var sum = 0; - // foreach (var item in collectionReference.ToStructEnumerable().Select(item => item, x => x)) - // sum += item; - // return sum; - //} - - //[BenchmarkCategory("List_Reference")] - //[Benchmark] - //public int StructLinq_List_Reference() - //{ - // var sum = 0; - // foreach (var item in listReference.ToStructEnumerable().Select(item => item, x => x)) - // sum += item; - // return sum; - //} + [BenchmarkCategory("Enumerable_Value")] + [Benchmark] + public int StructLinq_Enumerable_Value() + { + var sum = 0; + foreach (var item in enumerableValue.ToStructEnumerable().Select(item => item, x => x)) + sum += item; + return sum; + } + + [BenchmarkCategory("Collection_Value")] + [Benchmark] + public int StructLinq_Collection_Value() + { + var sum = 0; + foreach (var item in collectionValue.ToStructEnumerable().Select(item => item, x => x)) + sum += item; + return sum; + } + + [BenchmarkCategory("List_Value")] + [Benchmark] + public int StructLinq_List_Value() + { + var sum = 0; + foreach (var item in listValue.ToStructEnumerable().Select(item => item, x => x)) + sum += item; + return sum; + } + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark] + public int StructLinq_Enumerable_Reference() + { + var sum = 0; + foreach (var item in enumerableReference.ToStructEnumerable().Select(item => item, x => x)) + sum += item; + return sum; + } + + [BenchmarkCategory("Collection_Reference")] + [Benchmark] + public int StructLinq_Collection_Reference() + { + var sum = 0; + foreach (var item in collectionReference.ToStructEnumerable().Select(item => item, x => x)) + sum += item; + return sum; + } + + [BenchmarkCategory("List_Reference")] + [Benchmark] + public int StructLinq_List_Reference() + { + var sum = 0; + foreach (var item in listReference.ToStructEnumerable().Select(item => item, x => x)) + sum += item; + return sum; + } // ------------------- -// [BenchmarkCategory("Array")] -// [Benchmark] -// public int Hyperlinq_Array_For() -// { -// var source = array.AsValueEnumerable().Select(item => item); -// var sum = 0; -// for (var index = 0; index < source.Count; index++) -// sum += source[index]; -// return sum; -// } - -//#pragma warning disable HLQ010 // Consider using a 'for' loop instead. -// [BenchmarkCategory("Array")] -// [Benchmark] -// public int Hyperlinq_Array_Foreach() -// { -// var sum = 0; -// foreach (var item in array.AsValueEnumerable().Select(item => item)) -// sum += item; -// return sum; -// } -//#pragma warning restore HLQ010 // Consider using a 'for' loop instead. + [BenchmarkCategory("Array")] + [Benchmark] + public int Hyperlinq_Array_For() + { + var source = array.AsValueEnumerable().Select(item => item); + var sum = 0; + for (var index = 0; index < source.Count; index++) + sum += source[index]; + return sum; + } + +#pragma warning disable HLQ010 // Consider using a 'for' loop instead. + [BenchmarkCategory("Array")] + [Benchmark] + public int Hyperlinq_Array_Foreach() + { + var sum = 0; + foreach (var item in array.AsValueEnumerable().Select(item => item)) + sum += item; + return sum; + } +#pragma warning restore HLQ010 // Consider using a 'for' loop instead. [BenchmarkCategory("Array")] [Benchmark] @@ -223,93 +245,113 @@ public int Hyperlinq_Memory_Foreach() } #pragma warning restore HLQ010 // Consider using a 'for' loop instead. - // [BenchmarkCategory("Enumerable_Value")] - // [Benchmark] - // public int Hyperlinq_Enumerable_Value() - // { - // var sum = 0; - // foreach (var item in EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) - // .Select(item => item)) - // sum += item; - // return sum; - // } - - // [BenchmarkCategory("Collection_Value")] - // [Benchmark] - // public int Hyperlinq_Collection_Value() - // { - // var sum = 0; - // foreach (var item in ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) - // .Select(item => item)) - // sum += item; - // return sum; - // } - - // [BenchmarkCategory("List_Value")] - // [Benchmark] - // public int Hyperlinq_List_Value_For() - // { - // var source = listValue.AsValueEnumerable().Select(item => item); - // var sum = 0; - // for (var index = 0; index < source.Count; index++) - // { - // var item = source[index]; - // sum += item; - // } - // return sum; - // } - - // [BenchmarkCategory("List_Value")] - // [Benchmark] - // public int Hyperlinq_List_Value_Foreach() - // { - // var sum = 0; - // foreach (var item in listValue.AsValueEnumerable().Select(item => item)) - // sum += item; - // return sum; - // } - - // [BenchmarkCategory("Enumerable_Reference")] - // [Benchmark] - // public int Hyperlinq_Enumerable_Reference() - // { - // var sum = 0; - // foreach (var item in enumerableReference.AsValueEnumerable().Select(item => item)) - // sum += item; - // return sum; - // } - - // [BenchmarkCategory("Collection_Reference")] - // [Benchmark] - // public int Hyperlinq_Collection_Reference() - // { - // var sum = 0; - // foreach (var item in collectionReference.AsValueEnumerable().Select(item => item)) - // sum += item; - // return sum; - // } - - // [BenchmarkCategory("List_Reference")] - // [Benchmark] - // public int Hyperlinq_List_Reference_For() - // { - // var source = listReference.AsValueEnumerable().Select(item => item); - // var sum = 0; - // for (var index = 0; index < source.Count; index++) - // sum += source[index]; - // return sum; - // } - - //#pragma warning disable HLQ010 // Consider using a 'for' loop instead. - // [BenchmarkCategory("List_Reference")] - // [Benchmark] - // public int Hyperlinq_List_Reference_Foreach() - // { - // var sum = 0; - // foreach (var item in listReference.AsValueEnumerable().Select(item => item)) - // sum += item; - // return sum; - // } - //#pragma warning restore HLQ010 // Consider using a 'for' loop instead. + [BenchmarkCategory("Enumerable_Value")] + [Benchmark] + public int Hyperlinq_Enumerable_Value() + { + var sum = 0; + foreach (var item in enumerableValue.AsValueEnumerable() + .Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("Collection_Value")] + [Benchmark] + public int Hyperlinq_Collection_Value() + { + var sum = 0; + foreach (var item in collectionValue.AsValueEnumerable() + .Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("List_Value")] + [Benchmark] + public int Hyperlinq_List_Value_For() + { + var source = listValue.AsValueEnumerable().Select(item => item); + var sum = 0; + for (var index = 0; index < source.Count; index++) + { + var item = source[index]; + sum += item; + } + return sum; + } + + [BenchmarkCategory("List_Value")] + [Benchmark] + public int Hyperlinq_List_Value_Foreach() + { + var sum = 0; + foreach (var item in listValue.AsValueEnumerable().Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public async ValueTask Hyperlinq_AsyncEnumerable_Value() + { + var sum = 0; + await foreach (var item in asyncEnumerableValue.AsAsyncValueEnumerable().Select((item, _) => new ValueTask(item))) + sum += item; + return sum; + } + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark] + public int Hyperlinq_Enumerable_Reference() + { + var sum = 0; + foreach (var item in enumerableReference.AsValueEnumerable().Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("Collection_Reference")] + [Benchmark] + public int Hyperlinq_Collection_Reference() + { + var sum = 0; + foreach (var item in collectionReference.AsValueEnumerable().Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("List_Reference")] + [Benchmark] + public int Hyperlinq_List_Reference_For() + { + var source = listReference.AsValueEnumerable().Select(item => item); + var sum = 0; + for (var index = 0; index < source.Count; index++) + sum += source[index]; + return sum; + } + +#pragma warning disable HLQ010 // Consider using a 'for' loop instead. + [BenchmarkCategory("List_Reference")] + [Benchmark] + public int Hyperlinq_List_Reference_Foreach() + { + var sum = 0; + foreach (var item in listReference.AsValueEnumerable().Select(item => item)) + sum += item; + return sum; + } +#pragma warning restore HLQ010 // Consider using a 'for' loop instead. + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public async ValueTask Hyperlinq_AsyncEnumerable_Reference() + { + var sum = 0; + await foreach (var item in asyncEnumerableReference.AsAsyncValueEnumerable().Select((item, _) => new ValueTask(item))) + sum += item; + return sum; + } } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs index 0f5dacde4..b8d3002db 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs @@ -14,55 +14,55 @@ public class SelectCountBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() - => Enumerable.Select(array, item => item) + => array.Select(item => item) .Count(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Value() - => Enumerable.Select(enumerableValue, item => item) + => enumerableValue.Select(item => item) .Count(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int Linq_Collection_Value() - => Enumerable.Select(collectionValue, item => item) + => collectionValue.Select(item => item) .Count(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int Linq_List_Value() - => Enumerable.Select(listValue, item => item) + => listValue.Select(item => item) .Count(); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.Select(asyncEnumerableValue, item => item) + => asyncEnumerableValue.Select(item => item) .CountAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Reference() - => Enumerable.Select(enumerableReference, item => item) + => enumerableReference.Select(item => item) .Count(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int Linq_Collection_Reference() - => Enumerable.Select(collectionReference, item => item) + => collectionReference.Select(item => item) .Count(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int Linq_List_Reference() - => Enumerable.Select(listReference, item => item) + => listReference.Select(item => item) .Count(); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.Select(asyncEnumerableReference, item => item) + => asyncEnumerableReference.Select(item => item) .CountAsync(); // --------------------------------------------------------------------- @@ -128,36 +128,21 @@ public int StructLinq_List_Reference() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Array() - => array - .Select(item => item) - .Count(); - - [BenchmarkCategory("Array")] - [Benchmark] - public int Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable() + => array.AsValueEnumerable() .Select(item => item) .Count(); - [BenchmarkCategory("Array")] - [Benchmark] - public int Hyperlinq_Memory() - => memory.AsValueEnumerable() - .Select(item => item) - .Count(); - - [BenchmarkCategory("Enumerable_Value")] [Benchmark] public int Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Select(item => item) .Count(); [BenchmarkCategory("Collection_Value")] [Benchmark] public int Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Select(item => item) .Count(); @@ -173,8 +158,8 @@ public int Hyperlinq_List_Value() [Benchmark] public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - .Select(item => item) + .AsAsyncValueEnumerable() + .Select((item, _) => new ValueTask(item)) .CountAsync(); [BenchmarkCategory("Enumerable_Reference")] @@ -206,7 +191,7 @@ public int Hyperlinq_List_Reference() public ValueTask Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() - .Select(item => item) + .Select((item, _) => new ValueTask(item)) .CountAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectManyBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectManyBenchmarks.cs index 521afd411..0374017e8 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectManyBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectManyBenchmarks.cs @@ -14,7 +14,7 @@ public class SelectManyBenchmarks : RandomBenchmarksBase public int Linq_Array() { var sum = 0; - foreach (var item in Enumerable.SelectMany(array, item => EnumerableEx.Return(item))) + foreach (var item in array.SelectMany(item => EnumerableEx.Return(item))) sum += item; return sum; } @@ -24,7 +24,7 @@ public int Linq_Array() public int Linq_Enumerable_Value() { var sum = 0; - foreach (var item in Enumerable.SelectMany(enumerableValue, item => EnumerableEx.Return(item))) + foreach (var item in enumerableValue.SelectMany(item => EnumerableEx.Return(item))) sum += item; return sum; } @@ -34,7 +34,7 @@ public int Linq_Enumerable_Value() public int Linq_Collection_Value() { var sum = 0; - foreach (var item in Enumerable.SelectMany(collectionValue, item => EnumerableEx.Return(item))) + foreach (var item in collectionValue.SelectMany(item => EnumerableEx.Return(item))) sum += item; return sum; } @@ -44,17 +44,17 @@ public int Linq_Collection_Value() public int Linq_List_Value() { var sum = 0; - foreach (var item in Enumerable.SelectMany(listValue, item => EnumerableEx.Return(item))) + foreach (var item in listValue.SelectMany(item => EnumerableEx.Return(item))) sum += item; return sum; } [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] - public async Task Linq_AsyncEnumerable_Value() + public async ValueTask Linq_AsyncEnumerable_Value() { var sum = 0; - await foreach (var item in AsyncEnumerable.SelectMany(asyncEnumerableValue, item => AsyncEnumerableEx.Return(item))) + await foreach (var item in asyncEnumerableValue.SelectMany(item => AsyncEnumerableEx.Return(item))) sum += item; return sum; } @@ -64,7 +64,7 @@ public async Task Linq_AsyncEnumerable_Value() public int Linq_Enumerable_Reference() { var sum = 0; - foreach (var item in Enumerable.SelectMany(enumerableReference, item => EnumerableEx.Return(item))) + foreach (var item in enumerableReference.SelectMany(item => EnumerableEx.Return(item))) sum += item; return sum; } @@ -74,7 +74,7 @@ public int Linq_Enumerable_Reference() public int Linq_Collection_Reference() { var sum = 0; - foreach (var item in Enumerable.SelectMany(collectionReference, item => EnumerableEx.Return(item))) + foreach (var item in collectionReference.SelectMany(item => EnumerableEx.Return(item))) sum += item; return sum; } @@ -84,17 +84,17 @@ public int Linq_Collection_Reference() public int Linq_List_Reference() { var sum = 0; - foreach (var item in Enumerable.SelectMany(listReference, item => EnumerableEx.Return(item))) + foreach (var item in listReference.SelectMany(item => EnumerableEx.Return(item))) sum += item; return sum; } [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] - public async Task Linq_AsyncEnumerable_Reference() + public async ValueTask Linq_AsyncEnumerable_Reference() { var sum = 0; - await foreach (var item in AsyncEnumerable.SelectMany(asyncEnumerableReference, item => AsyncEnumerableEx.Return(item))) + await foreach (var item in asyncEnumerableReference.SelectMany(item => AsyncEnumerableEx.Return(item))) sum += item; return sum; } @@ -106,7 +106,8 @@ public async Task Linq_AsyncEnumerable_Reference() public int Hyperlinq_Array() { var sum = 0; - foreach (var item in array.AsValueEnumerable().SelectMany, ValueEnumerable.ReturnEnumerable.DisposableEnumerator, int>(item => ValueEnumerable.Return(item))) + foreach (var item in array.AsValueEnumerable() + .SelectMany, ValueEnumerable.ReturnEnumerable.DisposableEnumerator, int>(item => ValueEnumerable.Return(item))) sum += item; return sum; } @@ -116,7 +117,8 @@ public int Hyperlinq_Array() public int Hyperlinq_Memory() { var sum = 0; - foreach (var item in memory.AsValueEnumerable().SelectMany, ValueEnumerable.ReturnEnumerable.DisposableEnumerator, int>(item => ValueEnumerable.Return(item))) + foreach (var item in memory.AsValueEnumerable() + .SelectMany, ValueEnumerable.ReturnEnumerable.DisposableEnumerator, int>(item => ValueEnumerable.Return(item))) sum += item; return sum; } @@ -126,7 +128,7 @@ public int Hyperlinq_Memory() public int Hyperlinq_Enumerable_Value() { var sum = 0; - foreach (var item in EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + foreach (var item in enumerableValue.AsValueEnumerable() .SelectMany(item => ValueEnumerable.Return(item))) sum += item; return sum; @@ -137,7 +139,7 @@ public int Hyperlinq_Enumerable_Value() public int Hyperlinq_Collection_Value() { var sum = 0; - foreach (var item in EnumerableExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + foreach (var item in collectionValue.AsValueEnumerable() .SelectMany(item => ValueEnumerable.Return(item))) sum += item; return sum; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs index d97ed313a..b7a39998a 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs @@ -14,56 +14,56 @@ public class SelectSumBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() - => Enumerable.Select(array, item => item) + => array.Select(item => item) .Sum(); - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark(Baseline = true)] - //public int Linq_Enumerable_Value() - // => Enumerable.Select(enumerableValue, item => item) - // .Sum(); - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark(Baseline = true)] - //public int Linq_Collection_Value() - // => Enumerable.Select(collectionValue, item => item) - // .Sum(); - - //[BenchmarkCategory("List_Value")] - //[Benchmark(Baseline = true)] - //public int Linq_List_Value() - // => Enumerable.Select(listValue, item => item) - // .Sum(); - - //[BenchmarkCategory("AsyncEnumerable_Value")] - //[Benchmark(Baseline = true)] - //public ValueTask Linq_AsyncEnumerable_Value() - // => AsyncEnumerable.Select(asyncEnumerableValue, item => item) - // .SumAsync(); - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark(Baseline = true)] - //public int Linq_Enumerable_Reference() - // => Enumerable.Select(enumerableReference, item => item) - // .Sum(); - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark(Baseline = true)] - //public int Linq_Collection_Reference() - // => Enumerable.Select(collectionReference, item => item) - // .Sum(); - - //[BenchmarkCategory("List_Reference")] - //[Benchmark(Baseline = true)] - //public int Linq_List_Reference() - // => Enumerable.Select(listReference, item => item) - // .Sum(); - - //[BenchmarkCategory("AsyncEnumerable_Reference")] - //[Benchmark(Baseline = true)] - //public ValueTask Linq_AsyncEnumerable_Reference() - // => AsyncEnumerable.Select(asyncEnumerableReference, item => item) - // .SumAsync(); + [BenchmarkCategory("Enumerable_Value")] + [Benchmark(Baseline = true)] + public int Linq_Enumerable_Value() + => enumerableValue.Select(item => item) + .Sum(); + + [BenchmarkCategory("Collection_Value")] + [Benchmark(Baseline = true)] + public int Linq_Collection_Value() + => collectionValue.Select(item => item) + .Sum(); + + [BenchmarkCategory("List_Value")] + [Benchmark(Baseline = true)] + public int Linq_List_Value() + => listValue.Select(item => item) + .Sum(); + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Value() + => asyncEnumerableValue.Select(item => item) + .SumAsync(); + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark(Baseline = true)] + public int Linq_Enumerable_Reference() + => enumerableReference.Select(item => item) + .Sum(); + + [BenchmarkCategory("Collection_Reference")] + [Benchmark(Baseline = true)] + public int Linq_Collection_Reference() + => collectionReference.Select(item => item) + .Sum(); + + [BenchmarkCategory("List_Reference")] + [Benchmark(Baseline = true)] + public int Linq_List_Reference() + => listReference.Select(item => item) + .Sum(); + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Reference() + => asyncEnumerableReference.Select(item => item) + .SumAsync(); // --------------------------------------------------------------------- @@ -75,53 +75,53 @@ public int StructLinq_Array() .Select(item => item, x => x) .Sum(x => x); - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark] - //public int StructLinq_Enumerable_Value() - // => enumerableValue - // .ToStructEnumerable() - // .Select(item => item, x => x) - // .Sum(x => x); - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark] - //public int StructLinq_Collection_Value() - // => collectionValue - // .ToStructEnumerable() - // .Select(item => item, x => x) - // .Sum(x => x); - - //[BenchmarkCategory("List_Value")] - //[Benchmark] - //public int StructLinq_List_Value() - // => listValue - // .ToStructEnumerable() - // .Select(item => item, x => x) - // .Sum(x => x); - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark] - //public int StructLinq_Enumerable_Reference() - // => enumerableReference - // .ToStructEnumerable() - // .Select(item => item, x => x) - // .Sum(x => x); - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark] - //public int StructLinq_Collection_Reference() - // => collectionReference - // .ToStructEnumerable() - // .Select(item => item, x => x) - // .Sum(x => x); - - //[BenchmarkCategory("List_Reference")] - //[Benchmark] - //public int StructLinq_List_Reference() - // => listReference - // .ToStructEnumerable() - // .Select(item => item, x => x) - // .Sum(x => x); + [BenchmarkCategory("Enumerable_Value")] + [Benchmark] + public int StructLinq_Enumerable_Value() + => enumerableValue + .ToStructEnumerable() + .Select(item => item, x => x) + .Sum(x => x); + + [BenchmarkCategory("Collection_Value")] + [Benchmark] + public int StructLinq_Collection_Value() + => collectionValue + .ToStructEnumerable() + .Select(item => item, x => x) + .Sum(x => x); + + [BenchmarkCategory("List_Value")] + [Benchmark] + public int StructLinq_List_Value() + => listValue + .ToStructEnumerable() + .Select(item => item, x => x) + .Sum(x => x); + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark] + public int StructLinq_Enumerable_Reference() + => enumerableReference + .ToStructEnumerable() + .Select(item => item, x => x) + .Sum(x => x); + + [BenchmarkCategory("Collection_Reference")] + [Benchmark] + public int StructLinq_Collection_Reference() + => collectionReference + .ToStructEnumerable() + .Select(item => item, x => x) + .Sum(x => x); + + [BenchmarkCategory("List_Reference")] + [Benchmark] + public int StructLinq_List_Reference() + => listReference + .ToStructEnumerable() + .Select(item => item, x => x) + .Sum(x => x); // --------------------------------------------------------------------- @@ -134,86 +134,71 @@ public int Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] - public int Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable() + public int Hyperlinq_Array_SIMD() + => array.AsValueEnumerable() + .SelectVector(item => item, item => item) + .Sum(); + + [BenchmarkCategory("Enumerable_Value")] + [Benchmark] + public int Hyperlinq_Enumerable_Value() + => enumerableValue.AsValueEnumerable() .Select(item => item) .Sum(); - [BenchmarkCategory("Array")] + [BenchmarkCategory("Collection_Value")] [Benchmark] - public int Hyperlinq_Span_SIMD() - => array.AsSpan().AsValueEnumerable() - .SelectVector(item => item, item => item) + public int Hyperlinq_Collection_Value() + => collectionValue.AsValueEnumerable() + .Select(item => item) .Sum(); - //[BenchmarkCategory("Array")] - //[Benchmark] - //public int Hyperlinq_Memory() - // => memory.AsValueEnumerable() - // .Select(item => item) - // .Sum(); - - - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark] - //public int Hyperlinq_Enumerable_Value() - // => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) - // .Select(item => item) - // .Sum(); - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark] - //public int Hyperlinq_Collection_Value() - // => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) - // .Select(item => item) - // .Sum(); - - //[BenchmarkCategory("List_Value")] - //[Benchmark] - //public int Hyperlinq_List_Value() - // => listValue - // .AsValueEnumerable() - // .Select(item => item) - // .Sum(); - - //[BenchmarkCategory("AsyncEnumerable_Value")] - //[Benchmark] - //public ValueTask Hyperlinq_AsyncEnumerable_Value() - // => asyncEnumerableValue - // .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - // .Select(item => item) - // .SumAsync(); - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark] - //public int Hyperlinq_Enumerable_Reference() - // => enumerableReference - // .AsValueEnumerable() - // .Select(item => item) - // .Sum(); - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark] - //public int Hyperlinq_Collection_Reference() - // => collectionReference - // .AsValueEnumerable() - // .Select(item => item) - // .Sum(); - - //[BenchmarkCategory("List_Reference")] - //[Benchmark] - //public int Hyperlinq_List_Reference() - // => listReference - // .AsValueEnumerable() - // .Select(item => item) - // .Sum(); - - //[BenchmarkCategory("AsyncEnumerable_Reference")] - //[Benchmark] - //public ValueTask Hyperlinq_AsyncEnumerable_Reference() - // => asyncEnumerableReference - // .AsAsyncValueEnumerable() - // .Select(item => item) - // .SumAsync(); + [BenchmarkCategory("List_Value")] + [Benchmark] + public int Hyperlinq_List_Value() + => listValue + .AsValueEnumerable() + .Select(item => item) + .Sum(); + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public ValueTask Hyperlinq_AsyncEnumerable_Value() + => asyncEnumerableValue + .AsAsyncValueEnumerable() + .Select((item, _) => new ValueTask(item)) + .SumAsync(); + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark] + public int Hyperlinq_Enumerable_Reference() + => enumerableReference + .AsValueEnumerable() + .Select(item => item) + .Sum(); + + [BenchmarkCategory("Collection_Reference")] + [Benchmark] + public int Hyperlinq_Collection_Reference() + => collectionReference + .AsValueEnumerable() + .Select(item => item) + .Sum(); + + [BenchmarkCategory("List_Reference")] + [Benchmark] + public int Hyperlinq_List_Reference() + => listReference + .AsValueEnumerable() + .Select(item => item) + .Sum(); + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public ValueTask Hyperlinq_AsyncEnumerable_Reference() + => asyncEnumerableReference + .AsAsyncValueEnumerable() + .Select((item, _) => new ValueTask(item)) + .SumAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs index 7b9dc4ba9..9c8e1dd8e 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs @@ -15,37 +15,47 @@ public class SelectToArrayBenchmarks : RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int[] Linq_Array() - => Enumerable.Select(array, item => item).ToArray(); + => array.Select(item => item).ToArray(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int[] Linq_Enumerable_Value() - => Enumerable.Select(enumerableValue, item => item).ToArray(); + => enumerableValue.Select(item => item).ToArray(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int[] Linq_Collection_Value() - => Enumerable.Select(collectionValue, item => item).ToArray(); + => collectionValue.Select(item => item).ToArray(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int[] Linq_List_Value() - => Enumerable.Select(listValue, item => item).ToArray(); + => listValue.Select(item => item).ToArray(); + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Value() + => asyncEnumerableValue.Select(item => item).ToArrayAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int[] Linq_Enumerable_Reference() - => Enumerable.Select(enumerableReference, item => item).ToArray(); + => enumerableReference.Select(item => item).ToArray(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int[] Linq_Collection_Reference() - => Enumerable.Select(collectionReference, item => item).ToArray(); + => collectionReference.Select(item => item).ToArray(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int[] Linq_List_Reference() - => Enumerable.Select(listReference, item => item).ToArray(); + => listReference.Select(item => item).ToArray(); + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Reference() + => asyncEnumerableReference.Select(item => item).ToArrayAsync(); // --------------------------------------------------------------------- @@ -124,36 +134,22 @@ public int[] Hyperlinq_Array() [BenchmarkCategory("Array")] [Benchmark] - public int[] Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable() - .Select(item => item) - .ToArray(); - - [BenchmarkCategory("Array")] - [Benchmark] - public int[] Hyperlinq_Span_SIMD() - => array.AsSpan().AsValueEnumerable() + public int[] Hyperlinq_Array_SIMD() + => array.AsValueEnumerable() .SelectVector(item => item, item => item) .ToArray(); - [BenchmarkCategory("Array")] - [Benchmark] - public int[] Hyperlinq_Memory() - => memory.AsValueEnumerable() - .Select(item => item) - .ToArray(); - [BenchmarkCategory("Enumerable_Value")] [Benchmark] public int[] Hyperlinq_Enumerable_Value() - => enumerableValue.AsValueEnumerable(enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Select(item => item) .ToArray(); [BenchmarkCategory("Collection_Value")] [Benchmark] public int[] Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Select(item => item) .ToArray(); @@ -169,8 +165,8 @@ public int[] Hyperlinq_List_Value() [Benchmark] public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - .Select(item => item) + .AsAsyncValueEnumerable() + .Select((item, _) => new ValueTask(item)) .ToArrayAsync(); [BenchmarkCategory("Enumerable_Reference")] @@ -202,7 +198,7 @@ public int[] Hyperlinq_List_Reference() public ValueTask Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() - .Select(item => item) + .Select((item, _) => new ValueTask(item)) .ToArrayAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs index c26e8c1af..287e4bf63 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs @@ -14,44 +14,44 @@ public class SelectToListBenchmarks: RandomBenchmarksBase { [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] - public List Linq_List() - => Enumerable.Select(array, item => item).ToList(); + public List Linq_Array() + => array.Select(item => item).ToList(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public List Linq_Enumerable_Value() - => Enumerable.Select(enumerableValue, item => item).ToList(); + => enumerableValue.Select(item => item).ToList(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public List Linq_Collection_Value() - => Enumerable.Select(collectionValue, item => item).ToList(); + => collectionValue.Select(item => item).ToList(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public List Linq_List_Value() - => Enumerable.Select(listValue, item => item).ToList(); + => listValue.Select(item => item).ToList(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public List Linq_Enumerable_Reference() - => Enumerable.Select(enumerableReference, item => item).ToList(); + => enumerableReference.Select(item => item).ToList(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public List Linq_Collection_Reference() - => Enumerable.Select(collectionReference, item => item).ToList(); + => collectionReference.Select(item => item).ToList(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public List Linq_List_Reference() - => Enumerable.Select(listReference, item => item).ToList(); + => listReference.Select(item => item).ToList(); // --------------------------------------------------------------------- [BenchmarkCategory("Array")] [Benchmark] - public List StructLinq_List() + public List StructLinq_Array() => array .ToStructEnumerable() .Select(item => item, x => x) @@ -109,36 +109,29 @@ public List StructLinq_List_Reference() [BenchmarkCategory("Array")] [Benchmark] - public List Hyperlinq_List() - => array - .Select(item => item) - .ToList(); - - [BenchmarkCategory("Array")] - [Benchmark] - public List Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable() + public List Hyperlinq_Array() + => array.AsValueEnumerable() .Select(item => item) .ToList(); [BenchmarkCategory("Array")] [Benchmark] - public List Hyperlinq_Memory() - => memory.AsValueEnumerable() - .Select(item => item) + public List Hyperlinq_Array_SIMD() + => array.AsValueEnumerable() + .SelectVector(item => item, item => item) .ToList(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public List Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Select(item => item) .ToList(); [BenchmarkCategory("Collection_Value")] [Benchmark] public List Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Select(item => item) .ToList(); @@ -154,8 +147,8 @@ public List Hyperlinq_List_Value() [Benchmark] public ValueTask> Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - .Select(item => item) + .AsAsyncValueEnumerable() + .Select((item, _) => new ValueTask(item)) .ToListAsync(); [BenchmarkCategory("Enumerable_Reference")] @@ -187,7 +180,7 @@ public List Hyperlinq_List_Reference() public ValueTask> Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() - .Select(item => item) + .Select((item, _) => new ValueTask(item)) .ToListAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs index 7ebee45e4..b4c595ac2 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs @@ -18,47 +18,47 @@ public class SingleBenchmarks : SingleBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() => - Enumerable.Single(array); + array.Single(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Value() => - Enumerable.Single(enumerableValue); + enumerableValue.Single(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int Linq_Collection_Value() => - Enumerable.Single(collectionValue); + collectionValue.Single(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int Linq_List_Value() => - Enumerable.Single(listValue); + listValue.Single(); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() => - AsyncEnumerable.SingleAsync(asyncEnumerableValue); + asyncEnumerableValue.SingleAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Reference() => - Enumerable.Single(enumerableReference); + enumerableReference.Single(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int Linq_Collection_Reference() => - Enumerable.Single(collectionReference); + collectionReference.Single(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int Linq_List_Reference() => - Enumerable.Single(listReference); + listReference.Single(); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() => - AsyncEnumerable.SingleAsync(asyncEnumerableReference); + asyncEnumerableReference.SingleAsync(); // --------------------------------------------------------------------- @@ -67,26 +67,16 @@ public ValueTask Linq_AsyncEnumerable_Reference() => public Option Hyperlinq_Array() => array.AsValueEnumerable().Single(); - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Span() => - array.AsSpan().AsValueEnumerable().Single(); - - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Memory() => - memory.AsValueEnumerable().Single(); - [BenchmarkCategory("Enumerable_Value")] [Benchmark] public Option Hyperlinq_Enumerable_Value() => - EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + enumerableValue.AsValueEnumerable() .Single(); [BenchmarkCategory("Collection_Value")] [Benchmark] public Option Hyperlinq_Collection_Value() => - ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + collectionValue.AsValueEnumerable() .Single(); [BenchmarkCategory("List_Value")] @@ -99,7 +89,7 @@ public Option Hyperlinq_List_Value() => [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark] public ValueTask> Hyperlinq_AsyncEnumerable_Value() => - asyncEnumerableValue.AsAsyncValueEnumerable((enumerable, cancellationToken) => enumerable.GetAsyncEnumerator(cancellationToken)) + asyncEnumerableValue.AsAsyncValueEnumerable() .SingleAsync(); [BenchmarkCategory("Enumerable_Reference")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs index 418f6167d..39fe01e62 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs @@ -16,7 +16,7 @@ public class SkipTakeBenchmarks : RandomSkipBenchmarksBase public int Linq_Array() { var sum = 0; - foreach (var item in Enumerable.Skip(array, Skip).Take(Count)) + foreach (var item in array.Skip(Skip).Take(Count)) sum += item; return sum; } @@ -26,7 +26,7 @@ public int Linq_Array() public int Linq_Enumerable_Value() { var sum = 0; - foreach (var item in Enumerable.Skip(enumerableValue, Skip).Take(Count)) + foreach (var item in enumerableValue.Skip(Skip).Take(Count)) sum += item; return sum; } @@ -36,7 +36,7 @@ public int Linq_Enumerable_Value() public int Linq_Collection_Value() { var sum = 0; - foreach (var item in Enumerable.Skip(collectionValue, Skip).Take(Count)) + foreach (var item in collectionValue.Skip(Skip).Take(Count)) sum += item; return sum; } @@ -46,17 +46,17 @@ public int Linq_Collection_Value() public int Linq_List_Value() { var sum = 0; - foreach (var item in Enumerable.Skip(listValue, Skip).Take(Count)) + foreach (var item in listValue.Skip(Skip).Take(Count)) sum += item; return sum; } [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] - public async Task Linq_AsyncEnumerable_Value() + public async ValueTask Linq_AsyncEnumerable_Value() { var sum = 0; - await foreach (var item in AsyncEnumerable.Skip(asyncEnumerableValue, Skip).Take(Count)) + await foreach (var item in asyncEnumerableValue.Skip(Skip).Take(Count)) sum += item; return sum; } @@ -66,7 +66,7 @@ public async Task Linq_AsyncEnumerable_Value() public int Linq_Enumerable_Reference() { var sum = 0; - foreach (var item in Enumerable.Skip(enumerableReference, Skip).Take(Count)) + foreach (var item in enumerableReference.Skip(Skip).Take(Count)) sum += item; return sum; } @@ -76,7 +76,7 @@ public int Linq_Enumerable_Reference() public int Linq_Collection_Reference() { var sum = 0; - foreach (var item in Enumerable.Skip(collectionReference, Skip).Take(Count)) + foreach (var item in collectionReference.Skip(Skip).Take(Count)) sum += item; return sum; } @@ -86,17 +86,17 @@ public int Linq_Collection_Reference() public int Linq_List_Reference() { var sum = 0; - foreach (var item in Enumerable.Skip(listReference, Skip).Take(Count)) + foreach (var item in listReference.Skip(Skip).Take(Count)) sum += item; return sum; } [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] - public async Task Linq_AsyncEnumerable_Reference() + public async ValueTask Linq_AsyncEnumerable_Reference() { var sum = 0; - await foreach (var item in AsyncEnumerable.Skip(asyncEnumerableReference, Skip).Take(Count)) + await foreach (var item in asyncEnumerableReference.Skip(Skip).Take(Count)) sum += item; return sum; } @@ -260,7 +260,7 @@ public int Hyperlinq_Memory_Foreach() public int Hyperlinq_Enumerable_Value() { var sum = 0; - foreach (var item in EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + foreach (var item in enumerableValue.AsValueEnumerable() .Skip(Skip) .Take(Count)) sum += item; @@ -272,7 +272,7 @@ public int Hyperlinq_Enumerable_Value() public int Hyperlinq_Collection_Value() { var sum = 0; - foreach (var item in ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + foreach (var item in collectionValue.AsValueEnumerable() .Skip(Skip) .Take(Count)) sum += item; @@ -305,10 +305,10 @@ public int Hyperlinq_List_Value_Foreach() [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark] - public async Task Hyperlinq_AsyncEnumerable_Value() + public async ValueTask Hyperlinq_AsyncEnumerable_Value() { var sum = 0; - await foreach (var item in asyncEnumerableValue.AsAsyncValueEnumerable((enumerable, cancellationToken) => enumerable.GetAsyncEnumerator(cancellationToken)) + await foreach (var item in asyncEnumerableValue.AsAsyncValueEnumerable() .Skip(Skip) .Take(Count)) sum += item; @@ -360,7 +360,7 @@ public int Hyperlinq_List_Reference_Foreach() [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark] - public async Task Hyperlinq_AsyncEnumerable_Reference() + public async ValueTask Hyperlinq_AsyncEnumerable_Reference() { var sum = 0; await foreach (var item in asyncEnumerableReference.AsAsyncValueEnumerable() diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs index 4869e3987..58e1a9059 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs @@ -17,45 +17,45 @@ public class SumBenchmarks : RandomBenchmarksBase public int Linq_Array() => Enumerable.Sum(array); - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark(Baseline = true)] - //public int Linq_Enumerable_Value() - // => Enumerable.Sum(enumerableValue); - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark(Baseline = true)] - //public int Linq_Collection_Value() - // => Enumerable.Sum(collectionValue); - - //[BenchmarkCategory("List_Value")] - //[Benchmark(Baseline = true)] - //public int Linq_List_Value() - // => Enumerable.Sum(listValue); - - //[BenchmarkCategory("AsyncEnumerable_Value")] - //[Benchmark(Baseline = true)] - //public ValueTask Linq_AsyncEnumerable_Value() - // => AsyncEnumerable.SumAsync(asyncEnumerableValue); - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark(Baseline = true)] - //public int Linq_Enumerable_Reference() - // => Enumerable.Sum(enumerableReference); - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark(Baseline = true)] - //public int Linq_Collection_Reference() - // => Enumerable.Sum(collectionReference); - - //[BenchmarkCategory("List_Reference")] - //[Benchmark(Baseline = true)] - //public int Linq_List_Reference() - // => Enumerable.Sum(listReference); - - //[BenchmarkCategory("AsyncEnumerable_Reference")] - //[Benchmark(Baseline = true)] - //public ValueTask Linq_AsyncEnumerable_Reference() - // => AsyncEnumerable.SumAsync(asyncEnumerableReference); + [BenchmarkCategory("Enumerable_Value")] + [Benchmark(Baseline = true)] + public int Linq_Enumerable_Value() + => Enumerable.Sum(enumerableValue); + + [BenchmarkCategory("Collection_Value")] + [Benchmark(Baseline = true)] + public int Linq_Collection_Value() + => Enumerable.Sum(collectionValue); + + [BenchmarkCategory("List_Value")] + [Benchmark(Baseline = true)] + public int Linq_List_Value() + => Enumerable.Sum(listValue); + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Value() + => AsyncEnumerable.SumAsync(asyncEnumerableValue); + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark(Baseline = true)] + public int Linq_Enumerable_Reference() + => Enumerable.Sum(enumerableReference); + + [BenchmarkCategory("Collection_Reference")] + [Benchmark(Baseline = true)] + public int Linq_Collection_Reference() + => Enumerable.Sum(collectionReference); + + [BenchmarkCategory("List_Reference")] + [Benchmark(Baseline = true)] + public int Linq_List_Reference() + => Enumerable.Sum(listReference); + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Reference() + => AsyncEnumerable.SumAsync(asyncEnumerableReference); // --------------------------------------------------------------------- @@ -66,47 +66,47 @@ public int StructLinq_Array() .ToStructEnumerable() .Sum(x => x); - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark] - //public int StructLinq_Enumerable_Value() - // => enumerableValue - // .ToStructEnumerable() - // .Sum(x => x); - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark] - //public int StructLinq_Collection_Value() - // => collectionValue - // .ToStructEnumerable() - // .Sum(x => x); - - //[BenchmarkCategory("List_Value")] - //[Benchmark] - //public int StructLinq_List_Value() - // => listValue - // .ToStructEnumerable() - // .Sum(x => x); - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark] - //public int StructLinq_Enumerable_Reference() - // => enumerableReference - // .ToStructEnumerable() - // .Sum(x => x); - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark] - //public int StructLinq_Collection_Reference() - // => collectionReference - // .ToStructEnumerable() - // .Sum(x => x); - - //[BenchmarkCategory("List_Reference")] - //[Benchmark] - //public int StructLinq_List_Reference() - // => listReference - // .ToStructEnumerable() - // .Sum(x => x); + [BenchmarkCategory("Enumerable_Value")] + [Benchmark] + public int StructLinq_Enumerable_Value() + => enumerableValue + .ToStructEnumerable() + .Sum(x => x); + + [BenchmarkCategory("Collection_Value")] + [Benchmark] + public int StructLinq_Collection_Value() + => collectionValue + .ToStructEnumerable() + .Sum(x => x); + + [BenchmarkCategory("List_Value")] + [Benchmark] + public int StructLinq_List_Value() + => listValue + .ToStructEnumerable() + .Sum(x => x); + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark] + public int StructLinq_Enumerable_Reference() + => enumerableReference + .ToStructEnumerable() + .Sum(x => x); + + [BenchmarkCategory("Collection_Reference")] + [Benchmark] + public int StructLinq_Collection_Reference() + => collectionReference + .ToStructEnumerable() + .Sum(x => x); + + [BenchmarkCategory("List_Reference")] + [Benchmark] + public int StructLinq_List_Reference() + => listReference + .ToStructEnumerable() + .Sum(x => x); // --------------------------------------------------------------------- @@ -123,68 +123,58 @@ public int LinqFasterSIMD_Array() public int Hyperlinq_Array() => array.AsValueEnumerable().Sum(); - [BenchmarkCategory("Array")] + [BenchmarkCategory("Enumerable_Value")] + [Benchmark] + public int Hyperlinq_Enumerable_Value() + => enumerableValue.AsValueEnumerable() + .Sum(); + + [BenchmarkCategory("Collection_Value")] + [Benchmark] + public int Hyperlinq_Collection_Value() + => collectionValue.AsValueEnumerable() + .Sum(); + + [BenchmarkCategory("List_Value")] + [Benchmark] + public int Hyperlinq_List_Value() + => listValue + .AsValueEnumerable() + .Sum(); + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public ValueTask Hyperlinq_AsyncEnumerable_Value() + => asyncEnumerableValue + .AsAsyncValueEnumerable() + .SumAsync(); + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark] + public int Hyperlinq_Enumerable_Reference() + => enumerableReference + .AsValueEnumerable() + .Sum(); + + [BenchmarkCategory("Collection_Reference")] + [Benchmark] + public int Hyperlinq_Collection_Reference() + => collectionReference + .AsValueEnumerable() + .Sum(); + + [BenchmarkCategory("List_Reference")] + [Benchmark] + public int Hyperlinq_List_Reference() + => listReference + .AsValueEnumerable() + .Sum(); + + [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark] - public int Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable().Sum(); - - //[BenchmarkCategory("Array")] - //[Benchmark] - //public int Hyperlinq_Memory() - // => memory.Sum(); - - //[BenchmarkCategory("Enumerable_Value")] - //[Benchmark] - //public int Hyperlinq_Enumerable_Value() - // => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) - // .Sum(); - - //[BenchmarkCategory("Collection_Value")] - //[Benchmark] - //public int Hyperlinq_Collection_Value() - // => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) - // .Sum(); - - //[BenchmarkCategory("List_Value")] - //[Benchmark] - //public int Hyperlinq_List_Value() - // => listValue - // .AsValueEnumerable() - // .Sum(); - - //[BenchmarkCategory("AsyncEnumerable_Value")] - //[Benchmark] - //public ValueTask Hyperlinq_AsyncEnumerable_Value() - // => asyncEnumerableValue - // .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - // .SumAsync(); - - //[BenchmarkCategory("Enumerable_Reference")] - //[Benchmark] - //public int Hyperlinq_Enumerable_Reference() - // => enumerableReference - // .AsValueEnumerable() - // .Sum(); - - //[BenchmarkCategory("Collection_Reference")] - //[Benchmark] - //public int Hyperlinq_Collection_Reference() - // => collectionReference - // .AsValueEnumerable() - // .Sum(); - - //[BenchmarkCategory("List_Reference")] - //[Benchmark] - //public int Hyperlinq_List_Reference() - // => listReference - // .AsValueEnumerable() - // .Sum(); - - //[BenchmarkCategory("AsyncEnumerable_Reference")] - //[Benchmark] - //public ValueTask Hyperlinq_AsyncEnumerable_Reference() - // => asyncEnumerableReference - // .AsAsyncValueEnumerable() - // .SumAsync(); + public ValueTask Hyperlinq_AsyncEnumerable_Reference() + => asyncEnumerableReference + .AsAsyncValueEnumerable() + .SumAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs index 2e89202a1..f2b1f32f1 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs @@ -14,37 +14,37 @@ public class ToArrayBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int[] Linq_Array() - => Enumerable.ToArray(array); + => array.ToArray(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int[] Linq_Enumerable_Value() - => Enumerable.ToArray(enumerableValue); + => enumerableValue.ToArray(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int[] Linq_Collection_Value() - => Enumerable.ToArray(collectionValue); + => collectionValue.ToArray(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int[] Linq_List_Value() - => Enumerable.ToArray(listValue); + => listValue.ToArray(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int[] Linq_Enumerable_Reference() - => Enumerable.ToArray(enumerableReference); + => enumerableReference.ToArray(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int[] Linq_Collection_Reference() - => Enumerable.ToArray(collectionReference); + => collectionReference.ToArray(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int[] Linq_List_Reference() - => Enumerable.ToArray(listReference); + => listReference.ToArray(); // --------------------------------------------------------------------- @@ -102,31 +102,19 @@ public int[] StructLinq_List_Reference() [BenchmarkCategory("Array")] [Benchmark] public int[] Hyperlinq_Array() - => array - .ToArray(); - - [BenchmarkCategory("Array")] - [Benchmark] - public int[] Hyperlinq_Span() - => array.AsSpan() - .ToArray(); - - [BenchmarkCategory("Array")] - [Benchmark] - public int[] Hyperlinq_Memory() - => memory + => array.AsValueEnumerable() .ToArray(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public int[] Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .ToArray(); [BenchmarkCategory("Collection_Value")] [Benchmark] public int[] Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .ToArray(); [BenchmarkCategory("List_Value")] @@ -140,7 +128,7 @@ public int[] Hyperlinq_List_Value() [Benchmark] public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) + .AsAsyncValueEnumerable() .ToArrayAsync(); [BenchmarkCategory("Enumerable_Reference")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs index 15c53fed8..24c98d6b8 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs @@ -15,37 +15,47 @@ public class ToListBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public List Linq_Array() - => Enumerable.ToList(array); + => array.ToList(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public List Linq_Enumerable_Value() - => Enumerable.ToList(enumerableValue); + => enumerableValue.ToList(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public List Linq_Collection_Value() - => Enumerable.ToList(collectionValue); + => collectionValue.ToList(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public List Linq_List_Value() - => Enumerable.ToList(listValue); + => listValue.ToList(); + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public ValueTask> Linq_AsyncEnumerable_Value() + => asyncEnumerableValue.ToListAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public List Linq_Enumerable_Reference() - => Enumerable.ToList(enumerableReference); + => enumerableReference.ToList(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public List Linq_Collection_Reference() - => Enumerable.ToList(collectionReference); + => collectionReference.ToList(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public List Linq_List_Reference() - => Enumerable.ToList(listReference); + => listReference.ToList(); + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public ValueTask> Linq_AsyncEnumerable_Reference() + => asyncEnumerableReference.ToListAsync(); // --------------------------------------------------------------------- @@ -103,31 +113,19 @@ public List StructLinq_List_Reference() [BenchmarkCategory("Array")] [Benchmark] public List Hyperlinq_Array() - => array - .ToList(); - - [BenchmarkCategory("Array")] - [Benchmark] - public List Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable() - .ToList(); - - [BenchmarkCategory("Array")] - [Benchmark] - public List Hyperlinq_Memory() - => memory.AsValueEnumerable() + => array.AsValueEnumerable() .ToList(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public List Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .ToList(); [BenchmarkCategory("Collection_Value")] [Benchmark] public List Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .ToList(); [BenchmarkCategory("List_Value")] @@ -141,7 +139,7 @@ public List Hyperlinq_List_Value() [Benchmark] public ValueTask> Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) + .AsAsyncValueEnumerable() .ToListAsync(); [BenchmarkCategory("Enumerable_Reference")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs index 14a4becd7..6d6f34c61 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs @@ -3,6 +3,7 @@ using StructLinq; using System; using System.Linq; +using System.Threading.Tasks; namespace NetFabric.Hyperlinq.Benchmarks { @@ -15,7 +16,7 @@ public class WhereBenchmarks : RandomBenchmarksBase public int Linq_Array() { var sum = 0; - foreach (var item in Enumerable.Where(array, item => (item & 0x01) == 0)) + foreach (var item in array.Where(item => (item & 0x01) == 0)) sum += item; return sum; } @@ -25,7 +26,7 @@ public int Linq_Array() public int Linq_Enumerable_Value() { var sum = 0; - foreach (var item in Enumerable.Where(enumerableValue, item => (item & 0x01) == 0)) + foreach (var item in enumerableValue.Where(item => (item & 0x01) == 0)) sum += item; return sum; } @@ -35,7 +36,7 @@ public int Linq_Enumerable_Value() public int Linq_Collection_Value() { var sum = 0; - foreach (var item in Enumerable.Where(collectionValue, item => (item & 0x01) == 0)) + foreach (var item in collectionValue.Where(item => (item & 0x01) == 0)) sum += item; return sum; } @@ -45,7 +46,17 @@ public int Linq_Collection_Value() public int Linq_List_Value() { var sum = 0; - foreach (var item in Enumerable.Where(listValue, item => (item & 0x01) == 0)) + foreach (var item in listValue.Where(item => (item & 0x01) == 0)) + sum += item; + return sum; + } + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public async ValueTask Linq_AsyncEnumerable_Value() + { + var sum = 0; + await foreach (var item in asyncEnumerableValue.Where(item => (item & 0x01) == 0)) sum += item; return sum; } @@ -55,7 +66,7 @@ public int Linq_List_Value() public int Linq_Enumerable_Reference() { var sum = 0; - foreach (var item in Enumerable.Where(enumerableReference, item => (item & 0x01) == 0)) + foreach (var item in enumerableReference.Where(item => (item & 0x01) == 0)) sum += item; return sum; } @@ -65,7 +76,7 @@ public int Linq_Enumerable_Reference() public int Linq_Collection_Reference() { var sum = 0; - foreach (var item in Enumerable.Where(collectionReference, item => (item & 0x01) == 0)) + foreach (var item in collectionReference.Where(item => (item & 0x01) == 0)) sum += item; return sum; } @@ -75,7 +86,17 @@ public int Linq_Collection_Reference() public int Linq_List_Reference() { var sum = 0; - foreach (var item in Enumerable.Where(listReference, item => (item & 0x01) == 0)) + foreach (var item in listReference.Where(item => (item & 0x01) == 0)) + sum += item; + return sum; + } + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public async ValueTask Linq_AsyncEnumerable_Reference() + { + var sum = 0; + await foreach (var item in asyncEnumerableReference.Where(item => (item & 0x01) == 0)) sum += item; return sum; } @@ -159,7 +180,7 @@ public int StructLinq_List_Reference() public int Hyperlinq_Array() { var sum = 0; - foreach (var item in array.Where(item => (item & 0x01) == 0)) + foreach (var item in array.AsValueEnumerable().Where(item => (item & 0x01) == 0)) sum += item; return sum; } @@ -189,7 +210,7 @@ public int Hyperlinq_Memory() public int Hyperlinq_Enumerable_Value() { var sum = 0; - foreach (var item in EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + foreach (var item in enumerableValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0)) sum += item; return sum; @@ -200,7 +221,7 @@ public int Hyperlinq_Enumerable_Value() public int Hyperlinq_Collection_Value() { var sum = 0; - foreach (var item in ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + foreach (var item in collectionValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0)) sum += item; return sum; @@ -216,6 +237,16 @@ public int Hyperlinq_List_Value() return sum; } + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public async ValueTask Hyperlinq_AsyncEnumerable_Value() + { + var sum = 0; + await foreach (var item in asyncEnumerableValue.AsAsyncValueEnumerable().Where((item, _) => new ValueTask((item & 0x01) == 0))) + sum += item; + return sum; + } + [BenchmarkCategory("Enumerable_Reference")] [Benchmark] public int Hyperlinq_Enumerable_Reference() @@ -245,5 +276,15 @@ public int Hyperlinq_List_Reference() sum += item; return sum; } + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public async ValueTask Hyperlinq_AsyncEnumerable_Reference() + { + var sum = 0; + await foreach (var item in asyncEnumerableReference.AsAsyncValueEnumerable().Where((item, _) => new ValueTask((item & 0x01) == 0))) + sum += item; + return sum; + } } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs index b0d949950..51cfb5fd4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs @@ -14,47 +14,47 @@ public class WhereCountBenchmarks : RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() - => Enumerable.Count(array, item => (item & 0x01) == 0); + => array.Count(item => (item & 0x01) == 0); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Value() - => Enumerable.Count(enumerableValue, item => (item & 0x01) == 0); + => enumerableValue.Count(item => (item & 0x01) == 0); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int Linq_Collection_Value() - => Enumerable.Count(collectionValue, item => (item & 0x01) == 0); + => collectionValue.Count(item => (item & 0x01) == 0); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int Linq_List_Value() - => Enumerable.Count(listValue, item => (item & 0x01) == 0); + => listValue.Count(item => (item & 0x01) == 0); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.CountAsync(asyncEnumerableValue, item => (item & 0x01) == 0); + => asyncEnumerableValue.CountAsync(item => (item & 0x01) == 0); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Reference() - => Enumerable.Count(enumerableReference, item => (item & 0x01) == 0); + => enumerableReference.Count(item => (item & 0x01) == 0); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int Linq_Collection_Reference() - => Enumerable.Count(collectionReference, item => (item & 0x01) == 0); + => collectionReference.Count(item => (item & 0x01) == 0); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int Linq_List_Reference() - => Enumerable.Count(listReference, item => (item & 0x01) == 0); + => listReference.Count(item => (item & 0x01) == 0); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.CountAsync(asyncEnumerableReference, item => (item & 0x01) == 0); + => asyncEnumerableReference.CountAsync(item => (item & 0x01) == 0); // --------------------------------------------------------------------- @@ -119,7 +119,7 @@ public int StructLinq_List_Reference() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Array() - => array + => array.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .Count(); @@ -140,14 +140,14 @@ public int Hyperlinq_Memory() [BenchmarkCategory("Enumerable_Value")] [Benchmark] public int Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .Count(); [BenchmarkCategory("Collection_Value")] [Benchmark] public int Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .Count(); @@ -163,8 +163,8 @@ public int Hyperlinq_List_Value() [Benchmark] public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - .Where(item => (item & 0x01) == 0) + .AsAsyncValueEnumerable() + .Where((item, _) => new ValueTask((item & 0x01) == 0)) .CountAsync(); [BenchmarkCategory("Enumerable_Reference")] @@ -196,7 +196,7 @@ public int Hyperlinq_List_Reference() public ValueTask Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() - .Where(item => (item & 0x01) == 0) + .Where((item, _) => new ValueTask((item & 0x01) == 0)) .CountAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs index 73196c7ea..5781c72a4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs @@ -14,47 +14,47 @@ public class WhereFirstBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() - => Enumerable.First(array, item => item == Count - 1); + => array.First(item => item == Count - 1); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Value() - => Enumerable.First(enumerableValue, item => item == Count - 1); + => enumerableValue.First(item => item == Count - 1); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int Linq_Collection_Value() - => Enumerable.First(collectionValue, item => item == Count - 1); + => collectionValue.First(item => item == Count - 1); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int Linq_List_Value() - => Enumerable.First(listValue, item => item == Count - 1); + => listValue.First(item => item == Count - 1); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.FirstAsync(asyncEnumerableValue, item => item == Count - 1); + => asyncEnumerableValue.FirstAsync(item => item == Count - 1); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Reference() - => Enumerable.First(enumerableReference, item => item == Count - 1); + => enumerableReference.First(item => item == Count - 1); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int Linq_Collection_Reference() - => Enumerable.First(collectionReference, item => item == Count - 1); + => collectionReference.First(item => item == Count - 1); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int Linq_List_Reference() - => Enumerable.First(listReference, item => item == Count - 1); + => listReference.First(item => item == Count - 1); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.FirstAsync(asyncEnumerableReference, item => item == Count - 1); + => asyncEnumerableReference.FirstAsync(item => item == Count - 1); // --------------------------------------------------------------------- @@ -65,31 +65,17 @@ public Option Hyperlinq_Array() .Where(item => item == Count - 1) .First(); - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable() - .Where(item => item == Count - 1) - .First(); - - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Memory() - => memory.AsValueEnumerable() - .Where(item => item == Count - 1) - .First(); - [BenchmarkCategory("Enumerable_Value")] [Benchmark] public Option Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Where(item => item == Count - 1) .First(); [BenchmarkCategory("Collection_Value")] [Benchmark] public Option Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Where(item => item == Count - 1) .First(); @@ -103,10 +89,10 @@ public Option Hyperlinq_List_Value() [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark] - public ValueTask Hyperlinq_AsyncEnumerable_Value() + public ValueTask> Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - .Where(item => item == Count - 1) + .AsAsyncValueEnumerable() + .Where((item, _) => new ValueTask(item == Count - 1)) .FirstAsync(); [BenchmarkCategory("Enumerable_Reference")] @@ -135,10 +121,10 @@ public Option Hyperlinq_List_Reference() [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark] - public ValueTask Hyperlinq_AsyncEnumerable_Reference() + public ValueTask> Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() - .Where(item => item == Count - 1) + .Where((item, _) => new ValueTask(item == Count - 1)) .FirstAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs index 9be5c7fa5..161c85fa9 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs @@ -3,6 +3,7 @@ using StructLinq; using System; using System.Linq; +using System.Threading.Tasks; namespace NetFabric.Hyperlinq.Benchmarks { @@ -15,7 +16,9 @@ public class WhereSelectBenchmarks: RandomBenchmarksBase public int Linq_Array() { var sum = 0; - foreach (var item in Enumerable.Where(array, item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in array + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -25,7 +28,9 @@ public int Linq_Array() public int Linq_Enumerable_Value() { var sum = 0; - foreach (var item in Enumerable.Where(enumerableValue, item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in enumerableValue + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -35,7 +40,9 @@ public int Linq_Enumerable_Value() public int Linq_Collection_Value() { var sum = 0; - foreach (var item in Enumerable.Where(collectionValue, item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in collectionValue + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -45,7 +52,21 @@ public int Linq_Collection_Value() public int Linq_List_Value() { var sum = 0; - foreach (var item in Enumerable.Where(listValue, item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in listValue + .Where(item => (item & 0x01) == 0) + .Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public async ValueTask Linq_AsyncEnumerable_Value() + { + var sum = 0; + await foreach (var item in asyncEnumerableValue + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -55,7 +76,9 @@ public int Linq_List_Value() public int Linq_Enumerable_Reference() { var sum = 0; - foreach (var item in Enumerable.Where(enumerableReference, item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in enumerableReference + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -65,7 +88,9 @@ public int Linq_Enumerable_Reference() public int Linq_Collection_Reference() { var sum = 0; - foreach (var item in Enumerable.Where(collectionReference, item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in collectionReference + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -75,7 +100,21 @@ public int Linq_Collection_Reference() public int Linq_List_Reference() { var sum = 0; - foreach (var item in Enumerable.Where(listReference, item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in listReference + .Where(item => (item & 0x01) == 0) + .Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public async ValueTask Linq_AsyncEnumerable_Reference() + { + var sum = 0; + await foreach (var item in asyncEnumerableReference + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -87,7 +126,9 @@ public int Linq_List_Reference() public int StructLinq_Array() { var sum = 0; - foreach (var item in array.ToStructEnumerable().Where(item => (item & 0x01) == 0, x => x).Select(item => item, x => x)) + foreach (var item in array.ToStructEnumerable() + .Where(item => (item & 0x01) == 0, x => x) + .Select(item => item, x => x)) sum += item; return sum; } @@ -97,7 +138,9 @@ public int StructLinq_Array() public int StructLinq_Enumerable_Value() { var sum = 0; - foreach (var item in enumerableValue.ToStructEnumerable().Where(item => (item & 0x01) == 0, x => x).Select(item => item, x => x)) + foreach (var item in enumerableValue.ToStructEnumerable() + .Where(item => (item & 0x01) == 0, x => x) + .Select(item => item, x => x)) sum += item; return sum; } @@ -107,7 +150,9 @@ public int StructLinq_Enumerable_Value() public int StructLinq_Collection_Value() { var sum = 0; - foreach (var item in collectionValue.ToStructEnumerable().Where(item => (item & 0x01) == 0, x => x).Select(item => item, x => x)) + foreach (var item in collectionValue.ToStructEnumerable() + .Where(item => (item & 0x01) == 0, x => x) + .Select(item => item, x => x)) sum += item; return sum; } @@ -117,7 +162,9 @@ public int StructLinq_Collection_Value() public int StructLinq_List_Value() { var sum = 0; - foreach (var item in listValue.ToStructEnumerable().Where(item => (item & 0x01) == 0, x => x).Select(item => item, x => x)) + foreach (var item in listValue.ToStructEnumerable() + .Where(item => (item & 0x01) == 0, x => x) + .Select(item => item, x => x)) sum += item; return sum; } @@ -127,7 +174,9 @@ public int StructLinq_List_Value() public int StructLinq_Enumerable_Reference() { var sum = 0; - foreach (var item in enumerableReference.ToStructEnumerable().Where(item => (item & 0x01) == 0, x => x).Select(item => item, x => x)) + foreach (var item in enumerableReference.ToStructEnumerable() + .Where(item => (item & 0x01) == 0, x => x) + .Select(item => item, x => x)) sum += item; return sum; } @@ -137,7 +186,9 @@ public int StructLinq_Enumerable_Reference() public int StructLinq_Collection_Reference() { var sum = 0; - foreach (var item in collectionReference.ToStructEnumerable().Where(item => (item & 0x01) == 0, x => x).Select(item => item, x => x)) + foreach (var item in collectionReference.ToStructEnumerable() + .Where(item => (item & 0x01) == 0, x => x) + .Select(item => item, x => x)) sum += item; return sum; } @@ -147,7 +198,9 @@ public int StructLinq_Collection_Reference() public int StructLinq_List_Reference() { var sum = 0; - foreach (var item in listReference.ToStructEnumerable().Where(item => (item & 0x01) == 0, x => x).Select(item => item, x => x)) + foreach (var item in listReference.ToStructEnumerable() + .Where(item => (item & 0x01) == 0, x => x) + .Select(item => item, x => x)) sum += item; return sum; } @@ -159,7 +212,9 @@ public int StructLinq_List_Reference() public int Hyperlinq_Array() { var sum = 0; - foreach (var item in array.Where(item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in array.AsValueEnumerable() + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -169,7 +224,9 @@ public int Hyperlinq_Array() public int Hyperlinq_Span() { var sum = 0; - foreach (var item in array.AsSpan().AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in array.AsSpan().AsValueEnumerable() + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -179,7 +236,9 @@ public int Hyperlinq_Span() public int Hyperlinq_Memory() { var sum = 0; - foreach (var item in memory.AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in memory.AsValueEnumerable() + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -189,7 +248,7 @@ public int Hyperlinq_Memory() public int Hyperlinq_Enumerable_Value() { var sum = 0; - foreach (var item in EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + foreach (var item in enumerableValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .Select(item => item)) sum += item; @@ -201,7 +260,7 @@ public int Hyperlinq_Enumerable_Value() public int Hyperlinq_Collection_Value() { var sum = 0; - foreach (var item in ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + foreach (var item in collectionValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .Select(item => item)) sum += item; @@ -213,7 +272,21 @@ public int Hyperlinq_Collection_Value() public int Hyperlinq_List_Value() { var sum = 0; - foreach (var item in listValue.AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in listValue.AsValueEnumerable() + .Where(item => (item & 0x01) == 0) + .Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public async ValueTask Hyperlinq_AsyncEnumerable_Value() + { + var sum = 0; + await foreach (var item in asyncEnumerableValue.AsAsyncValueEnumerable() + .Where((item, _) => new ValueTask((item & 0x01) == 0)) + .Select((item, _) => new ValueTask(item))) sum += item; return sum; } @@ -223,7 +296,9 @@ public int Hyperlinq_List_Value() public int Hyperlinq_Enumerable_Reference() { var sum = 0; - foreach (var item in enumerableReference.AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in enumerableReference.AsValueEnumerable() + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -233,7 +308,9 @@ public int Hyperlinq_Enumerable_Reference() public int Hyperlinq_Collection_Reference() { var sum = 0; - foreach (var item in collectionReference.AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in collectionReference.AsValueEnumerable() + .Where(item => (item & 0x01) == 0) + .Select(item => item)) sum += item; return sum; } @@ -243,7 +320,21 @@ public int Hyperlinq_Collection_Reference() public int Hyperlinq_List_Reference() { var sum = 0; - foreach (var item in listReference.AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item)) + foreach (var item in listReference.AsValueEnumerable() + .Where(item => (item & 0x01) == 0) + .Select(item => item)) + sum += item; + return sum; + } + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public async ValueTask Hyperlinq_AsyncEnumerable_Reference() + { + var sum = 0; + await foreach (var item in asyncEnumerableReference.AsAsyncValueEnumerable() + .Where((item, _) => new ValueTask((item & 0x01) == 0)) + .Select((item, _) => new ValueTask(item))) sum += item; return sum; } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs index 26b3d2736..c7b67d07e 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs @@ -1,6 +1,8 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using System; +using System.Linq; +using System.Threading.Tasks; namespace NetFabric.Hyperlinq.Benchmarks { @@ -11,74 +13,62 @@ public class WhereSelectCountBenchmarks : RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() - => System.Linq.Enumerable.Count( - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(array, item => (item & 0x01) == 0), item => item)); + => array.Where(item => (item & 0x01) == 0).Select(item => item).Count(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Value() - => System.Linq.Enumerable.Count( - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(enumerableValue, item => (item & 0x01) == 0), item => item)); + => enumerableValue.Where(item => (item & 0x01) == 0).Select(item => item).Count(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int Linq_Collection_Value() - => System.Linq.Enumerable.Count( - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(collectionValue, item => (item & 0x01) == 0), item => item)); + => collectionValue.Where(item => (item & 0x01) == 0).Select(item => item).Count(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int Linq_List_Value() - => System.Linq.Enumerable.Count( - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(listValue, item => (item & 0x01) == 0), item => item)); + => listValue.Where(item => (item & 0x01) == 0).Select(item => item).Count(); + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Value() + => asyncEnumerableValue.Where(item => (item & 0x01) == 0).Select(item => item).CountAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Reference() - => System.Linq.Enumerable.Count( - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(enumerableReference, item => (item & 0x01) == 0), item => item)); + => enumerableReference.Where(item => (item & 0x01) == 0).Select(item => item).Count(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int Linq_Collection_Reference() - => System.Linq.Enumerable.Count( - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(collectionReference, item => (item & 0x01) == 0), item => item)); + => collectionReference.Where(item => (item & 0x01) == 0).Select(item => item).Count(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int Linq_List_Reference() - => System.Linq.Enumerable.Count( - System.Linq.Enumerable.Select( - System.Linq.Enumerable.Where(listReference, item => (item & 0x01) == 0), item => item)); + => listReference.Where(item => (item & 0x01) == 0).Select(item => item).Count(); - [BenchmarkCategory("Array")] - [Benchmark] - public int Hyperlinq_Array() - => array.AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item).Count(); + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Reference() + => asyncEnumerableReference.Where(item => (item & 0x01) == 0).Select(item => item).CountAsync(); - [BenchmarkCategory("Array")] - [Benchmark] - public int Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item).Count(); + // --------------------------------------------------------------------- [BenchmarkCategory("Array")] [Benchmark] - public int Hyperlinq_Memory() - => memory.AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item).Count(); + public int Hyperlinq_Array() + => array.AsValueEnumerable().Where(item => (item & 0x01) == 0).Select(item => item).Count(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public int Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .Select(item => item) .Count(); @@ -86,7 +76,7 @@ public int Hyperlinq_Enumerable_Value() [BenchmarkCategory("Collection_Value")] [Benchmark] public int Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .Select(item => item) .Count(); @@ -101,6 +91,15 @@ public int Hyperlinq_List_Value() .Select(item => item) .Count(); + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public ValueTask Hyperlinq_AsyncEnumerable_Value() + => asyncEnumerableValue + .AsAsyncValueEnumerable() + .Where((item, _) => new ValueTask((item & 0x01) == 0)) + .Select((item, _) => new ValueTask(item)) + .CountAsync(); + [BenchmarkCategory("Enumerable_Reference")] [Benchmark] public int Hyperlinq_Enumerable_Reference() @@ -127,5 +126,14 @@ public int Hyperlinq_List_Reference() .Where(item => (item & 0x01) == 0) .Select(item => item) .Count(); + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public ValueTask Hyperlinq_AsyncEnumerable_Reference() + => asyncEnumerableReference + .AsAsyncValueEnumerable() + .Where((item, _) => new ValueTask((item & 0x01) == 0)) + .Select((item, _) => new ValueTask(item)) + .CountAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs index ab8e704c2..5dc9ea654 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs @@ -14,47 +14,47 @@ public class WhereSingleBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int Linq_Array() - => Enumerable.Single(array, item => item == Count - 1); + => array.Single(item => item == Count - 1); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Value() - => Enumerable.Single(enumerableValue, item => item == Count - 1); + => enumerableValue.Single(item => item == Count - 1); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int Linq_Collection_Value() - => Enumerable.Single(collectionValue, item => item == Count - 1); + => collectionValue.Single(item => item == Count - 1); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int Linq_List_Value() - => Enumerable.Single(listValue, item => item == Count - 1); + => listValue.Single(item => item == Count - 1); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.SingleAsync(asyncEnumerableValue, item => item == Count - 1); + => asyncEnumerableValue.SingleAsync(item => item == Count - 1); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int Linq_Enumerable_Reference() - => Enumerable.Single(enumerableReference, item => item == Count - 1); + => enumerableReference.Single(item => item == Count - 1); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int Linq_Collection_Reference() - => Enumerable.Single(collectionReference, item => item == Count - 1); + => collectionReference.Single(item => item == Count - 1); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int Linq_List_Reference() - => Enumerable.Single(listReference, item => item == Count - 1); + => listReference.Single(item => item == Count - 1); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.SingleAsync(asyncEnumerableReference, item => item == Count - 1); + => asyncEnumerableReference.SingleAsync(item => item == Count - 1); // --------------------------------------------------------------------- @@ -65,31 +65,17 @@ public Option Hyperlinq_Array() .Where(item => item == Count - 1) .Single(); - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable() - .Where(item => item == Count - 1) - .Single(); - - [BenchmarkCategory("Array")] - [Benchmark] - public Option Hyperlinq_Memory() - => memory.AsValueEnumerable() - .Where(item => item == Count - 1) - .Single(); - [BenchmarkCategory("Enumerable_Value")] [Benchmark] public Option Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Where(item => item == Count - 1) .Single(); [BenchmarkCategory("Collection_Value")] [Benchmark] public Option Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Where(item => item == Count - 1) .Single(); @@ -103,10 +89,10 @@ public Option Hyperlinq_List_Value() [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark] - public ValueTask Hyperlinq_AsyncEnumerable_Value() + public ValueTask> Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - .Where(item => item == Count - 1) + .AsAsyncValueEnumerable() + .Where((item, _) => new ValueTask(item == Count - 1)) .SingleAsync(); [BenchmarkCategory("Enumerable_Reference")] @@ -135,10 +121,10 @@ public Option Hyperlinq_List_Reference() [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark] - public ValueTask Hyperlinq_AsyncEnumerable_Reference() + public ValueTask> Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() - .Where(item => item == Count - 1) + .Where((item, _) => new ValueTask(item == Count - 1)) .SingleAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs index ef2ba134b..c30a8a399 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs @@ -14,55 +14,55 @@ public class WhereToArrayBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int[] Linq_Array() - => Enumerable.Where(array, item => (item & 0x01) == 0) + => array.Where(item => (item & 0x01) == 0) .ToArray(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public int[] Linq_Enumerable_Value() - => Enumerable.Where(enumerableValue, item => (item & 0x01) == 0) + => enumerableValue.Where(item => (item & 0x01) == 0) .ToArray(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public int[] Linq_Collection_Value() - => Enumerable.Where(collectionValue, item => (item & 0x01) == 0) + => collectionValue.Where(item => (item & 0x01) == 0) .ToArray(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public int[] Linq_List_Value() - => Enumerable.Where(listValue, item => (item & 0x01) == 0) + => listValue.Where(item => (item & 0x01) == 0) .ToArray(); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Value() - => AsyncEnumerable.Where(asyncEnumerableValue, item => (item & 0x01) == 0) + => asyncEnumerableValue.Where(item => (item & 0x01) == 0) .ToArrayAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int[] Linq_Enumerable_Reference() - => Enumerable.Where(enumerableReference, item => (item & 0x01) == 0) + => enumerableReference.Where(item => (item & 0x01) == 0) .ToArray(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public int[] Linq_Collection_Reference() - => Enumerable.Where(collectionReference, item => (item & 0x01) == 0) + => collectionReference.Where(item => (item & 0x01) == 0) .ToArray(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public int[] Linq_List_Reference() - => Enumerable.Where(listReference, item => (item & 0x01) == 0) + => listReference.Where(item => (item & 0x01) == 0) .ToArray(); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.Where(asyncEnumerableReference, item => (item & 0x01) == 0) + => asyncEnumerableReference.Where(item => (item & 0x01) == 0) .ToArrayAsync(); // --------------------------------------------------------------------- @@ -128,35 +128,21 @@ public int[] StructLinq_List_Reference() [BenchmarkCategory("Array")] [Benchmark] public int[] Hyperlinq_Array() - => array - .Where(item => (item & 0x01) == 0) - .ToArray(); - - [BenchmarkCategory("Array")] - [Benchmark] - public int[] Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable() - .Where(item => (item & 0x01) == 0) - .ToArray(); - - [BenchmarkCategory("Array")] - [Benchmark] - public int[] Hyperlinq_Memory() - => memory.AsValueEnumerable() + => array.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .ToArray(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public int[] Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .ToArray(); [BenchmarkCategory("Collection_Value")] [Benchmark] public int[] Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .ToArray(); @@ -172,8 +158,8 @@ public int[] Hyperlinq_List_Value() [Benchmark] public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - .Where(item => (item & 0x01) == 0) + .AsAsyncValueEnumerable() + .Where((item, _) => new ValueTask((item & 0x01) == 0)) .ToArrayAsync(); [BenchmarkCategory("Enumerable_Reference")] @@ -205,7 +191,7 @@ public int[] Hyperlinq_List_Reference() public ValueTask Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() - .Where(item => (item & 0x01) == 0) + .Where((item, _) => new ValueTask((item & 0x01) == 0)) .ToArrayAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs index bea4a1859..5bbc48b9c 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs @@ -15,55 +15,55 @@ public class WhereToListBenchmarks: RandomBenchmarksBase [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public List Linq_Array() - => Enumerable.Where(array, item => (item & 0x01) == 0) + => array.Where(item => (item & 0x01) == 0) .ToList(); [BenchmarkCategory("Enumerable_Value")] [Benchmark(Baseline = true)] public List Linq_Enumerable_Value() - => Enumerable.Where(enumerableValue, item => (item & 0x01) == 0) + => enumerableValue.Where(item => (item & 0x01) == 0) .ToList(); [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public List Linq_Collection_Value() - => Enumerable.Where(collectionValue, item => (item & 0x01) == 0) + => collectionValue.Where(item => (item & 0x01) == 0) .ToList(); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] public List Linq_List_Value() - => Enumerable.Where(listValue, item => (item & 0x01) == 0) + => listValue.Where(item => (item & 0x01) == 0) .ToList(); [BenchmarkCategory("AsyncEnumerable_Value")] [Benchmark(Baseline = true)] public ValueTask> Linq_AsyncEnumerable_Value() - => AsyncEnumerable.Where(asyncEnumerableValue, item => (item & 0x01) == 0) + => asyncEnumerableValue.Where(item => (item & 0x01) == 0) .ToListAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public List Linq_Enumerable_Reference() - => Enumerable.Where(enumerableReference, item => (item & 0x01) == 0) + => enumerableReference.Where(item => (item & 0x01) == 0) .ToList(); [BenchmarkCategory("Collection_Reference")] [Benchmark(Baseline = true)] public List Linq_Collection_Reference() - => Enumerable.Where(collectionReference, item => (item & 0x01) == 0) + => collectionReference.Where(item => (item & 0x01) == 0) .ToList(); [BenchmarkCategory("List_Reference")] [Benchmark(Baseline = true)] public List Linq_List_Reference() - => Enumerable.Where(listReference, item => (item & 0x01) == 0) + => listReference.Where(item => (item & 0x01) == 0) .ToList(); [BenchmarkCategory("AsyncEnumerable_Reference")] [Benchmark(Baseline = true)] public ValueTask> Linq_AsyncEnumerable_Reference() - => AsyncEnumerable.Where(asyncEnumerableReference, item => (item & 0x01) == 0) + => asyncEnumerableReference.Where(item => (item & 0x01) == 0) .ToListAsync(); // --------------------------------------------------------------------- @@ -129,35 +129,21 @@ public List StructLinq_List_Reference() [BenchmarkCategory("Array")] [Benchmark] public List Hyperlinq_Array() - => array - .Where(item => (item & 0x01) == 0) - .ToList(); - - [BenchmarkCategory("Array")] - [Benchmark] - public List Hyperlinq_Span() - => array.AsSpan().AsValueEnumerable() - .Where(item => (item & 0x01) == 0) - .ToList(); - - [BenchmarkCategory("Array")] - [Benchmark] - public List Hyperlinq_Memory() - => memory.AsValueEnumerable() + => array.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .ToList(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public List Hyperlinq_Enumerable_Value() - => EnumerableExtensions.AsValueEnumerable(enumerableValue, enumerable => enumerable.GetEnumerator()) + => enumerableValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .ToList(); [BenchmarkCategory("Collection_Value")] [Benchmark] public List Hyperlinq_Collection_Value() - => ReadOnlyCollectionExtensions.AsValueEnumerable(collectionValue, enumerable => enumerable.GetEnumerator()) + => collectionValue.AsValueEnumerable() .Where(item => (item & 0x01) == 0) .ToList(); @@ -173,8 +159,8 @@ public List Hyperlinq_List_Value() [Benchmark] public ValueTask> Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue - .AsAsyncValueEnumerable((enumerable, cancellationToke) => enumerable.GetAsyncEnumerator(cancellationToke)) - .Where(item => (item & 0x01) == 0) + .AsAsyncValueEnumerable() + .Where((item, _) => new ValueTask((item & 0x01) == 0)) .ToListAsync(); [BenchmarkCategory("Enumerable_Reference")] @@ -206,7 +192,7 @@ public List Hyperlinq_List_Reference() public ValueTask> Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() - .Where(item => (item & 0x01) == 0) + .Where((item, _) => new ValueTask((item & 0x01) == 0)) .ToListAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Program.cs b/NetFabric.Hyperlinq.Benchmarks/Program.cs index b65d028a2..2fdf7ee52 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Program.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Program.cs @@ -75,20 +75,20 @@ static void SaveSummary(Summary summary) } static string GetInformationalVersion(Assembly assembly) - => GetCustomAttribute(assembly)?.InformationalVersion.Split('+')[0]; + => GetCustomAttribute(assembly)?.InformationalVersion.Split('+')[0] ?? ""; - static T GetCustomAttribute(Assembly assembly) where T : Attribute - => (T)Attribute.GetCustomAttribute(assembly, typeof(T), false); + static T? GetCustomAttribute(Assembly assembly) where T : Attribute + => (T?)Attribute.GetCustomAttribute(assembly, typeof(T), false); - static Type GetTargetType(Summary summary) + static Type? GetTargetType(Summary summary) { var targetTypes = summary.BenchmarksCases.Select(i => i.Descriptor.Type).Distinct().ToList(); return targetTypes.Count == 1 ? targetTypes[0] : null; } - static string GetSolutionDirectory() + static string? GetSolutionDirectory() { - var dir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); + var dir = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); while (!string.IsNullOrEmpty(dir)) { diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs index c96789a85..6d5fef241 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -9,9 +10,10 @@ public static class TestAsyncEnumerable { public static Enumerable ValueType(int[] array) - => new Enumerable(array); + => new(array); public static IAsyncEnumerable ReferenceType(int[] array) + // ReSharper disable once HeapView.ObjectAllocation.Evident => new ReferenceEnumerable(array); public class Enumerable : IAsyncEnumerable @@ -22,10 +24,23 @@ public Enumerable(int[] array) => this.array = array; public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) - => new Enumerator(array, cancellationToken); + => new(array, cancellationToken); IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(array, cancellationToken); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AsyncEnumerableExtensions.AsyncValueEnumerable AsAsyncValueEnumerable() + => this.AsAsyncValueEnumerable(); + + public readonly struct GetEnumeratorFunction + : IFunction + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator Invoke(Enumerable source, CancellationToken cancellationToken) + => source.GetAsyncEnumerator(cancellationToken); + } + public struct Enumerator : IAsyncEnumerator { readonly int[] array; @@ -60,6 +75,7 @@ public ReferenceEnumerable(int[] array) => this.array = array; public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken) + // ReSharper disable once HeapView.ObjectAllocation.Evident => new Enumerator(array, cancellationToken); class Enumerator : IAsyncEnumerator diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs index c155c947f..795e95dd2 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs @@ -1,15 +1,17 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq.Benchmarks { public static class TestCollection { public static Enumerable ValueType(int[] array) - => new Enumerable(array); + => new(array); public static IReadOnlyCollection ReferenceType(int[] array) + // ReSharper disable once HeapView.ObjectAllocation.Evident => new EnumerableReferenceType(array); public class Enumerable : IReadOnlyCollection, ICollection @@ -34,12 +36,26 @@ public void CopyTo(int[] array, int arrayIndex) => this.array.CopyTo(array, arrayIndex); public Enumerator GetEnumerator() - => new Enumerator(array); + => new(array); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(array); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(array); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ReadOnlyCollectionExtensions.ValueEnumerable AsValueEnumerable() + => ReadOnlyCollectionExtensions.AsValueEnumerable(this); + + public readonly struct GetEnumeratorFunction + : IFunction + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator Invoke(Enumerable source) + => source.GetEnumerator(); + } + public struct Enumerator : IEnumerator { readonly int[] array; @@ -51,12 +67,17 @@ public Enumerator(int[] array) index = -1; } - public int Current => array[index]; - object IEnumerator.Current => array[index]; + public int Current + => array[index]; + object? IEnumerator.Current + // ReSharper disable once HeapView.BoxingAllocation + => array[index]; - public bool MoveNext() => ++index < array.Length; + public bool MoveNext() + => ++index < array.Length; - public void Reset() => throw new NotSupportedException(); + public void Reset() + => throw new NotSupportedException(); public void Dispose() { } } @@ -75,9 +96,12 @@ public EnumerableReferenceType(int[] array) public bool IsReadOnly => true; - public void Add(int item) => throw new NotSupportedException(); - public bool Remove(int item) => throw new NotSupportedException(); - public void Clear() => throw new NotSupportedException(); + public void Add(int item) + => throw new NotSupportedException(); + public bool Remove(int item) + => throw new NotSupportedException(); + public void Clear() + => throw new NotSupportedException(); public bool Contains(int item) => ((IList)array).Contains(item); @@ -85,8 +109,12 @@ public bool Contains(int item) public void CopyTo(int[] array, int arrayIndex) => this.array.CopyTo(array, arrayIndex); - public IEnumerator GetEnumerator() => new Enumerator(array); - IEnumerator IEnumerable.GetEnumerator() => new Enumerator(array); + public IEnumerator GetEnumerator() + // ReSharper disable once HeapView.ObjectAllocation.Evident + => new Enumerator(array); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.ObjectAllocation.Evident + => new Enumerator(array); class Enumerator : IEnumerator { @@ -95,8 +123,11 @@ class Enumerator : IEnumerator public Enumerator(int[] array) => this.array = array; - public int Current => array[index]; - object IEnumerator.Current => array[index]; + public int Current + => array[index]; + object? IEnumerator.Current + // ReSharper disable once HeapView.BoxingAllocation + => array[index]; public bool MoveNext() => ++index < array.Length; diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestEnumerable.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestEnumerable.cs index dc894aa5a..397b6e324 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestEnumerable.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Utils/TestEnumerable.cs @@ -1,15 +1,17 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq.Benchmarks { public static class TestEnumerable { public static Enumerable ValueType(int[] array) - => new Enumerable(array); + => new(array); public static IEnumerable ReferenceType(int[] array) + // ReSharper disable once HeapView.ObjectAllocation.Evident => new ReferenceEnumerable(array); public class Enumerable : IEnumerable @@ -20,12 +22,26 @@ public Enumerable(int[] array) => this.array = array; public Enumerator GetEnumerator() - => new Enumerator(array); + => new(array); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(array); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(array); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public EnumerableExtensions.ValueEnumerable AsValueEnumerable() + => this.AsValueEnumerable(); + + public readonly struct GetEnumeratorFunction + : IFunction + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator Invoke(Enumerable source) + => source.GetEnumerator(); + } + public struct Enumerator : IEnumerator { readonly int[] array; @@ -37,8 +53,11 @@ public Enumerator(int[] array) index = -1; } - public int Current => array[index]; - object IEnumerator.Current => array[index]; + public int Current + => array[index]; + object? IEnumerator.Current + // ReSharper disable once HeapView.BoxingAllocation + => array[index]; public bool MoveNext() => ++index < array.Length; @@ -56,8 +75,10 @@ public ReferenceEnumerable(int[] array) => this.array = array; public IEnumerator GetEnumerator() + // ReSharper disable once HeapView.ObjectAllocation.Evident => new Enumerator(array); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.ObjectAllocation.Evident => new Enumerator(array); class Enumerator : IEnumerator @@ -67,8 +88,11 @@ class Enumerator : IEnumerator public Enumerator(int[] array) => this.array = array; - public int Current => array[index]; - object IEnumerator.Current => array[index]; + public int Current + => array[index]; + object? IEnumerator.Current + // ReSharper disable once HeapView.BoxingAllocation + => array[index]; public bool MoveNext() => ++index < array.Length; diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs index 5e5f5f3a9..b14acab8d 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs @@ -1,15 +1,17 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq.Benchmarks { public static class TestList { public static Enumerable ValueType(int[] array) - => new Enumerable(array); + => new(array); public static IReadOnlyList ReferenceType(int[] array) + // ReSharper disable once HeapView.ObjectAllocation.Evident => new EnumerableReferenceType(array); public class Enumerable : IReadOnlyList, IList @@ -45,12 +47,18 @@ public void CopyTo(int[] array, int arrayIndex) => this.array.CopyTo(array, arrayIndex); public Enumerator GetEnumerator() - => new Enumerator(array); + => new(array); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(array); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(array); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ReadOnlyListExtensions.ValueEnumerable AsValueEnumerable() + => this.AsValueEnumerable(); + public struct Enumerator : IEnumerator { readonly int[] array; @@ -62,8 +70,11 @@ public Enumerator(int[] array) index = -1; } - public int Current => array[index]; - object IEnumerator.Current => array[index]; + public int Current + => array[index]; + object IEnumerator.Current + // ReSharper disable once HeapView.BoxingAllocation + => array[index]; public bool MoveNext() => ++index < array.Length; @@ -107,8 +118,12 @@ public bool Contains(int item) public void CopyTo(int[] array, int arrayIndex) => this.array.CopyTo(array, arrayIndex); - public IEnumerator GetEnumerator() => new Enumerator(array); - IEnumerator IEnumerable.GetEnumerator() => new Enumerator(array); + public IEnumerator GetEnumerator() + // ReSharper disable once HeapView.ObjectAllocation.Evident + => new Enumerator(array); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.ObjectAllocation.Evident + => new Enumerator(array); class Enumerator : IEnumerator { @@ -117,12 +132,17 @@ class Enumerator : IEnumerator public Enumerator(int[] array) => this.array = array; - public int Current => array[index]; - object IEnumerator.Current => array[index]; + public int Current + => array[index]; + object? IEnumerator.Current + // ReSharper disable once HeapView.BoxingAllocation + => array[index]; - public bool MoveNext() => ++index < array.Length; + public bool MoveNext() + => ++index < array.Length; - public void Reset() => throw new NotSupportedException(); + public void Reset() + => throw new NotSupportedException(); public void Dispose() { } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/Utils.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/Utils.cs index 30f621e72..b63b3d509 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/Utils.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Utils/Utils.cs @@ -1,11 +1,14 @@ using System; +using System.Diagnostics.CodeAnalysis; namespace NetFabric.Hyperlinq.Benchmarks { static class Utils { + [return: NotNull] public static int[] GetSequentialValues(int count) { + // ReSharper disable once HeapView.ObjectAllocation.Evident var array = new int[count]; for (var index = 0; index < count; index++) @@ -14,10 +17,13 @@ public static int[] GetSequentialValues(int count) return array; } + [return: NotNull] public static int[] GetRandomValues(int seed, int count) { + // ReSharper disable once HeapView.ObjectAllocation.Evident var array = new int[count]; + // ReSharper disable once HeapView.ObjectAllocation.Evident var random = new Random(seed); for (var index = 0; index < count; index++) array[index] = random.Next(count); diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs index c47749114..f5ce2250f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs @@ -20,8 +20,8 @@ public void Count_With_ValidData_Must_Succeed(int[] source) .Count(); // Act - var result = ValueReadOnlyCollectionExtensions - .Count, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .Count(); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs index 5cffbe591..e6b8d5828 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs @@ -17,8 +17,8 @@ public void Sum_With_ValidData_Must_Succeed(int[] source) .Sum(); // Act - var result = wrapped - .Sum, Wrap.Enumerator, int, int>(); + var result = wrapped.AsValueEnumerable() + .Sum(); // Assert _ = result.Must() @@ -35,8 +35,8 @@ public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) .Sum(); // Act - var result = wrapped - .Sum, Wrap.Enumerator, int?, int>(); + var result = wrapped.AsValueEnumerable() + .Sum(); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs new file mode 100644 index 000000000..1842f64dc --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using NetFabric.Assertive; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsAsyncValueEnumerable +{ + public partial class AsyncEnumerableTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsAsyncValueEnumerable1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsAsyncEnumerable(source); + + // Act + var result = wrapped + .AsAsyncValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, Wrap.AsyncEnumerator, Wrap.AsyncEnumerator, int, Wrap.AsyncEnumerableWrapper.GetAsyncEnumeratorFunction, Wrap.AsyncEnumerableWrapper.GetAsyncEnumeratorFunction>>() + .BeAsyncEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public async ValueTask AsAsyncValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsAsyncEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = await wrapped + .AsAsyncValueEnumerable() + .SumAsync() + .ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs new file mode 100644 index 000000000..12a3a8b9d --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using NetFabric.Assertive; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsAsyncValueEnumerable +{ + public partial class AsyncValueEnumerableTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsAsyncValueEnumerable1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsAsyncValueEnumerable(source); + + // Act + var result = wrapped + .AsAsyncValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, Wrap.AsyncEnumerator, Wrap.AsyncEnumerator, int, Wrap.AsyncValueEnumerableWrapper.GetAsyncEnumeratorFunction, Wrap.AsyncValueEnumerableWrapper.GetAsyncEnumeratorFunction>>() + .BeAsyncEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public async ValueTask AsAsyncValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsAsyncValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = await wrapped + .AsAsyncValueEnumerable() + .SumAsync() + .ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs similarity index 50% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs index ffd8b864a..5311a6b0f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs @@ -1,81 +1,82 @@ +using System.Linq; using NetFabric.Assertive; -using Xunit; using System.Collections.Generic; using System.Threading.Tasks; -using System; -using System.Linq; +using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsAsyncValueEnumerable { - public class ValueEnumerableTests + public partial class AsyncEnumerableTests { [Theory] [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsAsyncValueEnumerable_With_ValidData_Must_Succeed(int[] source) + public void AsAsyncValueEnumerable6_Enumerator_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap - .AsValueEnumerable(source); + .AsAsyncEnumerable(source); // Act var result = wrapped - .AsAsyncValueEnumerable, Wrap.Enumerator, int>(); + .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>( + (enumerable, _) => enumerable.GetAsyncEnumerator()); // Assert _ = result.Must() .BeAsyncEnumerableOf() .BeEqualTo(source); } - + [Theory] [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable_With_ToArrayAsync_Must_Succeed(int[] source) + public void AsAsyncValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap - .AsValueEnumerable(source); - var expected = source - .ToArray(); + .AsAsyncEnumerable(source); // Act - var result = await wrapped - .AsAsyncValueEnumerable, Wrap.Enumerator, int>() - .ToArrayAsync() - .ConfigureAwait(false); + var result = wrapped + .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, + AsyncValueEnumerator, int>( + (enumerable, _) => enumerable.GetAsyncEnumerator(), + (enumerable, cancellationToken) => + new AsyncValueEnumerator( + ((IAsyncEnumerable)enumerable).GetAsyncEnumerator(cancellationToken))); // Assert _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); + .BeAsyncEnumerableOf() + .BeEqualTo(source); } - + [Theory] [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable_With_ToListAsync_Must_Succeed(int[] source) + public async ValueTask AsAsyncValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap - .AsValueEnumerable(source); + .AsAsyncEnumerable(source); var expected = source - .ToList(); + .Sum(); // Act var result = await wrapped - .AsAsyncValueEnumerable, Wrap.Enumerator, int>() - .ToListAsync() + .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, AsyncValueEnumerator, int>( + (enumerable, _) => enumerable.GetAsyncEnumerator(), + (enumerable, cancellationToken) => new AsyncValueEnumerator(((IAsyncEnumerable)enumerable).GetAsyncEnumerator(cancellationToken))) + .SumAsync() .ConfigureAwait(false); // Assert _ = result.Must() - .BeOfType>() - .BeEnumerableOf() .BeEqualTo(expected); } } -} +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs new file mode 100644 index 000000000..5363407bc --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs @@ -0,0 +1,84 @@ +using System.Linq; +using NetFabric.Assertive; +using System.Collections.Generic; +using System.Threading.Tasks; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsAsyncValueEnumerable +{ + public partial class AsyncValueEnumerableTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsAsyncValueEnumerable6_Enumerator_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsAsyncValueEnumerable(source); + + // Act + var result = AsyncValueEnumerableExtensions + .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>( + wrapped, + (enumerable, _) => enumerable.GetAsyncEnumerator()); + + // Assert + _ = result.Must() + .BeAsyncEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsAsyncValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsAsyncValueEnumerable(source); + + // Act + var result = AsyncValueEnumerableExtensions + .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, AsyncValueEnumerator, int>( + wrapped, + (enumerable, _) => enumerable.GetAsyncEnumerator(), + (enumerable, cancellationToken) => + new AsyncValueEnumerator( + ((IAsyncEnumerable)enumerable).GetAsyncEnumerator(cancellationToken))); + + // Assert + _ = result.Must() + .BeAsyncEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public async ValueTask AsAsyncValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsAsyncValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = await AsyncValueEnumerableExtensions + .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, AsyncValueEnumerator, int>( + wrapped, + (enumerable, _) => enumerable.GetAsyncEnumerator(), + (enumerable, cancellationToken) => new AsyncValueEnumerator(((IAsyncEnumerable)enumerable).GetAsyncEnumerator(cancellationToken))) + .SumAsync() + .ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs deleted file mode 100644 index 4a64819dd..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.Tests.cs +++ /dev/null @@ -1,145 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsAsyncValueEnumerable -{ - public class AsyncEnumerableTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsAsyncValueEnumerable_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsAsyncEnumerable(source); - - // Act - var result = wrapped - .AsAsyncValueEnumerable(); - - // Assert - _ = result.Must() - .BeAsyncEnumerableOf() - .BeEqualTo(source); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable_With_ToArrayAsync_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsAsyncEnumerable(source); - var expected = source - .ToArray(); - - // Act - var result = await wrapped - .AsAsyncValueEnumerable() - .ToArrayAsync() - .ConfigureAwait(false); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable_With_ToListAsync_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsAsyncEnumerable(source); - var expected = source - .ToList(); - - // Act - var result = await wrapped - .AsAsyncValueEnumerable() - .ToListAsync() - .ConfigureAwait(false); - - // Assert - _ = result.Must() - .BeOfType>() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsAsyncValueEnumerable_GetEnumerator_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsAsyncEnumerable(source); - - // Act - var result = wrapped - .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>((enumerable, _) => enumerable.GetAsyncEnumerator()); - - // Assert - _ = result.Must() - .BeAsyncEnumerableOf() - .BeEqualTo(source); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable_GetEnumerator_ToListAsync_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsAsyncEnumerable(source); - - // Act - var result = await wrapped - .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>((enumerable, _) => enumerable.GetAsyncEnumerator()) - .ToListAsync() - .ConfigureAwait(false); - - // Assert - _ = result.Must() - .BeAsyncEnumerableOf() - .BeEqualTo(source); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable_GetEnumerator_ToArrayAsync_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsAsyncEnumerable(source); - - // Act - var result = await wrapped - .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>((enumerable, _) => enumerable.GetAsyncEnumerator()) - .ToArrayAsync() - .ConfigureAwait(false); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(source); - } - } -} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.Tests.cs deleted file mode 100644 index 4ff502669..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.Tests.cs +++ /dev/null @@ -1,41 +0,0 @@ -using NetFabric.Assertive; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsAsyncValueEnumerable -{ - public class AsyncValueEnumerableTests - { - [Fact] - public void AsAsyncValueEnumerable_With_ValueType_Must_ReturnCopy() - { - // Arrange - var source = new int[0]; - var wrapped = Wrap.AsAsyncValueEnumerable(source); - - // Act - var result = AsyncValueEnumerableExtensions - .AsAsyncValueEnumerable, Wrap.AsyncEnumerator, int>(wrapped); - - // Assert - _ = result.Must() - .BeEqualTo(wrapped); - } - - [Fact] - public void AsAsyncValueEnumerable_With_ReferenceType_Must_ReturnSame() - { - // Arrange - var source = new int[0]; - var wrapped = Wrap - .AsAsyncValueEnumerable(source) as IAsyncValueEnumerable>; - - // Act - var result = AsyncValueEnumerableExtensions - .AsAsyncValueEnumerable>, Wrap.AsyncEnumerator, int>(wrapped); - - // Assert - _ = result.Must() - .BeSameAs(wrapped); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs rename to NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs rename to NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs rename to NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs index 4f2f6fa86..a28bb7d92 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs @@ -23,7 +23,7 @@ public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) // Assert _ = result.Must() - .BeOfType, int>>() + .BeOfType, int>>() .BeEnumerableOf() .BeEqualTo(wrapped); } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs index 6e04524de..91baee4dd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable public class ValueEnumerableTests { [Fact] - public void AsValueEnumerable_With_ValueType_Must_ReturnCopy() + public void AsValueEnumerable_Must_ReturnCopy() { // Arrange var source = Array.Empty(); @@ -15,28 +15,13 @@ public void AsValueEnumerable_With_ValueType_Must_ReturnCopy() // Act var result = wrapped - .AsValueEnumerable, Wrap.Enumerator, int>(); + .AsValueEnumerable(); // Assert _ = result.Must() - .BeEqualTo(wrapped); - } - - [Fact] - public void AsValueEnumerable_With_ReferenceType_Must_ReturnSame() - { - // Arrange - var source = Array.Empty(); - var wrapped = Wrap - .AsValueEnumerable(source) as IValueEnumerable>; - - // Act - var result = wrapped - .AsValueEnumerable>, Wrap.Enumerator, int>(); - - // Assert - _ = result.Must() - .BeSameAs(wrapped); + .BeOfType, Wrap.Enumerator, Wrap.Enumerator, int, Wrap.ValueEnumerableWrapper.GetEnumeratorFunction, Wrap.ValueEnumerableWrapper.GetEnumeratorFunction>>() + .BeEnumerableOf() + .BeEqualTo(source); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs index 75ffc4796..3768ec8e9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs @@ -21,8 +21,8 @@ public void ToArray_With_ValidData_Must_Succeed(int[] source) .ToArray(); // Act - var result = ValueReadOnlyCollectionExtensions - .ToArray, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .ToArray(); // Assert _ = result.Must() @@ -43,8 +43,8 @@ public void ToArray_With_ValidData_Collections_Must_Succeed(int[] source) .ToArray(); // Act - var result = ValueReadOnlyCollectionExtensions - .ToArray, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .ToArray(); // Assert _ = result.Must() @@ -66,8 +66,8 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source) .ToArray(); // Act - using var result = ValueEnumerableExtensions - .ToArray, Wrap.Enumerator, int>(wrapped, pool); + using var result = wrapped.AsValueEnumerable() + .ToArray(pool); // Assert _ = result.Memory @@ -90,8 +90,8 @@ public void ToArray_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ToArray(); // Assert @@ -115,8 +115,8 @@ public void ToArray_Predicate_MemoryPool_With_ValidData_Must_Succeed(int[] sourc .ToArray(); // Act - using var result = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + using var result = wrapped.AsValueEnumerable() + .Select(selector) .ToArray(pool); // Assert @@ -140,8 +140,8 @@ public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ToArray(); // Assert @@ -165,8 +165,8 @@ public void ToArray_SelectorAt_MemoryPool_With_ValidData_Must_Succeed(int[] sour .ToArray(); // Act - using var result = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + using var result = wrapped.AsValueEnumerable() + .Select(selector) .ToArray(pool); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs index c47d409d2..9a2c667e7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs @@ -21,8 +21,8 @@ public void ToList_With_ValidData_Must_Succeed(int[] source) .ToList(); // Act - var result = ValueReadOnlyCollectionExtensions - .ToList, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .ToList(); // Assert _ = result.Must() @@ -44,8 +44,8 @@ public void ToList_With_ValidData_Collections_Must_Succeed(int[] source) .ToList(); // Act - var result = ValueReadOnlyCollectionExtensions - .ToList, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .ToList(); // Assert _ = result.Must() @@ -68,8 +68,8 @@ public void ToList_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ToList(); // Assert @@ -93,8 +93,8 @@ public void ToList_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ToList(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs index fc2aebb99..5020adab6 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs @@ -18,10 +18,10 @@ public void ElementAt_With_OutOfRange_Must_Return_None(int[] source) .AsValueReadOnlyCollection(source); // Act - var optionNegative = ValueReadOnlyCollectionExtensions - .ElementAt, Wrap.Enumerator, int>(wrapped, -1); - var optionTooLarge = ValueReadOnlyCollectionExtensions - .ElementAt, Wrap.Enumerator, int>(wrapped, source.Length); + var optionNegative = wrapped.AsValueEnumerable() + .ElementAt(-1); + var optionTooLarge = wrapped.AsValueEnumerable() + .ElementAt(source.Length); // Assert _ = optionNegative.Must() @@ -46,8 +46,8 @@ public void ElementAt_With_ValidData_Must_Return_Some(int[] source) .ElementAt(index); // Act - var result = ValueReadOnlyCollectionExtensions - .ElementAt, Wrap.Enumerator, int>(wrapped, index); + var result = wrapped.AsValueEnumerable() + .ElementAt(index); // Assert _ = result.Match( @@ -67,11 +67,11 @@ public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, Fu .AsValueReadOnlyCollection(source); // Act - var optionNegative = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var optionNegative = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(-1); - var optionTooLarge = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var optionTooLarge = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(source.Length); // Assert @@ -97,8 +97,8 @@ public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Fun for (var index = 0; index < source.Length; index++) { // Act - var result = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(index); // Assert @@ -119,11 +119,11 @@ public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, .AsValueReadOnlyCollection(source); // Act - var optionNegative = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var optionNegative = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(-1); - var optionTooLarge = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var optionTooLarge = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(source.Length); // Assert @@ -150,8 +150,8 @@ public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, F for (var index = 0; index < source.Length; index++) { // Act - var result = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .ElementAt(index); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs index ecbb6c856..f6b0b59ba 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs @@ -16,8 +16,8 @@ public void First_With_Empty_Must_Return_None(int[] source) .AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .First, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .First(); // Assert _ = result.Must() @@ -37,8 +37,8 @@ public void First_With_ValidData_Must_Return_Some(int[] source) .First(); // Act - var result = ValueReadOnlyCollectionExtensions - .First, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .First(); // Assert _ = result.Match( @@ -55,8 +55,8 @@ public void First_Selector_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .First(); // Assert @@ -78,8 +78,8 @@ public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .First(); // Assert @@ -97,8 +97,8 @@ public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .First(); // Assert @@ -120,8 +120,8 @@ public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func< .First(); // Act - var result = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .First(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs index 297504b08..c775732fd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs @@ -16,8 +16,8 @@ public void Single_With_Empty_Must_Return_None(int[] source) .AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .Single, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .Single(); // Assert _ = result.Must() @@ -36,8 +36,8 @@ public void Single_With_Single_Must_Return_Some(int[] source) .Single(); // Act - var result = ValueReadOnlyCollectionExtensions - .Single, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .Single(); // Assert _ = result.Match( @@ -54,8 +54,8 @@ public void Single_With_Multiple_Must_Return_None(int[] source) .AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .Single, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .Single(); // Assert _ = result.Must() @@ -72,8 +72,8 @@ public void Single_Selector_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -94,8 +94,8 @@ public void Single_Selector_With_Single_Must_Return_Some(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -113,8 +113,8 @@ public void Single_Selector_With_Multiple_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -132,8 +132,8 @@ public void Single_SelectorAt_With_Empty_Must_Return_None(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -154,8 +154,8 @@ public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert @@ -173,8 +173,8 @@ public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, Func< .AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector) + var result = wrapped.AsValueEnumerable() + .Select(selector) .Single(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs index 98296b29f..40d4d694f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs @@ -20,8 +20,8 @@ public void Where_With_ValidData_Must_Succeed(int[] source, Func pred .Where(predicate); // Act - var result = ValueReadOnlyCollectionExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped.AsValueEnumerable() + .Where(predicate); // Assert _ = result.Must() @@ -43,8 +43,8 @@ public void Where_Sum_With_ValidData_Must_Succeed(int[] source, Func .Sum(); // Act - var result = ValueReadOnlyCollectionExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Sum(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs index 6e9b8be68..15a5a77ce 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs @@ -20,8 +20,8 @@ public void Where_With_ValidData_Must_Succeed(int[] source, Func .Where(predicate); // Act - var result = ValueReadOnlyCollectionExtensions - .Where, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped.AsValueEnumerable() + .Where(predicate); // Assert _ = result.Must() @@ -43,8 +43,8 @@ public void Where_Sum_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Sum(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs index 85e45646b..7a946af1f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs @@ -20,8 +20,8 @@ public void WhereSelect_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(selector); // Assert @@ -44,8 +44,8 @@ public void WhereSelect_Sum_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate) + var result = wrapped.AsValueEnumerable() + .Where(predicate) .Select(item => item) .Count(); diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs index 9c77d46a1..826e183e3 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs @@ -19,7 +19,7 @@ public void Skip_With_ValidData_Must_Succeed(int[] source, int count) .Skip(count); // Act - var result = ValueReadOnlyCollectionExtensions.Skip, Wrap.Enumerator, int>(wrapped, count); + var result = wrapped.AsValueEnumerable().Skip(count); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs index b448bceb9..e9053f0b8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs @@ -19,8 +19,8 @@ public void Take_With_ValidData_Must_Succeed(int[] source, int count) .Take(count); // Act - var result = ValueReadOnlyCollectionExtensions - .Take, Wrap.Enumerator, int>(wrapped, count); + var result = wrapped.AsValueEnumerable() + .Take(count); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs index 60dafc5f5..9701c8224 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs @@ -19,8 +19,8 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func s .Select(selector); // Act - var result = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, string>(wrapped, selector); + var result = wrapped.AsValueEnumerable() + .Select(selector); // Assert _ = result.Must() @@ -41,8 +41,8 @@ public void Select_Sum_With_ValidData_Must_Succeed(int[] source) .Sum(); // Act - var result = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, int>(wrapped, item => item) + var result = wrapped.AsValueEnumerable() + .Select(item => item) .Sum(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs index 6f4d98c52..986037a58 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs @@ -19,8 +19,8 @@ public void Select_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int, string>(wrapped, selector); + var result = wrapped.AsValueEnumerable() + .Select(selector); // Assert _ = result.Must() @@ -41,8 +41,8 @@ public void Select_Sum_With_ValidData_Must_Succeed(int[] source) .Sum(); // Act - var result = ValueReadOnlyCollectionExtensions - .Select, Wrap.Enumerator, int, int>(wrapped, (item, _) => item) + var result = wrapped.AsValueEnumerable() + .Select((item, _) => item) .Sum(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs index defae1ba0..62347904c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs @@ -19,8 +19,8 @@ public void All_With_ValidData_Must_Succeed(int[] source, Func predic .All(predicate); // Act - var result = ValueReadOnlyCollectionExtensions - .All, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped.AsValueEnumerable() + .All(predicate); // Assert _ = result.Must() @@ -39,8 +39,8 @@ public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped.AsValueEnumerable() + .All(predicate); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs index 4c3ea433b..fce077d62 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs @@ -19,8 +19,8 @@ public void Any_With_ValidData_Must_Succeed(int[] source) source.Any(); // Act - var result = ValueReadOnlyCollectionExtensions - .Any, Wrap.Enumerator, int>(wrapped); + var result = wrapped.AsValueEnumerable() + .Any(); // Assert _ = result.Must() @@ -39,8 +39,8 @@ public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped.AsValueEnumerable() + .Any(predicate); // Assert _ = result.Must() @@ -59,8 +59,8 @@ public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func, Wrap.Enumerator, int>(wrapped, predicate); + var result = wrapped.AsValueEnumerable() + .Any(predicate); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs index 53919e908..4bc717404 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs @@ -18,8 +18,8 @@ public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value); + var result = wrapped.AsValueEnumerable() + .Contains(value); // Assert _ = result.Must() @@ -37,8 +37,8 @@ public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(in var wrapped = Wrap.AsValueReadOnlyCollection(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); // Act - var result = ValueReadOnlyCollectionExtensions - .Contains, Wrap.Enumerator, string>(wrapped, value); + var result = wrapped.AsValueEnumerable() + .Contains(value); // Assert _ = result.Must() @@ -56,8 +56,8 @@ public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] sour var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value); + var result = wrapped.AsValueEnumerable() + .Contains(value); // Assert _ = result.Must() @@ -76,8 +76,8 @@ public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] var wrapped = Wrap.AsValueReadOnlyCollection(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); // Act - var result = ValueReadOnlyCollectionExtensions - .Contains, Wrap.Enumerator, string>(wrapped, value); + var result = wrapped.AsValueEnumerable() + .Contains(value); // Assert _ = result.Must() @@ -95,8 +95,8 @@ public void Contains_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value, EqualityComparer.Default); + var result = wrapped.AsValueEnumerable() + .Contains(value, EqualityComparer.Default); // Assert _ = result.Must() @@ -114,8 +114,8 @@ public void Contains_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] sou var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value, EqualityComparer.Default); + var result = wrapped.AsValueEnumerable() + .Contains(value, EqualityComparer.Default); // Assert _ = result.Must() @@ -133,8 +133,8 @@ public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value, TestComparer.Instance); + var result = wrapped.AsValueEnumerable() + .Contains(value, TestComparer.Instance); // Assert _ = result.Must() @@ -152,8 +152,8 @@ public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act - var result = ValueReadOnlyCollectionExtensions - .Contains, Wrap.Enumerator, int>(wrapped, value, TestComparer.Instance); + var result = wrapped.AsValueEnumerable() + .Contains(value, TestComparer.Instance); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs index 985c894b6..8579095be 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs @@ -1,6 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Threading; namespace NetFabric.Hyperlinq @@ -11,6 +11,7 @@ public static AsyncEnumerableWrapper AsAsyncEnumerable(T[] source) => source switch { null => throw new ArgumentNullException(nameof(source)), + // ReSharper disable once HeapView.ObjectAllocation.Evident _ => new AsyncEnumerableWrapper(source) }; @@ -25,7 +26,20 @@ internal AsyncEnumerableWrapper(T[] source) public AsyncEnumerator GetAsyncEnumerator() => new(source); IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) + // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AsyncEnumerableExtensions.AsyncValueEnumerable, AsyncEnumerator, AsyncEnumerator, T, GetAsyncEnumeratorFunction, GetAsyncEnumeratorFunction> AsAsyncValueEnumerable() + => this.AsAsyncValueEnumerable, AsyncEnumerator, T, GetAsyncEnumeratorFunction>(); + + public readonly struct GetAsyncEnumeratorFunction + : IFunction, CancellationToken, AsyncEnumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AsyncEnumerator Invoke(AsyncEnumerableWrapper enumerable, CancellationToken _) + => enumerable.GetAsyncEnumerator(); + } } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs index 663592227..94b2302bd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs @@ -1,6 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Threading; namespace NetFabric.Hyperlinq @@ -27,7 +27,20 @@ public readonly AsyncEnumerator GetAsyncEnumerator() readonly AsyncEnumerator IAsyncValueEnumerable>.GetAsyncEnumerator(CancellationToken _) => new(source); readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) + // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AsyncValueEnumerableExtensions.AsyncValueEnumerable, AsyncEnumerator, AsyncEnumerator, T, GetAsyncEnumeratorFunction, GetAsyncEnumeratorFunction> AsAsyncValueEnumerable() + => AsyncValueEnumerableExtensions.AsAsyncValueEnumerable, AsyncEnumerator, T, GetAsyncEnumeratorFunction>(this); + + public readonly struct GetAsyncEnumeratorFunction + : IFunction, CancellationToken, AsyncEnumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AsyncEnumerator Invoke(AsyncValueEnumerableWrapper enumerable, CancellationToken _) + => enumerable.GetAsyncEnumerator(); + } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs index cda9174a7..6304e9481 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using Xunit.Sdk; namespace NetFabric.Hyperlinq { @@ -10,6 +11,7 @@ public static CollectionWrapper AsCollection(T[] source) => source switch { null => throw new ArgumentNullException(nameof(source)), + // ReSharper disable once HeapView.ObjectAllocation.Evident _ => new CollectionWrapper(source) }; @@ -28,7 +30,7 @@ public void CopyTo(T[] array, int arrayIndex) => source.CopyTo(array, arrayIndex); public bool Contains(T item) - => ((IList)source).Contains(item); + => ((ICollection)source).Contains(item); void ICollection.Add(T item) => throw new NotSupportedException(); diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs index f8f28551d..0f0c10a67 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -10,6 +11,7 @@ public static EnumerableWrapper AsEnumerable(T[] source) => source switch { null => throw new ArgumentNullException(nameof(source)), + // ReSharper disable once HeapView.ObjectAllocation.Evident _ => new EnumerableWrapper(source) }; @@ -24,9 +26,23 @@ internal EnumerableWrapper(T[] source) public Enumerator GetEnumerator() => new(source); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public EnumerableExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() + => this.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(); + + public readonly struct GetEnumeratorFunction + : IFunction, Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator Invoke(EnumerableWrapper enumerable) + => enumerable.GetEnumerator(); + } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs index d7dd17d0e..75fb6bd3a 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs @@ -10,6 +10,7 @@ public static ListWrapper AsList(T[] source) => source switch { null => throw new ArgumentNullException(nameof(source)), + // ReSharper disable once HeapView.ObjectAllocation.Evident _ => new ListWrapper(source) }; diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs index ea287ddbd..8d006b69c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs @@ -10,6 +10,7 @@ public static ReadOnlyCollectionWrapper AsReadOnlyCollection(T[] source) => source switch { null => throw new ArgumentNullException(nameof(source)), + // ReSharper disable once HeapView.ObjectAllocation.Evident _ => new ReadOnlyCollectionWrapper(source) }; @@ -23,6 +24,16 @@ public ReadOnlyCollectionWrapper(T[] source) public int Count => source.Length; + + public new ReadOnlyCollectionExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() + => ReadOnlyCollectionExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); + + public new readonly struct GetEnumeratorFunction + : IFunction, Enumerator> + { + public Enumerator Invoke(ReadOnlyCollectionWrapper enumerable) + => enumerable.GetEnumerator(); + } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs index d4e4e5621..c8218969f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs @@ -10,6 +10,7 @@ public static ReadOnlyListWrapper AsReadOnlyList(T[] source) => source switch { null => throw new ArgumentNullException(nameof(source)), + // ReSharper disable once HeapView.ObjectAllocation.Evident _ => new ReadOnlyListWrapper(source) }; @@ -23,6 +24,9 @@ internal ReadOnlyListWrapper(T[] source) public T this[int index] => source[index]; + + public new ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() + => this.AsValueEnumerable, T>(); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs index f9c8c6706..3de26eaf1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -28,8 +29,10 @@ public readonly int Count public readonly Enumerator GetEnumerator() => new(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); public bool IsReadOnly => true; @@ -46,6 +49,18 @@ bool ICollection.Remove(T item) => throw new NotSupportedException(); void ICollection.Clear() => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyCollectionExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() + => ValueReadOnlyCollectionExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); + + public readonly struct GetEnumeratorFunction + : IFunction, Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator Invoke(ValueCollectionWrapper enumerable) + => enumerable.GetEnumerator(); + } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs index 8b9660465..9abf009dd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -24,12 +25,23 @@ internal ValueEnumerableWrapper(T[] source) public readonly Enumerator GetEnumerator() => new(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); - public ValueEnumerableWrapper AsValueEnumerable() - => this.AsValueEnumerable, Enumerator, T>(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerableExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() + => ValueEnumerableExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); + + public readonly struct GetEnumeratorFunction + : IFunction, Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator Invoke(ValueEnumerableWrapper enumerable) + => enumerable.GetEnumerator(); + } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs index 2a5a9c285..946833dd8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -37,8 +38,10 @@ T IList.this[int index] public readonly Enumerator GetEnumerator() => new(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); public bool IsReadOnly => true; @@ -63,6 +66,10 @@ void IList.Insert(int index, T item) => throw new NotSupportedException(); void IList.RemoveAt(int index) => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.ValueEnumerable, Enumerator, T> AsValueEnumerable() + => this.AsValueEnumerable, Enumerator, T>(); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs index aef6a4fc5..82830591f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -27,9 +28,23 @@ public readonly int Count public readonly Enumerator GetEnumerator() => new(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ReadOnlyCollectionExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() + => ReadOnlyCollectionExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); + + public readonly struct GetEnumeratorFunction + : IFunction, Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator Invoke(ValueReadOnlyCollectionWrapper enumerable) + => enumerable.GetEnumerator(); + } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs index 02098845c..6c694d0c6 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -30,9 +31,15 @@ public readonly T this[int index] public readonly Enumerator GetEnumerator() => new(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.ValueEnumerable, Enumerator, T> AsValueEnumerable() + => this.AsValueEnumerable, Enumerator, T>(); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs index f933d6fdd..0b9b6834a 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs @@ -20,10 +20,15 @@ internal AsyncEnumerator(T[] source) } public readonly T Current - => source[index]; + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask MoveNextAsync() => new(++index < source.Length); + public readonly ValueTask DisposeAsync() => default; } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.Enumerator.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.Enumerator.cs index 4d944d7a8..09c670e6f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.Enumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.Enumerator.cs @@ -19,11 +19,16 @@ internal Enumerator(T[] source) index = -1; } - public readonly T Current - => source[index]; - readonly object IEnumerator.Current + public readonly T Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + readonly object? IEnumerator.Current + // ReSharper disable once HeapView.PossibleBoxingAllocation => source[index]; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() => ++index < source.Length; public void Reset() diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs index 4510feb15..ab487511e 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs @@ -9,7 +9,7 @@ public static TSum Sum(this TList source) where TSum : struct => source.Sum(0, source.Count); - static TSum Sum(this TList source, int offset, int count) + internal static TSum Sum(this TList source, int offset, int count) where TList : IReadOnlyList where TSum : struct { diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs new file mode 100644 index 000000000..c2467b810 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs @@ -0,0 +1,103 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace NetFabric.Hyperlinq +{ + public static partial class AsyncEnumerableExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable AsAsyncValueEnumerable(this IAsyncEnumerable source) + => new(source); + + [StructLayout(LayoutKind.Auto)] + public readonly partial struct AsyncValueEnumerable + : IAsyncValueEnumerable.AsyncEnumerator> + { + readonly IAsyncEnumerable source; + + internal AsyncValueEnumerable(IAsyncEnumerable source) + => this.source = source; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly AsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + => new(source, cancellationToken); + readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + // ReSharper disable once HeapView.BoxingAllocation + => new AsyncEnumerator(source, cancellationToken); + + public readonly struct AsyncEnumerator + : IAsyncEnumerator + { + readonly IAsyncEnumerator enumerator; + + internal AsyncEnumerator(IAsyncEnumerable enumerable, CancellationToken cancellationToken) + => enumerator = enumerable.GetAsyncEnumerator(cancellationToken); + + public readonly TSource Current + => enumerator.Current; + readonly TSource IAsyncEnumerator.Current + => enumerator.Current; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueTask MoveNextAsync() + => enumerator.MoveNextAsync(); + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueTask DisposeAsync() + => enumerator.DisposeAsync(); + } + + #region Conversion + + AsyncValueEnumerable AsAsyncEnumerable() + => this; + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, int, int>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, int?, int>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, long, long>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, long?, long>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, float, float>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, float?, float>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, double, double>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, double?, double>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, decimal, decimal>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, decimal?, decimal>(cancellationToken); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs new file mode 100644 index 000000000..92f272ea1 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs @@ -0,0 +1,93 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace NetFabric.Hyperlinq +{ + public static partial class AsyncValueEnumerableExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable AsAsyncValueEnumerable(this IAsyncValueEnumerable source) + where TEnumerator : struct, IAsyncEnumerator + => new(source); + + [StructLayout(LayoutKind.Auto)] + public readonly partial struct AsyncValueEnumerable + : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + { + readonly IAsyncValueEnumerable source; + + internal AsyncValueEnumerable(IAsyncValueEnumerable source) + => this.source = source; + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + => source.GetAsyncEnumerator(cancellationToken); + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + // ReSharper disable once HeapView.BoxingAllocation + => source.GetAsyncEnumerator(cancellationToken); + + #region Conversion + + AsyncValueEnumerable AsAsyncValueEnumerable() + => this; + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, int, int>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, int?, int>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, long, long>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, long?, long>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, float, float>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, float?, float>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, double, double>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, double?, double>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, decimal, decimal>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, decimal?, decimal>(cancellationToken); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs new file mode 100644 index 000000000..7439eb4c4 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace NetFabric.Hyperlinq +{ + public static partial class AsyncEnumerableExtensions + { + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + => AsAsyncValueEnumerable>(source, new FunctionWrapper(getAsyncEnumerator)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TGetAsyncEnumerator : struct, IFunction + => new(source, getAsyncEnumerator, getAsyncEnumerator); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator, Func getAsyncEnumerator2) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + => AsAsyncValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getAsyncEnumerator), new FunctionWrapper(getAsyncEnumerator2)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default, TGetAsyncEnumerator2 getAsyncEnumerator2 = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => new(source, getAsyncEnumerator, getAsyncEnumerator2); + + [StructLayout(LayoutKind.Auto)] + public partial struct AsyncValueEnumerable + : IAsyncValueEnumerable + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + { + readonly TEnumerable source; + TGetAsyncEnumerator getAsyncEnumerator; + TGetAsyncEnumerator2 getAsyncEnumerator2; + + internal AsyncValueEnumerable(TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator, TGetAsyncEnumerator2 getAsyncEnumerator2) + => (this.source, this.getAsyncEnumerator, this.getAsyncEnumerator2) = (source, getAsyncEnumerator, getAsyncEnumerator2); + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TEnumerator2 GetAsyncEnumerator(CancellationToken cancellationToken = default) + => getAsyncEnumerator2.Invoke(source, cancellationToken); + TEnumerator IAsyncValueEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + => getAsyncEnumerator.Invoke(source, cancellationToken); + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + // ReSharper disable once HeapView.PossibleBoxingAllocation + => source.GetAsyncEnumerator(cancellationToken); + + #region Conversion + + AsyncValueEnumerable AsAsyncValueEnumerable() + => this; + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, int, int>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, int?, int>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, long, long>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, long?, long>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, float, float>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, float?, float>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, double, double>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, double?, double>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, decimal, decimal>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, decimal?, decimal>(cancellationToken); + } +} diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs new file mode 100644 index 000000000..3982190f5 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace NetFabric.Hyperlinq +{ + public static partial class AsyncValueEnumerableExtensions + { + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => AsAsyncValueEnumerable>(source, new FunctionWrapper(getAsyncEnumerator)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TGetAsyncEnumerator : struct, IFunction + => new(source, getAsyncEnumerator, getAsyncEnumerator); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator, Func getAsyncEnumerator2) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + => AsAsyncValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getAsyncEnumerator), new FunctionWrapper(getAsyncEnumerator2)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default, TGetAsyncEnumerator2 getAsyncEnumerator2 = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => new(source, getAsyncEnumerator, getAsyncEnumerator2); + + [StructLayout(LayoutKind.Auto)] + public partial struct AsyncValueEnumerable + : IAsyncValueEnumerable + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + { + readonly TEnumerable source; + TGetAsyncEnumerator getAsyncEnumerator; + TGetAsyncEnumerator2 getAsyncEnumerator2; + + internal AsyncValueEnumerable(TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator, TGetAsyncEnumerator2 getAsyncEnumerator2) + => (this.source, this.getAsyncEnumerator, this.getAsyncEnumerator2) = (source, getAsyncEnumerator, getAsyncEnumerator2); + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TEnumerator2 GetAsyncEnumerator(CancellationToken cancellationToken = default) + => getAsyncEnumerator2.Invoke(source, cancellationToken); + TEnumerator IAsyncValueEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + => getAsyncEnumerator.Invoke(source, cancellationToken); + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + // ReSharper disable once HeapView.PossibleBoxingAllocation + => source.GetAsyncEnumerator(cancellationToken); + + #region Conversion + + AsyncValueEnumerable AsAsyncValueEnumerable() + => this; + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, int, int>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, int?, int>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, long, long>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, long?, long>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, float, float>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, float?, float>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, double, double>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, double?, double>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, decimal, decimal>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, decimal?, decimal>(cancellationToken); + } +} diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs deleted file mode 100644 index f02249d36..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncEnumerable.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; - -namespace NetFabric.Hyperlinq -{ - public static partial class AsyncEnumerableExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsyncValueEnumerableWrapper AsAsyncValueEnumerable(this IAsyncEnumerable source) - => new(source); - - [GeneratorIgnore] // TODO: to be removed - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsyncValueEnumerableWrapper AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator) - where TEnumerable : IAsyncEnumerable - where TEnumerator : struct, IAsyncEnumerator - => new(source, getAsyncEnumerator); - - public readonly partial struct AsyncValueEnumerableWrapper - : IAsyncValueEnumerable - where TEnumerable : IAsyncEnumerable - where TEnumerator : struct, IAsyncEnumerator - { - readonly TEnumerable source; - readonly Func getAsyncEnumerator; - - internal AsyncValueEnumerableWrapper(TEnumerable source, Func getAsyncEnumerator) - { - this.source = source; - this.getAsyncEnumerator = getAsyncEnumerator; - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) - => getAsyncEnumerator(source, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) - // ReSharper disable once HeapView.BoxingAllocation - => getAsyncEnumerator(source, cancellationToken); - } - - public readonly partial struct AsyncValueEnumerableWrapper - : IAsyncValueEnumerable.AsyncEnumerator> - { - readonly IAsyncEnumerable source; - - internal AsyncValueEnumerableWrapper(IAsyncEnumerable source) - => this.source = source; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly AsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) - => new(source, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) - // ReSharper disable once HeapView.BoxingAllocation - => new AsyncEnumerator(source, cancellationToken); - - public readonly struct AsyncEnumerator - : IAsyncEnumerator - { - readonly IAsyncEnumerator enumerator; - - internal AsyncEnumerator(IAsyncEnumerable enumerable, CancellationToken cancellationToken) - => enumerator = enumerable.GetAsyncEnumerator(cancellationToken); - - public readonly TSource Current - => enumerator.Current; - readonly TSource IAsyncEnumerator.Current - => enumerator.Current; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueTask MoveNextAsync() - => enumerator.MoveNextAsync(); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueTask DisposeAsync() - => enumerator.DisposeAsync(); - } - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.cs deleted file mode 100644 index f8da8bc8f..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.AsyncValueEnumerable.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class AsyncValueEnumerableExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TEnumerable AsAsyncValueEnumerable(this TEnumerable source) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - => source; - } -} diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.cs deleted file mode 100644 index 3d66cb4a3..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable.ValueEnumerable.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsyncValueEnumerableWrapper AsAsyncValueEnumerable(this TEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => new(source); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct AsyncValueEnumerableWrapper - : IAsyncValueEnumerable.AsyncEnumerator> - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - { - readonly TEnumerable source; - - internal AsyncValueEnumerableWrapper(TEnumerable source) - => this.source = source; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly AsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) - { - cancellationToken.ThrowIfCancellationRequested(); - return new AsyncEnumerator(source, cancellationToken); - } - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) - // ReSharper disable once HeapView.BoxingAllocation - => GetAsyncEnumerator(cancellationToken); - - [StructLayout(LayoutKind.Auto)] - public struct AsyncEnumerator - : IAsyncEnumerator - { - TEnumerator enumerator; - readonly CancellationToken cancellationToken; - - internal AsyncEnumerator(TEnumerable enumerable, CancellationToken cancellationToken) - { - enumerator = enumerable.GetEnumerator(); - this.cancellationToken = cancellationToken; - } - - public readonly TSource Current - => enumerator.Current; - readonly TSource IAsyncEnumerator.Current - => enumerator.Current; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask MoveNextAsync() - { - cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(enumerator.MoveNext()); - } - - public ValueTask DisposeAsync() - { - enumerator.Dispose(); - return default; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask ToArrayAsync(CancellationToken cancellationToken = default) - => new(result: source.ToArray()); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToListAsync(CancellationToken cancellationToken = default) - => new(result: source.ToList()); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsyncValueEnumerator.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsyncValueEnumerator.cs new file mode 100644 index 000000000..9c63c511f --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsyncValueEnumerator.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading.Tasks; + +namespace NetFabric.Hyperlinq +{ + [StructLayout(LayoutKind.Auto)] + public readonly struct AsyncValueEnumerator + : IAsyncEnumerator + { + readonly IAsyncEnumerator enumerator; + + public AsyncValueEnumerator(IAsyncEnumerator enumerator) + => this.enumerator = enumerator; + + public TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => enumerator.Current; + } + TSource IAsyncEnumerator.Current + => enumerator.Current; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask MoveNextAsync() + => enumerator.MoveNextAsync(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask DisposeAsync() + => enumerator.DisposeAsync(); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs index ea975d83d..e29b5e75b 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs @@ -29,6 +29,13 @@ IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index a8f49a657..30f127cf1 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -73,10 +73,20 @@ void ICollection.Clear() [ExcludeFromCodeCoverage] bool ICollection.Remove(TSource item) => Throw.NotSupportedException(); + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion + #region Quantifier [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource value, IEqualityComparer? comparer) => Count is not 0 && source.Contains(value, comparer); + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs new file mode 100644 index 000000000..c147ec255 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs @@ -0,0 +1,95 @@ +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueEnumerableExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this IValueEnumerable source) + where TEnumerator : struct, IEnumerator + => new(source); + + [StructLayout(LayoutKind.Auto)] + public readonly partial struct ValueEnumerable + : IValueEnumerable + where TEnumerator : struct, IEnumerator + { + readonly IValueEnumerable source; + + internal ValueEnumerable(IValueEnumerable source) + => this.source = source; + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TEnumerator GetEnumerator() + => source.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => source.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => source.GetEnumerator(); + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, decimal?, decimal>(); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs new file mode 100644 index 000000000..7fa8e661e --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyCollectionExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this IValueReadOnlyCollection source) + where TEnumerator : struct, IEnumerator + => new(source); + + [StructLayout(LayoutKind.Auto)] + public readonly partial struct ValueEnumerable + : IValueReadOnlyCollection + , ICollection + where TEnumerator : struct, IEnumerator + { + readonly IValueReadOnlyCollection source; + + internal ValueEnumerable(IValueReadOnlyCollection source) + => this.source = source; + + public int Count + => source.Count; + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TEnumerator GetEnumerator() + => source.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => source.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => source.GetEnumerator(); + + bool ICollection.IsReadOnly + => true; + + public void CopyTo(Span span) + { + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + + if (source.Count is not 0) + { + using var enumerator = GetEnumerator(); + checked + { + for (var index = 0; enumerator.MoveNext(); index++) + span[index] = enumerator.Current; + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TSource[] array, int arrayIndex) + => CopyTo(array.AsSpan().Slice(arrayIndex)); + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TSource item) + => Count is not 0 && source.Contains(item); + + [ExcludeFromCodeCoverage] + void ICollection.Add(TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void ICollection.Clear() + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + bool ICollection.Remove(TSource item) + => Throw.NotSupportedException(); + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, int, int>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, int?, int>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, long, long>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, long?, long>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, float, float>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, float?, float>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, double, double>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, double?, double>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, decimal, decimal>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, decimal?, decimal>(source); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs index c3a2e443a..bc95fa35a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -68,6 +68,13 @@ IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index c65bda255..db3bdf408 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -112,6 +112,12 @@ void ICollection.Clear() bool ICollection.Remove(TSource item) => Throw.NotSupportedException(); + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs new file mode 100644 index 000000000..0b28526f5 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueEnumerableExtensions + { + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TGetEnumerator : struct, IFunction + => new(source, getEnumerator, getEnumerator); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => new(source, getEnumerator, getEnumerator2); + + [StructLayout(LayoutKind.Auto)] + public partial struct ValueEnumerable + : IValueEnumerable + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + { + readonly TEnumerable source; + TGetEnumerator getEnumerator; + TGetEnumerator2 getEnumerator2; + + internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) + => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TEnumerator2 GetEnumerator() + => getEnumerator2.Invoke(source); + TEnumerator IValueEnumerable.GetEnumerator() + => getEnumerator.Invoke(source); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.PossibleBoxingAllocation + => source.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.PossibleBoxingAllocation + => source.GetEnumerator(); + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, int, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, long, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, long?, long>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, float, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, float?, float>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, double, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, double?, double>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, decimal, decimal>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, decimal?, decimal>(); + } +} diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs new file mode 100644 index 000000000..a087a17e8 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -0,0 +1,224 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyCollectionExtensions + { + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TGetEnumerator : struct, IFunction + => new(source, getEnumerator, getEnumerator); + + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => new(source, getEnumerator, getEnumerator2); + + [StructLayout(LayoutKind.Auto)] + public partial struct ValueEnumerable + : IValueReadOnlyCollection + , ICollection + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + { + readonly TEnumerable source; + TGetEnumerator getEnumerator; + TGetEnumerator2 getEnumerator2; + + internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) + => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); + + public readonly int Count + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TEnumerator2 GetEnumerator() + => getEnumerator2.Invoke(source); + TEnumerator IValueEnumerable.GetEnumerator() + => getEnumerator.Invoke(source); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => source.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => source.GetEnumerator(); + + bool ICollection.IsReadOnly + => true; + + public void CopyTo(Span span) + { + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + + if (source.Count is not 0) + { + using var enumerator = getEnumerator.Invoke(source); + checked + { + for (var index = 0; enumerator.MoveNext(); index++) + span[index] = enumerator.Current; + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TSource[] array, int arrayIndex) + => CopyTo(array.AsSpan().Slice(arrayIndex)); + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TSource item) + => Count is not 0 && EnumerableExtensions.Contains(source, item); + + [ExcludeFromCodeCoverage] + void ICollection.Add(TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void ICollection.Clear() + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + bool ICollection.Remove(TSource item) + => Throw.NotSupportedException(); + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, int, int>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, int?, int>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, long, long>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, long?, long>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, float, float>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, float?, float>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, double, double>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, double?, double>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, decimal, decimal>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, decimal?, decimal>(source); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs index f910096ed..5292f91b4 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs @@ -174,7 +174,13 @@ public readonly void Reset() public readonly void Dispose() { } } - + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion #region Partitioning [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index 1cf02f6a4..101c0702a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -148,7 +148,7 @@ public MemoryValueEnumerable AsValueEnumerable() => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyMemory ToArray() + public TSource[] ToArray() => source.Span.ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index 0ba7b0c09..dd9b1b778 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -54,7 +54,7 @@ public SpanValueEnumerable AsValueEnumerable() => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlySpan ToArray() + public TSource[] ToArray() => source.ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.cs deleted file mode 100644 index af42a4c86..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TEnumerable AsValueEnumerable(this TEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source; - } -} diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs new file mode 100644 index 000000000..bd5ed7afb --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs @@ -0,0 +1,269 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable, TEnumerator, TSource> AsValueEnumerable(this IValueReadOnlyList source) + where TEnumerator : struct, IEnumerator + => AsValueEnumerable, TEnumerator, TSource>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TList source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => new(source, 0, source.Count); + + [StructLayout(LayoutKind.Auto)] + public readonly partial struct ValueEnumerable + : IValueReadOnlyList.DisposableEnumerator> + , IList + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + { + internal readonly TList source; + internal readonly int offset; + + internal ValueEnumerable(TList source, int offset, int count) + => (this.source, this.offset, Count) = (source, offset, count); + + public readonly int Count { get; } + + public readonly TSource this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); + + return source[index + offset]; + } + } + + TSource IReadOnlyList.this[int index] + => this[index]; + + TSource IList.this[int index] + { + get => this[index]; + + [ExcludeFromCodeCoverage] + // ReSharper disable once ValueParameterNotUsed + set => Throw.NotSupportedException(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() + => new(in this); + + DisposableEnumerator IValueEnumerable.GetEnumerator() + => new(in this); + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => new DisposableEnumerator(in this); + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => new DisposableEnumerator(in this); + + + bool ICollection.IsReadOnly + => true; + + public void CopyTo(Span span) + { + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + + ReadOnlyListExtensions.Copy(this, 0, span, Count); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TSource[] array, int arrayIndex) + => CopyTo(array.AsSpan().Slice(arrayIndex)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TSource item) + => Count is not 0 && source.Contains(item); + + public int IndexOf(TSource item) + => ReadOnlyListExtensions.IndexOf(source, item, offset, Count); + + [ExcludeFromCodeCoverage] + void ICollection.Add(TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + bool ICollection.Remove(TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void ICollection.Clear() + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void IList.Insert(int index, TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void IList.RemoveAt(int index) + => Throw.NotSupportedException(); + + [StructLayout(LayoutKind.Auto)] + public struct Enumerator + { + readonly TList source; + readonly int end; + int index; + + internal Enumerator(in ValueEnumerable enumerable) + { + source = enumerable.source; + index = enumerable.offset - 1; + end = index + enumerable.Count; + } + + public TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index <= end; + } + + [StructLayout(LayoutKind.Auto)] + public struct DisposableEnumerator + : IEnumerator + { + readonly TList source; + readonly int end; + int index; + + internal DisposableEnumerator(in ValueEnumerable enumerable) + { + source = enumerable.source; + index = enumerable.offset - 1; + end = index + enumerable.Count; + } + + public TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + TSource IEnumerator.Current + => source[index]; + object? IEnumerator.Current + // ReSharper disable once HeapView.PossibleBoxingAllocation + => source[index]; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index <= end; + + [ExcludeFromCodeCoverage] + public readonly void Reset() + => Throw.NotSupportedException(); + + public readonly void Dispose() { } + } + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + #endregion + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerable Skip(int count) + { + var (skipCount, takeCount) = Utils.Skip(Count, count); + return new ValueEnumerable(source, offset + skipCount, takeCount); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerable Take(int count) + => new(source, offset, Utils.Take(Count, count)); + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this in ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TList : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => source.source.Sum(source.offset, source.Count); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 4d8de444e..384932e46 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -10,7 +10,6 @@ LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance true - enable true true @@ -76,4 +75,8 @@ + + + + diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs index caafa4e6c..04a93f3ab 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs @@ -209,8 +209,8 @@ public Option Single() #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.AsyncValueEnumerableWrapper, Enumerator, TResult> AsAsyncValueEnumerable() - => ValueEnumerableExtensions.AsAsyncValueEnumerable, Enumerator, TResult>(this); + public readonly ArraySegmentSelectManyEnumerable AsValueEnumerable() + => this; #endregion #region Partitioning diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs index c11ab2a77..8405360eb 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs @@ -229,8 +229,8 @@ public Option Single() #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.AsyncValueEnumerableWrapper, Enumerator, TResult> AsAsyncValueEnumerable() - => ValueEnumerableExtensions.AsAsyncValueEnumerable, Enumerator, TResult>(this); + public SelectManyEnumerable AsValueEnumerable() + => this; #endregion #region Partitioning diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs index f4164a3c8..81e08346a 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs @@ -208,8 +208,8 @@ public Option Single() #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.AsyncValueEnumerableWrapper, Enumerator, TResult> AsAsyncValueEnumerable() - => ValueEnumerableExtensions.AsAsyncValueEnumerable, Enumerator, TResult>(this); + public readonly MemorySelectManyEnumerable AsValueEnumerable() + => this; #endregion #region Partitioning diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs index ad3bb0104..fea266b3c 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs @@ -209,8 +209,8 @@ public Option Single() #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly AsyncValueEnumerableWrapper, Enumerator, TResult> AsAsyncValueEnumerable() - => ValueEnumerableExtensions.AsAsyncValueEnumerable, Enumerator, TResult>(this); + public readonly SelectManyEnumerable AsValueEnumerable() + => this; #endregion #region Partitioning diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs index cd23a9106..cb40ee140 100644 --- a/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs @@ -7,15 +7,15 @@ public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this ReadOnlySpan source) + static bool Any(this ReadOnlySpan source) => source.Length is not 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this in ReadOnlySpan source, Func predicate) + static bool Any(this in ReadOnlySpan source, Func predicate) => source.Any(new FunctionWrapper(predicate)); - public static bool Any(this ReadOnlySpan source, TPredicate predicate = default) + static bool Any(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { foreach (var item in source) @@ -27,10 +27,10 @@ public static bool Any(this ReadOnlySpan source, T } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this in ReadOnlySpan source, Func predicate) + static bool Any(this in ReadOnlySpan source, Func predicate) => source.AnyAt(new FunctionWrapper(predicate)); - public static bool AnyAt(this ReadOnlySpan source, TPredicate predicate = default) + static bool AnyAt(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { for (var index = 0; index < source.Length; index++) diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.Span.cs b/NetFabric.Hyperlinq/Quantifier/Any/Any.Span.cs index f157ae3a7..97b47ea5f 100644 --- a/NetFabric.Hyperlinq/Quantifier/Any/Any.Span.cs +++ b/NetFabric.Hyperlinq/Quantifier/Any/Any.Span.cs @@ -7,24 +7,24 @@ public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this Span source) + static bool Any(this Span source) => source.Length is not 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this Span source, Func predicate) + static bool Any(this Span source, Func predicate) => source.Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this Span source, TPredicate predicate = default) + static bool Any(this Span source, TPredicate predicate = default) where TPredicate : struct, IFunction => ((ReadOnlySpan)source).Any(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this Span source, Func predicate) + static bool Any(this Span source, Func predicate) => source.AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AnyAt(this Span source, TPredicate predicate = default) + static bool AnyAt(this Span source, TPredicate predicate = default) where TPredicate : struct, IFunction => ((ReadOnlySpan)source).AnyAt(predicate); } diff --git a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs index 55fab417e..e3b5a1041 100644 --- a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - public static bool ContainsVector(this ReadOnlySpan source, TSource value) + static bool ContainsVector(this ReadOnlySpan source, TSource value) where TSource : struct { if (source.Length is 0) diff --git a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs index deda3cf86..9dbfc7401 100644 --- a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs +++ b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs @@ -7,7 +7,7 @@ public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool ContainsVector(this Span source, TSource value) + static bool ContainsVector(this Span source, TSource value) where TSource : struct => ((ReadOnlySpan)source).ContainsVector(value); diff --git a/README.md b/README.md index 1383e56dd..6888bf44f 100644 --- a/README.md +++ b/README.md @@ -81,17 +81,16 @@ The names of the benchmarks are structured as follow: - _Memory_ - a `Memory<>` - _Enumerable_ - implements `IEnumerable<>` - _Collection_ - implements `IReadOnlyCollection<>` and `ICollection<>` - - _List_ - implements `IReadOnlyList<>` and `IList<>` but not an array + - _List_ - implements `IReadOnlyList<>` and `IList<>` but is not an array - _AsyncEnumerable_ - implements `IAsyncEnumerable<>` - The type of enumerator provided by the source: - _Value_ - the enumerator is a value type - _Reference_ - the enumerator is a reference type -- The contents of the source: - - _Sequential_ - contains numbers in sequential order - - _Random_ - contains numbers in random order - How the result of the operation is iterated: - _For_ - a `for` loop is used to call the indexer - - _Foreach_ - a `foreach` loop is used to call the enumerator + - _Foreach_ - a `foreach` loop is used to call the enumerator +- Has a variant: + - _SIMD_ - using SIMD ## Usage @@ -123,9 +122,9 @@ public static void Example(IReadOnlyList list) - `Netfabric.Hyperlinq` contains special versions of `AsValueEnumerable()` for better performance with all collections in the `System.Collections.Immutable` namespace. Projects targetting .NET Framework, `netcoreapp2.1` or `netstandard2.0`, require the addition of the [`NetFabric.Hyperlinq.Immutable` NuGet package](https://www.nuget.org/packages/NetFabric.Hyperlinq.Immutable/) dependency. -- All enumerables returned by `NetFabric.Hyperlinq` are compatible with `System.Linq`. +- Most enumerables returned by `NetFabric.Hyperlinq` are compatible with `System.Linq`. The exception is enumerables for `Span<>` or `ReadOnlySpan<>`. -`OrderByDescending()` is not yet available in `Netfabric.Hyperlinq` but can still be used without requiring any conversion: +This allows the use of `System.Linq` operators on `NetFabric.Hyperlinq` enumerables. `OrderByDescending()` is not yet available in `Netfabric.Hyperlinq` but can still be used without requiring any conversion: ``` csharp public static void Example(IReadOnlyList list) @@ -146,43 +145,51 @@ To add `NetFabric.Hyperlinq` operations after a `System.Linq` operation, simply ### Value delegates -Calling a lambda expression for each item of the collection is very expensive. `NetFabric.Hyperlinq` supports a much more performant alternative. +Calling a lambda expression for each item of the collection is very expensive. `NetFabric.Hyperlinq` supports an alternative that is not as practical but that has much better performance. -- Declare a `struct` that implements `IFunction<>` or `IFunctionIn<>`. +- Declare a `struct` that implements `IFunction<>`. Here's two examples of how to implement: ``` csharp -readonly struct DoubleOfInt32 +readonly struct MultiplyBy2 : IFunction { public int Invoke(int element) => element * 2; } -readonly struct DoubleOfInt32ByRef - : IFunctionIn +readonly struct LessThan + : IFunction { - public int Invoke(in int element) - => element * 2; + readonly int value; + + public LessThan(int value) + => this.value = value; + + public bool Invoke(int element) + => element < value; } ``` -- Add the name of the structure to the method generics arguments +- Pass an instance as a parameter or just add the type to the generics arguments list (uses the default constructor): ``` csharp public static void Example(IReadOnlyList list) { var result = list .AsValueEnumerable() - .Select(); + .Where(new LessThan(10)) + .Select(); foreach(var value in result) Console.WriteLine(value); } ``` +The instances are allocated on the stack and the methods calls are non-virtual. + ### Generation operations -In `NetFabric.Hyperlinq`, the generation operations like `Empty()`, `Range()`, `Repeat()` and `Return()` are static methods implemented in the static class `ValueEnumerable`. To use the equivalent operations from `NetFabric.Hyperlinq`, simply replace `Enumerable` for `ValueEnumerable`. +In `NetFabric.Hyperlinq`, the generation operations like `Empty()`, `Range()`, `Repeat()` and `Return()` are static methods implemented in the static class `ValueEnumerable`. To use them, instead of the `System.Linq` equivalents, simply use `ValueEnumerable` instead of `Enumerable`. ``` csharp public static void Example(int count) @@ -196,54 +203,6 @@ public static void Example(int count) } ``` -### Method return types - -Usually, when returning a query, it's used `IEnumerable<>` as the method return type: - -``` csharp -public static IEnumerable Example(int count) - => ValueEnumerable - .Range(0, count) - .Select(value => value * 2); -``` - -This allows the caller to use `System.Linq` or a `foreach` loop to pull and process the result. `NetFabric.Hyperlinq` can also be used but the `AsValueEnumerable()` conversion method has to be used. - -The operation in `NetFabric.Hyperlinq` are implemented so that they return the highest level enumeration interface possible. For example, the `Range()` operation return implements `IValueReadOnlyList<,>` and the subsequent `Select()` return does the same thing. `IValueReadOnlyList<,>` derives from `IReadOnlyList<>` so, we can change the method to return this interface: - -``` csharp -public static IReadOnlyList Example(int count) - => ValueEnumerable - .Range(0, count) - .Select(value => value * 2); -``` - -Now, the caller is free to use the enumerator or the indexer, which are provided by this interface. This means that, all previous methods of iteration can be used plus the `for` loops, which is much more efficient. The indexer performs fewer internal operations and doesn't need an enumerator instance. `NetFabric.Hyperlinq` can also be used and the `AsValueEnumerable()` conversion method still has to be used but, `NetFabric.Hyperlinq` will now use the indexer. - -Otherwise, `NetFabric.Hyperlinq` will use enumerators. It implements all enumerators as value types. This allows the enumerators not to be allocated on the heap and calls to its methods to be non-virtual. The `IEnumerable<>` interface, and all other derived BCL interfaces, convert the enumerator to the `IEnumerator<>` interface. This results in the enumerator to be boxed, undoing the mentioned benefits. - -`NetFabric.Hyperlinq` defines enumerable interfaces that contain the enumerator type as a generic parameter. This allows the caller to use it without boxing. Consider changing the method to return one of these interfaces: - -``` csharp -public static IValueReadOnlyList.DisposableEnumerator> Example(int count) - => ValueEnumerable - .Range(0, count) - .Select(value => value * 2); -``` - -The caller is now able to use `NetFabric.Hyperlinq` without requiring the `AsValueEnumerable()` conversion method. In this case, it will use the indexer in all subsequent operations but the enumerator is still available. In other cases (`IValueEnumerable<,>`, `IValueReadOnlyCollection<,>` and `IAsyncValueEnumerable<,>`) it will use the enumerator. - -`NetFabric.Hyperlinq` also implements the enumerables as value types. Returning an interface means that the enumerable will still be boxed. If you want to also avoid this, consider changing the return type to be the actual enumerable type. In this case: - -``` csharp -public static ReadOnlyList.SelectEnumerable Example(int count) - => ValueEnumerable - .Range(0, count) - .Select(value => value * 2); -``` - -**NOTE:** Returning the enumerable type or a value enumeration interface, allows major performance improvements but creates a library design issue. Changes in the method implementation may result in changes to the retun type. This is a breaking change. This is an issue on the public API but not so much for the private and internal methods. Take this into consideration when deciding on the return type. - ### Composition `NetFabric.Hyperlinq` operations can be composed just like with `System.Linq`. The difference is on how each one optimizes the internals to reduce the number of enumerators required to iterate the values. @@ -256,17 +215,7 @@ var result = source.AsValueEnumerable() .Select(item => item * 2); ``` -But, `System.Linq` does not do the same for this other example: - -``` csharp -var result = source.AsValueEnumerable() - .Where(item => item > 2) - .First(); -``` - -`System.Linq` has a second overload for methods, like `First()` and `Single()`, that take the predicate as a parameter and allow the `Where()` to be removed. In `NetFabric.Hyperlinq` this is not required. With the intention of reducing the code to be maintained and tested, these other overloads actually are not available in `NetFabric.Hyperlinq`. - -`NetFabric.Hyperlinq` includes many more composition optimizations. In the following code, only one enumerator is used, and only because of the `Where()` operation. Otherwise, the indexer would have been used instead. Also, the `Select()` is applied after `First()`, so that it's applied to only to the resulting item: +`NetFabric.Hyperlinq` includes many more composition optimizations. In the following code, only one enumerator is used: ``` csharp var result = array.AsValueEnumerable() @@ -279,7 +228,7 @@ var result = array.AsValueEnumerable() ### Option -In `System.Linq`, the aggregation operations like `First()`, `Single()` and `ElementAt()`, throw an exception when the source has no items. Often, empty collections are a valid scenario and exception handling is very slow. `System.Linq` has alternative methods like `FirstOrDefault()`, `SingleOrDefault()` and `ElementAtOrDefault()`, that return the `default` value instead of throwing. This is still an issue when the items are value-typed, where there's no way to distinguish between an empty collection and a valid item. +In `System.Linq`, the aggregation operations like `First()`, `Single()` and `ElementAt()`, throw an exception when the source has no items. Often, empty collections are a valid scenario and exception handling is very slow. `System.Linq` has alternative methods like `FirstOrDefault()`, `SingleOrDefault()` and `ElementAtOrDefault()`, that return the `default` value instead of throwing. This is still an issue when the items are of a value-type, where there's no way to distinguish between an empty collection and a valid item. In `NetFabric.Hyperlinq`, aggregation operations return an `Option<>` type. This is similar in behavior to the [`Nullable<>`](https://docs.microsoft.com/en-us/dotnet/api/system.nullable-1) but it can contain reference types. @@ -302,13 +251,17 @@ if (isSome) If you prefer a more functional approach, you can use `Match()` to specify the value returned when the collection has values and when it's empty. Here's how to use it to define the previous behavior of `First()` and `FirstOrDefault()`: ``` csharp -var first = source.AsValueEnumerable().First().Match( - item => item, - () => throw new InvalidOperationException("Sequence contains no elements")); - -var firstOrDefault = source.AsValueEnumerable().First().Match( - item => item, - () => default); +var first = source.AsValueEnumerable() + .First() + .Match( + item => item, + () => throw new InvalidOperationException("Sequence contains no elements")); + +var firstOrDefault = source.AsValueEnumerable() + .First() + .Match( + item => item, + () => default); Console.WriteLine(first); Console.WriteLine(firstOrDefault); @@ -317,45 +270,49 @@ Console.WriteLine(firstOrDefault); `Match()` can also be used to define actions: ``` csharp -source.AsValueEnumerable().First().Match( - item => Console.WriteLine(item), - () => { }); +source.AsValueEnumerable() + .First() + .Match( + item => Console.WriteLine(item), + () => { }); ``` The `NetFabric.Hyperlinq` operations can be applied to `Option<>`, including `Where()`, `Select()` and `SelectMany()`. These return another `Option<>` with the predicate/selector applied to the value, if it exists. ```csharp -source.AsValueEnumerable().First().Where(item => item > 2).Match( - item => Console.WriteLine(item), - () => { }); +source.AsValueEnumerable() + .First() + .Where(item => item > 2) + .Match( + item => Console.WriteLine(item), + () => { }); ``` ### Buffer pools [Buffer pools](https://adamsitnik.com/Array-Pool/) allow the use of heap memory without adding pressure to the garbage collector. It preallocates a chunk of memory and "rents" it as required. The garbage collector will add this memory to the Large Object Heap (LOH). -`ToArray()` is usually used to cache values for a brief period. `Netfabric.Hyperlinq` adds an oveload that takes a `MemoryPool<>` as a parameter: +`ToArray()` is frequently used to cache values for a brief period and the use of buffer pools may be useful. + +`Netfabric.Hyperlinq` adds an overload that takes a `MemoryPool<>` as a parameter: ``` csharp -using var buffer = source.AsValueEnumerable() - .ToArray(MemoryPool.Shared); -var memory = buffer.Memory; -// use memory here +void Method() +{ + using var buffer = source.AsValueEnumerable() + .ToArray(MemoryPool.Shared); + var memory = buffer.Memory; + // use memory here +} ``` It returns an [`IMemoryOwner<>`](https://docs.microsoft.com/en-us/dotnet/api/system.buffers.imemoryowner-1). The `using` statement guarantees that it is disposed and the buffer automatically returned to the pool. ### SIMD -`NetFabric.Hyperlinq` uses SIMD implicitly to improve performance when possible, but many times it can only be done explicitly by calling specific operations. - -SIMD improves performance by performing the same operations simultaneously on multiple items. The operation can only be performed if this number is met. This means that a remaining number of items has to be processed without SIMD. - -The items processed simultaneously are stored inside a [`System.Numerics.Vector`](https://docs.microsoft.com/en-us/dotnet/api/system.numerics.vector-1) structure. +`NetFabric.Hyperlinq` uses SIMD implicitly to improve performance of some operations. Many times this can only be done explicitly because it can only be used on a limited number of types and operations on them. -Operations that require an expression to process data, on the SIMD-enable equivalent require an expression that applies it at the [`System.Numerics.Vector`](https://docs.microsoft.com/en-us/dotnet/api/system.numerics.vector-1) level and another one at the item level. - -For this reason, and also because SIMD cannot be applied to all data types, SIMD specific operations have be called. The method has a `Vector` post-fix in the name. +In `NetFabric.Hyperlinq`, alternative methods that use SIMD, have the word `Vector` at the end of its name. You'll also find that the operations that require an expression, now require two. ``` csharp var result = list @@ -364,10 +321,12 @@ var result = list .ToArray(); ``` -These methods also support value delegates. In this case, the `struct` containing the expressions must implement two `IFunction<,>`. +SIMD improves performance by performing the same operations simultaneously on multiple items. The operation can only be performed if this number is met. This means that the remaining number of items has to be processed without SIMD. The first expression is applied on a [`System.Numerics.Vector<>`](https://docs.microsoft.com/en-us/dotnet/api/system.numerics.vector-1), while the second one is applied on an item. + +These methods also support the use of [value delegates](#value-delegates). In this case, the `struct` containing the expressions must implement two `IFunction<,>`: ``` csharp -readonly struct DoubleOfInt32 +readonly struct MultiplyBy2 : IFunction, Vector> , IFunction { @@ -382,7 +341,7 @@ public static void Example(List list) { var result = list .AsValueEnumerable() - .SelectVector() + .SelectVector() .ToArray(); foreach(var value in result) @@ -390,7 +349,7 @@ public static void Example(List list) } ``` -Please note that the operation `SelectVector()` does not return and enumerable. It returns the context required for subsequent operations like `ToArray()`, `ToList()`, and `Sum()`. +Please note that the operation `SelectVector()` does not return an enumerable. It returns the context required for subsequent operations like `ToArray()`, `ToList()`, and `Sum()`. Up until now I haven't found a way to improve the performance of `Select()` by using SIMD. The returned context allows the use of composition, exposing only the operations that can gain with the use of SIMD. From f41a0101d3e4e2f769e5c04106dee1c6b6f683a0 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Mon, 8 Mar 2021 23:23:10 +0000 Subject: [PATCH 16/61] Test Sum() for NaN and Infinity --- .../Aggregation/Sum.TestData.cs | 41 ++++++++++++------- .../Aggregation/Sum/Sum.ReadOnlyList.Tests.cs | 6 +-- .../Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs | 10 ++--- .../Sum/Sum.ValueEnumerable.Tests.cs | 10 ++--- .../Sum/Sum.ValueReadOnlyCollection.Tests.cs | 6 +-- .../SumAsync.AsyncValueEnumerable.Tests.cs | 10 ++--- 6 files changed, 47 insertions(+), 36 deletions(-) diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs index dc7ab01f9..7933b8ccd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs @@ -5,27 +5,38 @@ namespace NetFabric.Hyperlinq { public static partial class TestData { - public static TheoryData Sum + public static TheoryData Sum => new() { - { new int[] { } }, - { new[] { 1 } }, - { new[] { 1, 2, 3, 4, 5, 6, 7 } }, - { new[] { 1, 2, 3, 4, 5, 6, 7, 8 } }, // size of Vector - { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } }, - { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 } }, + { new double[] { } }, + { new[] { double.NaN } }, + { new[] { double.PositiveInfinity } }, + { new[] { 1.0 } }, + { new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 } }, + { new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 } }, + { new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 } }, + { new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 } }, + { new[] { double.NaN, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 } }, + { new[] { double.PositiveInfinity, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 } }, + { new[] { double.MaxValue, double.MaxValue } }, + { new[] { double.PositiveInfinity, double.PositiveInfinity } }, }; - public static TheoryData NullableSum + public static TheoryData NullableSum => new() { - { new int?[] { } }, - { new int?[] { null } }, - { new int?[] { 1 } }, - { new int?[] { null, null, null } }, - { new int?[] { null, 2, 3, 4, null } }, - { new int?[] { 1, 2, null, 4, 5 } }, - { new int?[] { 1, 2, 3, 4, 5 } }, + { new double?[] { } }, + { new double?[] { null } }, + { new double?[] { double.NaN } }, + { new double?[] { double.PositiveInfinity } }, + { new double?[] { 1 } }, + { new double?[] { null, null, null } }, + { new double?[] { null, 2.0, double.NaN, 4.0, null } }, + { new double?[] { null, 2.0, 3.0, 4.0, null } }, + { new double?[] { 1.0, 2.0, null, 4.0, 5.0 } }, + { new double?[] { 1.0, 2.0, 3.0, 4.0, 5.0 } }, + { new double?[] { double.MaxValue, double.MaxValue } }, + { new double?[] { double.PositiveInfinity, double.PositiveInfinity } }, }; } diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs index cdadb2af4..7d00a03b9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs @@ -9,7 +9,7 @@ public class ReadOnlyListTests { [Theory] [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public void Sum_With_ValidData_Must_Succeed(int[] source) + public void Sum_With_ValidData_Must_Succeed(double[] source) { // Arrange var wrapped = Wrap.AsList(source); @@ -27,7 +27,7 @@ public void Sum_With_ValidData_Must_Succeed(int[] source) [Theory] [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) + public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) { // Arrange var wrapped = Wrap.AsList(source); @@ -40,7 +40,7 @@ public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) // Assert _ = result.Must() - .BeEqualTo(expected.Value); + .BeEqualTo(expected!.Value); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs index f9e885fbb..c44e6f00e 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs @@ -10,10 +10,10 @@ public class ArrayTests [Theory] [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public void Sum_With_ValidData_Must_Succeed(int[] source) + public void Sum_With_ValidData_Must_Succeed(double[] source) { // Arrange - var wrapped = (ReadOnlySpan)source.AsSpan(); + var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = source .Sum(); @@ -28,10 +28,10 @@ public void Sum_With_ValidData_Must_Succeed(int[] source) [Theory] [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) + public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) { // Arrange - var wrapped = (ReadOnlySpan)source.AsSpan(); + var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = source .Sum(); @@ -41,7 +41,7 @@ public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) // Assert _ = result.Must() - .BeEqualTo(expected.Value); + .BeEqualTo(expected!.Value); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs index 711a4b286..b4420fa02 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs @@ -9,7 +9,7 @@ public class ValueEnumerableTests { [Theory] [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public void Sum_With_ValidData_Must_Succeed(int[] source) + public void Sum_With_ValidData_Must_Succeed(double[] source) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); @@ -18,7 +18,7 @@ public void Sum_With_ValidData_Must_Succeed(int[] source) // Act var result = wrapped - .Sum, Wrap.Enumerator, int, int>(); + .Sum, Wrap.Enumerator, double, double>(); // Assert _ = result.Must() @@ -27,7 +27,7 @@ public void Sum_With_ValidData_Must_Succeed(int[] source) [Theory] [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) + public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); @@ -36,11 +36,11 @@ public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) // Act var result = wrapped - .Sum, Wrap.Enumerator, int?, int>(); + .Sum, Wrap.Enumerator, double?, double>(); // Assert _ = result.Must() - .BeEqualTo(expected.Value); + .BeEqualTo(expected!.Value); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs index e6b8d5828..0dae33b78 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs @@ -9,7 +9,7 @@ public class ValueReadOnlyCollectionTests { [Theory] [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public void Sum_With_ValidData_Must_Succeed(int[] source) + public void Sum_With_ValidData_Must_Succeed(double[] source) { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); @@ -27,7 +27,7 @@ public void Sum_With_ValidData_Must_Succeed(int[] source) [Theory] [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) + public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); @@ -40,7 +40,7 @@ public void Sum_With_Nullable_ValidData_Must_Succeed(int?[] source) // Assert _ = result.Must() - .BeEqualTo(expected.Value); + .BeEqualTo(expected!.Value); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs index 83b6a9539..42c63580b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs @@ -10,7 +10,7 @@ public class AsyncValueEnumerableTests { [Theory] [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public async ValueTask SumAsync_With_ValidData_Must_Succeed(int[] source) + public async ValueTask SumAsync_With_ValidData_Must_Succeed(double[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -19,7 +19,7 @@ public async ValueTask SumAsync_With_ValidData_Must_Succeed(int[] source) // Act var result = await wrapped - .SumAsync, Wrap.AsyncEnumerator, int, int>() + .SumAsync, Wrap.AsyncEnumerator, double, double>() .ConfigureAwait(false); // Assert @@ -29,7 +29,7 @@ public async ValueTask SumAsync_With_ValidData_Must_Succeed(int[] source) [Theory] [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public async ValueTask SumAsync_With_Nullable_ValidData_Must_Succeed(int?[] source) + public async ValueTask SumAsync_With_Nullable_ValidData_Must_Succeed(double?[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -38,12 +38,12 @@ public async ValueTask SumAsync_With_Nullable_ValidData_Must_Succeed(int?[] sour // Act var result = await wrapped - .SumAsync, Wrap.AsyncEnumerator, int?, int>() + .SumAsync, Wrap.AsyncEnumerator, double?, double>() .ConfigureAwait(false); // Assert _ = result.Must() - .BeEqualTo(expected.Value); + .BeEqualTo(expected!.Value); } } } \ No newline at end of file From 98e83e934f8b29d8b6ab202a9ecb96663df25882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Tue, 9 Mar 2021 00:04:19 +0000 Subject: [PATCH 17/61] Fix coverage (#346) --- .github/workflows/dotnetcore.yml | 8 ++------ .../NetFabric.Hyperlinq.UnitTests.csproj | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 04a9e8ef8..d12ba49b3 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -18,16 +18,12 @@ jobs: - name: Build solution run: dotnet build - name: Tests and coverage - run: dotnet test ./NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj -f:net5.0 -c:Release --collect:"XPlat Code Coverage" --settings coverlet.runsettings - - name: Get path to lcov file - id: get_lcov_path - shell: bash - run: printf '::set-output name=lcov_path::%s\n' ./NetFabric.Hyperlinq.UnitTests/TestResults/*/coverage.info + run: dotnet test ./NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj -f:net5.0 -p:CollectCoverage=true -p:CoverletOutputFormat=lcov -p:CoverletOutput=TestResults/ - name: Publish coverage report to coveralls.io uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ${{ steps.get_lcov_path.outputs.lcov_path }} + path-to-lcov: ./NetFabric.Hyperlinq.UnitTests/TestResults/coverage.net5.0.info diff --git a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj index b23123814..a94851a7d 100644 --- a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj +++ b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj @@ -10,7 +10,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 3aa217cfe0339d388587abf77fb2fe9413b7b505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Tue, 9 Mar 2021 13:24:33 +0000 Subject: [PATCH 18/61] Code review (#347) --- NetFabric.Hyperlinq.Benchmarks/Program.cs | 2 +- .../Aggregation/Sum.TestData.cs | 10 +- ...ueEnumerable'1.ReadOnlyCollection.Tests.cs | 22 ++ ...ValueEnumerable'1.ValueEnumerable.Tests.cs | 51 +++ ...merable'1.ValueReadOnlyCollection.Tests.cs | 73 ++++ ...ueEnumerable'6.ReadOnlyCollection.Tests.cs | 25 ++ ...ValueEnumerable'6.ValueEnumerable.Tests.cs | 78 ++++ ...merable'6.ValueReadOnlyCollection.Tests.cs | 102 ++++++ .../AsValueEnumerable.ArraySegment.Tests.cs | 61 +--- .../AsValueEnumerable.ReadOnlyList.Tests.cs | 89 ++--- .../AsValueEnumerable.ReadOnlyMemory.Tests.cs | 55 +-- .../AsValueEnumerable.ReadOnlySpan.Tests.cs | 51 +-- ...AsValueEnumerable.ValueEnumerable.Tests.cs | 27 -- ...ValueEnumerable.ValueReadOnlyList.Tests.cs | 156 ++++++++ .../Element/ElementAt.TestData.cs | 4 +- .../Generation/Range.TestData.cs | 6 +- .../Generation/Repeat.TestData.cs | 4 +- .../Generation/Return.TestData.cs | 2 +- .../Option/Option.Tests.cs | 12 +- .../Option/TestData.Option.cs | 36 +- .../Partitioning/Skip.TestData.cs | 3 + .../Partitioning/Take.TestData.cs | 12 +- .../Contains.AsyncValueEnumerable.Tests.cs | 2 +- .../Contains/Contains.ReadOnlyList.Tests.cs | 2 +- .../Contains/Contains.ReadOnlySpan.Tests.cs | 2 +- .../Contains.ValueEnumerable.Tests.cs | 2 +- .../Contains.ValueReadOnlyCollection.Tests.cs | 4 +- .../TestData/TestData.Empty.cs | 190 +++++----- .../TestData/TestData.Multiple.cs | 338 +++++++++--------- .../TestData/TestData.Single.cs | 236 ++++++------ .../Utils/SpanExtensions.cs | 53 ++- .../AsValueEnumerable.ArraySegment.cs | 2 +- .../AsValueEnumerable.ReadOnlyMemory.cs | 6 +- .../AsValueEnumerable.ReadOnlySpan.cs | 2 +- .../ToDictionary/ToDictionary.ReadOnlySpan.cs | 8 +- .../ToDictionaryAsync.AsyncValueEnumerable.cs | 8 +- .../SequenceEqual.ReadOnlySpan.cs | 4 +- .../Where/Where/Where.ReadOnlyMemory.cs | 2 +- .../Where/Where/Where.ReadOnlySpan.cs | 2 +- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 2 +- .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 2 +- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 2 +- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 2 +- .../Generation/ValueEnumerable/Empty.cs | 2 +- .../Generation/ValueEnumerable/Return.cs | 9 +- .../Select/Select/Select.ArraySegment.cs | 7 +- .../Select/Select/Select.ReadOnlyMemory.cs | 2 +- .../Select/Select/Select.ReadOnlySpan.cs | 2 +- .../Select/SelectAt/SelectAt.ArraySegment.cs | 9 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 2 +- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 2 +- .../Select/SelectVector/SelectVector.Range.cs | 51 ++- .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 4 +- .../Set/Distinct/Distinct.ReadOnlySpan.cs | 4 +- 54 files changed, 1143 insertions(+), 703 deletions(-) create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.Benchmarks/Program.cs b/NetFabric.Hyperlinq.Benchmarks/Program.cs index 2fdf7ee52..1a9c412c4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Program.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Program.cs @@ -98,7 +98,7 @@ static string GetInformationalVersion(Assembly assembly) dir = Path.GetDirectoryName(dir); } - return null; + return default; } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs index 7933b8ccd..56a200f6d 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs @@ -26,14 +26,14 @@ public static TheoryData NullableSum => new() { { new double?[] { } }, - { new double?[] { null } }, + { new double?[] { default } }, { new double?[] { double.NaN } }, { new double?[] { double.PositiveInfinity } }, { new double?[] { 1 } }, - { new double?[] { null, null, null } }, - { new double?[] { null, 2.0, double.NaN, 4.0, null } }, - { new double?[] { null, 2.0, 3.0, 4.0, null } }, - { new double?[] { 1.0, 2.0, null, 4.0, 5.0 } }, + { new double?[] { default, default, default } }, + { new double?[] { default, 2.0, double.NaN, 4.0, default } }, + { new double?[] { default, 2.0, 3.0, 4.0, default } }, + { new double?[] { 1.0, 2.0, default, 4.0, 5.0 } }, { new double?[] { 1.0, 2.0, 3.0, 4.0, 5.0 } }, { new double?[] { double.MaxValue, double.MaxValue } }, { new double?[] { double.PositiveInfinity, double.PositiveInfinity } }, diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs index fcd2a1558..5550c1295 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs @@ -26,6 +26,28 @@ public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) .BeEqualTo(source); } + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyCollection(source); + var expected = source + .Count(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + [Theory] [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.Tests.cs new file mode 100644 index 000000000..99625d156 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.Tests.cs @@ -0,0 +1,51 @@ +using System.Linq; +using NetFabric.Assertive; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ValueEnumerableTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueEnumerable(source); + + // Act + var result = wrapped + .AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.Tests.cs new file mode 100644 index 000000000..48ef26ecb --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.Tests.cs @@ -0,0 +1,73 @@ +using System.Linq; +using NetFabric.Assertive; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ValueReadOnlyCollectionTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueReadOnlyCollection1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + + // Act + var result = wrapped + .AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueReadOnlyCollection1_Count_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Count(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueReadOnlyCollection1_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs index a75108d8a..a7911b8d9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs @@ -52,6 +52,31 @@ public void AsValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[] sou .BeEqualTo(source); } + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Count_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsReadOnlyCollection(source); + var expected = source + .Count(); + + // Act + var result = ReadOnlyCollectionExtensions + .AsValueEnumerable, Wrap.Enumerator, ValueEnumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator(), + enumerable => new ValueEnumerator(((IEnumerable)enumerable).GetEnumerator())) + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + [Theory] [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.Tests.cs new file mode 100644 index 000000000..5c933ab0c --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.Tests.cs @@ -0,0 +1,78 @@ +using System.Linq; +using NetFabric.Assertive; +using System.Collections.Generic; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ValueEnumerableTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueEnumerable(source); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueEnumerable(source); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs new file mode 100644 index 000000000..fd662cde5 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs @@ -0,0 +1,102 @@ +using System.Linq; +using NetFabric.Assertive; +using System.Collections.Generic; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ValueReadOnlyCollectionTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Count_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Count(); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()) + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Sum(); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs index a7f8660b2..f074dee01 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs @@ -27,29 +27,6 @@ public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) result.SequenceEqual(source).Must().BeTrue(); } - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var wrapped = new ArraySegment(source); - var expected = source - .Skip(count); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(count); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - result.SequenceEqual(expected).Must().BeTrue(); - } - [Theory] [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) @@ -74,20 +51,20 @@ public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] sourc } [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count) + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) { // Arrange var wrapped = new ArraySegment(source); var expected = source - .Take(count); + .Take(count0) + .Take(count1); // Act var result = wrapped .AsValueEnumerable() - .Take(count); + .Take(count0) + .Take(count1); // Assert _ = result.Must() @@ -97,26 +74,27 @@ public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, in } [Theory] - [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) { // Arrange var wrapped = new ArraySegment(source); var expected = source - .Take(count0) - .Take(count1); + .Skip(skipCount) + .Take(takeCount) + .Count(); // Act - var result = wrapped - .AsValueEnumerable() - .Take(count0) - .Take(count1); + var result = wrapped.AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .Count(); // Assert _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - result.SequenceEqual(expected).Must().BeTrue(); + .BeEqualTo(expected); } [Theory] @@ -133,8 +111,7 @@ public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int .Sum(); // Act - var result = wrapped - .AsValueEnumerable() + var result = wrapped.AsValueEnumerable() .Skip(skipCount) .Take(takeCount) .Sum(); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs index a28bb7d92..73cd22e55 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs @@ -29,43 +29,24 @@ public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) } [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source) + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source, int skipCount, int takeCount) { // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .ToArray(source); - - // Act - var result = wrapped - .AsValueEnumerable() + var expected = source + .Skip(skipCount) + .Take(takeCount) .ToArray(); - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_Collection_With_ToArray_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsList(source); - var expected = Enumerable - .ToArray(source); - // Act var result = wrapped .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) .ToArray(); // Assert @@ -76,7 +57,7 @@ public void AsValueEnumerable_Collection_With_ToArray_Must_Succeed(int[] source) [Theory] [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + public void AsValueEnumerable_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) { // Arrange var wrapped = Wrap @@ -96,51 +77,53 @@ public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] sourc .BeEnumerableOf() .BeEqualTo(expected); } - + [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count) + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) { // Arrange var wrapped = Wrap .AsReadOnlyList(source); - var expected = Enumerable - .ToList(source); + var expected = source + .Take(count0) + .Take(count1); // Act var result = wrapped .AsValueEnumerable() - .ToList(); + .Take(count0) + .Take(count1); // Assert _ = result.Must() - .BeOfType>() .BeEnumerableOf() .BeEqualTo(expected); } - + [Theory] - [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) { // Arrange var wrapped = Wrap .AsReadOnlyList(source); var expected = source - .Take(count0) - .Take(count1); + .Skip(skipCount) + .Take(takeCount) + .Count(); // Act var result = wrapped .AsValueEnumerable() - .Take(count0) - .Take(count1); + .Skip(skipCount) + .Take(takeCount) + .Count(); // Assert _ = result.Must() - .BeEnumerableOf() .BeEqualTo(expected); } @@ -152,19 +135,21 @@ public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int { // Arrange var wrapped = Wrap - .AsList(source); - var expected = Enumerable - .ToList(source); + .AsReadOnlyList(source); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .Sum(); // Act var result = wrapped .AsValueEnumerable() - .ToList(); + .Skip(skipCount) + .Take(takeCount) + .Sum(); // Assert _ = result.Must() - .BeOfType>() - .BeEnumerableOf() .BeEqualTo(expected); } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs index d250d6d35..839b6bc1d 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs @@ -27,29 +27,6 @@ public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) result.SequenceEqual(source).Must().BeTrue(); } - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var wrapped = (ReadOnlyMemory)source.AsMemory(); - var expected = source - .Skip(count); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(count); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - result.SequenceEqual(expected).Must().BeTrue(); - } - [Theory] [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) @@ -74,20 +51,20 @@ public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] sourc } [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count) + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) { // Arrange var wrapped = (ReadOnlyMemory)source.AsMemory(); var expected = source - .Take(count); + .Take(count0) + .Take(count1); // Act var result = wrapped .AsValueEnumerable() - .Take(count); + .Take(count0) + .Take(count1); // Assert _ = result.Must() @@ -97,26 +74,28 @@ public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, in } [Theory] - [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) { // Arrange var wrapped = (ReadOnlyMemory)source.AsMemory(); var expected = source - .Take(count0) - .Take(count1); + .Skip(skipCount) + .Take(takeCount) + .Count(); // Act var result = wrapped .AsValueEnumerable() - .Take(count0) - .Take(count1); + .Skip(skipCount) + .Take(takeCount) + .Count(); // Assert _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected, testRefStructs: false); - result.SequenceEqual(expected).Must().BeTrue(); + .BeEqualTo(expected); } [Theory] diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs index ba6fe399c..112315775 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs @@ -24,26 +24,6 @@ public void AsValueEnumerable1_With_ValidData_Must_Succeed(int[] source) result.SequenceEqual(source).Must().BeTrue(); } - [Theory] - [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Skip_With_ValidData_Must_Succeed(int[] source, int count) - { - // Arrange - var wrapped = (ReadOnlySpan)source.AsSpan(); - var expected = source - .Skip(count); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(count); - - // Assert - result.SequenceEqual(expected).Must().BeTrue(); - } - [Theory] [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) @@ -65,43 +45,48 @@ public void AsValueEnumerable1_Skip_Skip_With_ValidData_Must_Succeed(int[] sourc } [Theory] - [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count) + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = source - .Take(count); + .Take(count0) + .Take(count1); // Act var result = wrapped .AsValueEnumerable() - .Take(count); + .Take(count0) + .Take(count1); // Assert result.SequenceEqual(expected).Must().BeTrue(); } [Theory] - [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); var expected = source - .Take(count0) - .Take(count1); + .Skip(skipCount) + .Take(takeCount) + .Count(); // Act var result = wrapped .AsValueEnumerable() - .Take(count0) - .Take(count1); + .Skip(skipCount) + .Take(takeCount) + .Count(); // Assert - result.SequenceEqual(expected).Must().BeTrue(); + _ = result.Must() + .BeEqualTo(expected); } [Theory] diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs deleted file mode 100644 index 91baee4dd..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueEnumerable.Tests.cs +++ /dev/null @@ -1,27 +0,0 @@ -using NetFabric.Assertive; -using System; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable -{ - public class ValueEnumerableTests - { - [Fact] - public void AsValueEnumerable_Must_ReturnCopy() - { - // Arrange - var source = Array.Empty(); - var wrapped = Wrap.AsValueEnumerable(source); - - // Act - var result = wrapped - .AsValueEnumerable(); - - // Assert - _ = result.Must() - .BeOfType, Wrap.Enumerator, Wrap.Enumerator, int, Wrap.ValueEnumerableWrapper.GetEnumeratorFunction, Wrap.ValueEnumerableWrapper.GetEnumeratorFunction>>() - .BeEnumerableOf() - .BeEqualTo(source); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs new file mode 100644 index 000000000..1bb2126fb --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs @@ -0,0 +1,156 @@ +using NetFabric.Assertive; +using Xunit; +using System.Collections.Generic; +using System.Linq; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public class ValueReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + + // Act + var result = wrapped + .AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeOfType, Wrap.Enumerator, int>>() + .BeEnumerableOf() + .BeEqualTo(wrapped); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source, int skipCount, int takeCount) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .ToArray(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .ToArray(); + + // Assert + _ = result.Must() + .BeArrayOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] + public void AsValueEnumerable_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(count0) + .Skip(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(count0) + .Skip(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Take(count0) + .Take(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Take(count0) + .Take(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .Count(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs index 12579d778..1eaa182f9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData ElementAtOutOfRange => - new TheoryData + new() { { new int[] { }, -1 }, { new int[] { }, 0 }, @@ -19,7 +19,7 @@ public static partial class TestData }; public static TheoryData ElementAt => - new TheoryData + new() { { new[] { 1 }, 0}, { new[] { 1, 2, 3, 4, 5 }, 0 }, diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs index 43de5fd24..e15c5d210 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData Range => - new TheoryData + new() { { -1, 0 }, { 0, 0 }, @@ -18,7 +18,7 @@ public static partial class TestData }; public static TheoryData Range_SkipTake => - new TheoryData + new() { { 1, 5, -1 }, { 1, 5, 0 }, @@ -28,7 +28,7 @@ public static partial class TestData }; public static TheoryData Range_Contains => - new TheoryData + new() { { 0, 0, 0 }, { 1, 5, -1 }, diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs index a6f5d31dc..a3db3c380 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData Repeat => - new TheoryData + new() { { 0, 0 }, { 0, 1 }, @@ -15,7 +15,7 @@ public static partial class TestData }; public static TheoryData Repeat_SkipTake => - new TheoryData + new() { { 1, 0, 0 }, { 1, 5, -1 }, diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs index 27f13098f..e19a56b59 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData Return => - new TheoryData + new() { int.MinValue, 0, int.MaxValue, }; diff --git a/NetFabric.Hyperlinq.UnitTests/Option/Option.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Option/Option.Tests.cs index 31139eea7..66560026c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Option/Option.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Option/Option.Tests.cs @@ -25,7 +25,7 @@ public void Option_With_None_Must_Succeed() [Theory] [MemberData(nameof(TestData.OptionSome), MemberType = typeof(TestData))] - public void Option_With_Some_Must_Succeed(string expected) + public void Option_With_Some_Must_Succeed(string? expected) { // Arrange var option = Option.Some(expected); @@ -59,7 +59,7 @@ public void Option_MatchFunc_With_None_Must_Call_None() [Theory] [MemberData(nameof(TestData.OptionSome), MemberType = typeof(TestData))] - public void Option_MatchFunc_With_Some_Must_Call_Some(string expected) + public void Option_MatchFunc_With_Some_Must_Call_Some(string? expected) { // Arrange var option = Option.Some(expected); @@ -91,7 +91,7 @@ public void Option_MatchAction_With_None_Must_Call_None() [Theory] [MemberData(nameof(TestData.OptionSome), MemberType = typeof(TestData))] - public void Option_MatchActionWith_Some_Must_Call_Some(string expected) + public void Option_MatchActionWith_Some_Must_Call_Some(string? expected) { // Arrange var option = Option.Some(expected); @@ -121,7 +121,7 @@ public void Option_Count_With_None_Must_Return_0() [Theory] [MemberData(nameof(TestData.OptionSome), MemberType = typeof(TestData))] - public void Option_Count_With_Some_Must_Return_1(string value) + public void Option_Count_With_Some_Must_Return_1(string? value) { // Arrange var option = Option.Some(value); @@ -148,7 +148,7 @@ public void Option_Any_With_None_Must_Return_False() [Theory] [MemberData(nameof(TestData.OptionSome), MemberType = typeof(TestData))] - public void Option_Any_With_Some_Must_Return_True(string value) + public void Option_Any_With_Some_Must_Return_True(string? value) { // Arrange var option = Option.Some(value); @@ -178,7 +178,7 @@ public void Option_SelectMany_With_None_Must_Succeed(int[] expected) [Theory] [MemberData(nameof(TestData.OptionSomeSelectMany), MemberType = typeof(TestData))] - public void Option_SelectMany_With_Some_Must_Succeed(string value, int[] expected) + public void Option_SelectMany_With_Some_Must_Succeed(string? value, int[] expected) { // Arrange var option = Option.Some(value); diff --git a/NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs b/NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs index 6a70cef3e..9d87a7a34 100644 --- a/NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs +++ b/NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs @@ -5,34 +5,34 @@ namespace NetFabric.Hyperlinq { public static partial class TestData { - public static TheoryData OptionSome => - new TheoryData + public static TheoryData OptionSome => + new() { - { (string)null }, - { string.Empty }, - { "string" }, + default, + string.Empty, + "string", }; public static TheoryData OptionNoneSelectMany => - new TheoryData + new() { - { new int[] { } }, - { new int[] { 1 } }, - { new int[] { 1, 2, 3, 4, 5 } }, + new int[] { }, + new[] { 1 }, + new[] { 1, 2, 3, 4, 5 }, }; - public static TheoryData OptionSomeSelectMany => - new TheoryData + public static TheoryData OptionSomeSelectMany => + new() { - { (string)null, new int[] { } }, - { (string)null, new int[] { 1 } }, - { (string)null, new int[] { 1, 2, 3, 4, 5 } }, + { default, new int[] { } }, + { default, new[] { 1 } }, + { default, new[] { 1, 2, 3, 4, 5 } }, { string.Empty, new int[] { } }, - { string.Empty, new int[] { 1 } }, - { string.Empty, new int[] { 1, 2, 3, 4, 5 } }, + { string.Empty, new[] { 1 } }, + { string.Empty, new[] { 1, 2, 3, 4, 5 } }, { "string", new int[] { } }, - { "string", new int[] { 1 } }, - { "string", new int[] { 1, 2, 3, 4, 5 } }, + { "string", new[] { 1 } }, + { "string", new[] { 1, 2, 3, 4, 5 } }, }; } diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs index 64214a382..ba63c6d75 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs @@ -24,6 +24,9 @@ public static partial class TestData { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, -1 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 0 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 5, 5 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 10, 10 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 20, 20 }, }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs index 059e79536..de2add957 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs @@ -15,19 +15,25 @@ public static partial class TestData { new int[] { }, -1, 0 }, { new int[] { }, 0, 0 }, { new int[] { }, 1, 0 }, + { new int[] { }, 0, 1 }, { new[] { 1 }, -1, -1 }, { new[] { 1 }, 0, 0 }, { new[] { 1 }, 0, 1 }, + { new[] { 1 }, 1, 0 }, { new[] { 1 }, 1, 1 }, { new[] { 1 }, 5, 2 }, { new[] { 1 }, 5, 5 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, -1 }, - { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 2 }, - { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 0 }, - { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 1 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 4, 0 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 4, 1 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 1, 4 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 4, 2 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 10, 10 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 20, 20 }, }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs index c2c39d1f8..6ca97f10f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs @@ -35,7 +35,7 @@ public async ValueTask ContainsAsync_ValueType_With_Null_And_NotContains_Must_Re public async ValueTask ContainsAsync_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - const string value = default; + const string? value = default; var wrapped = Wrap.AsAsyncValueEnumerable(source.Select(item => item.ToString()).ToArray()); // Act diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs index b3daaa1b0..7ad5facb1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs @@ -33,7 +33,7 @@ public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - const string value = default; + const string? value = default; var wrapped = Wrap.AsValueReadOnlyList(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); // Act diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs index 0cf850180..84ba5871c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs @@ -34,7 +34,7 @@ public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - const string value = default; + const string? value = default; var wrapped = source.AsValueEnumerable().Select(item => item.ToString()).ToArray(); // Act diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs index 892a045e1..0d78459f4 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs @@ -33,7 +33,7 @@ public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - const string value = default; + const string? value = default; var wrapped = Wrap.AsValueEnumerable(source.Select(item => item.ToString()).ToArray()); // Act diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs index 4bc717404..db485b9a7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs @@ -33,8 +33,8 @@ public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange - const string value = default; - var wrapped = Wrap.AsValueReadOnlyCollection(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); + const string? value = default; + var wrapped = Wrap.AsValueReadOnlyCollection(source.Select(item => item.ToString()).ToArray()); // Act var result = wrapped.AsValueEnumerable() diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs index 9340f5dd7..95b5c1968 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs @@ -6,41 +6,41 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData Empty => - new TheoryData + new() { - { new int[] { } }, + new int[] { }, }; public static TheoryData SkipEmpty => - new TheoryData + new() { { new int[] { }, -1 }, { new int[] { }, 0 }, { new int[] { }, 1 }, - { new int[] { 1 }, 1 }, - { new int[] { 1 }, 5 }, + { new[] { 1 }, 1 }, + { new[] { 1 }, 5 }, - { new int[] { 0, 1, 2 }, 3 }, - { new int[] { 0, 1, 2 }, 5 }, + { new[] { 0, 1, 2 }, 3 }, + { new[] { 0, 1, 2 }, 5 }, }; public static TheoryData TakeEmpty => - new TheoryData + new() { { new int[] { }, -1 }, { new int[] { }, 0 }, { new int[] { }, 1 }, - { new int[] { 5 }, -1 }, - { new int[] { 5 }, 0 }, + { new[] { 5 }, -1 }, + { new[] { 5 }, 0 }, - { new int[] { 0, 1, 2, 3, 4, 5 }, -1 }, - { new int[] { 0, 1, 2, 3, 4, 5 }, 0 }, + { new[] { 0, 1, 2, 3, 4, 5 }, -1 }, + { new[] { 0, 1, 2, 3, 4, 5 }, 0 }, }; public static TheoryData SkipTakeEmpty => - new TheoryData + new() { { new int[] { }, -1, -1 }, { new int[] { }, -1, 0 }, @@ -50,180 +50,180 @@ public static partial class TestData { new int[] { }, 1, 0 }, { new int[] { }, 1, 9 }, - { new int[] { 1 }, -1, -1 }, - { new int[] { 1 }, -1, 0 }, - { new int[] { 1 }, 0, -1 }, - { new int[] { 1 }, 0, 0 }, - { new int[] { 1 }, 1, 0 }, - { new int[] { 1 }, 1, 9 }, + { new[] { 1 }, -1, -1 }, + { new[] { 1 }, -1, 0 }, + { new[] { 1 }, 0, -1 }, + { new[] { 1 }, 0, 0 }, + { new[] { 1 }, 1, 0 }, + { new[] { 1 }, 1, 9 }, - { new int[] { 1, 2, 3, 4, 5 }, -1, -1 }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 0 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, -1 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, -1 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 0 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 0 }, - { new int[] { 1, 2, 3, 4, 5 }, 9, 0 }, - { new int[] { 1, 2, 3, 4, 5 }, 9, 9 }, + { new[] { 1, 2, 3, 4, 5 }, -1, -1 }, + { new[] { 1, 2, 3, 4, 5 }, -1, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 0, -1 }, + { new[] { 1, 2, 3, 4, 5 }, 2, -1 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 9, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 9, 9 }, }; public static TheoryData> PredicateEmpty => - new TheoryData> + new() { { new int[] { }, _ => false }, { new int[] { }, _ => true }, - { new int[] { 1 }, _ => false }, - { new int[] { 1 }, item => item > 9 }, + { new[] { 1 }, _ => false }, + { new[] { 1 }, item => item > 9 }, - { new int[] { 1, 2, 3, 4, 5 }, _ => false }, - { new int[] { 1, 2, 3, 4, 5 }, item => item > 9 }, + { new[] { 1, 2, 3, 4, 5 }, _ => false }, + { new[] { 1, 2, 3, 4, 5 }, item => item > 9 }, }; public static TheoryData> SkipTakePredicateEmpty => - new TheoryData> + new() { { new int[] { }, 0, 9, _ => false }, { new int[] { }, 0, 0, _ => true }, { new int[] { }, 0, 9, item => item > 9 }, - { new int[] { 1 }, 0, 0, _ => true }, - { new int[] { 1 }, 9, 9, _ => true }, - { new int[] { 1 }, 0, 9, _ => false }, - { new int[] { 1 }, 0, 9, item => item > 9 }, + { new[] { 1 }, 0, 0, _ => true }, + { new[] { 1 }, 9, 9, _ => true }, + { new[] { 1 }, 0, 9, _ => false }, + { new[] { 1 }, 0, 9, item => item > 9 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 0, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 9, 9, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item > 9 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 0, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 9, 9, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item > 9 }, }; public static TheoryData, Func> PredicatePredicateEmpty => - new TheoryData, Func> + new() { { new int[] { }, _ => true, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, _ => false, _ => false }, - { new int[] { 1, 2, 3, 4, 5 }, _ => true, _ => false }, - { new int[] { 1, 2, 3, 4, 5 }, _ => false, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, _ => false, _ => false }, + { new[] { 1, 2, 3, 4, 5 }, _ => true, _ => false }, + { new[] { 1, 2, 3, 4, 5 }, _ => false, _ => true }, }; public static TheoryData, Func> SkipTakePredicatePredicateEmpty => - new TheoryData, Func> + new() { { new int[] { }, 0, 9, _ => true, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, _ => false }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, _ => false }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, _ => false }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, _ => false }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, _ => true }, }; public static TheoryData> PredicateAtEmpty => - new TheoryData> + new() { { new int[] { }, (_, __) => false }, { new int[] { }, (_, __) => true }, - { new int[] { 1 }, (_, __) => false }, - { new int[] { 1 }, (item, _) => item > 9 }, - { new int[] { 1 }, (_, index) => index > 9 }, + { new[] { 1 }, (_, __) => false }, + { new[] { 1 }, (item, _) => item > 9 }, + { new[] { 1 }, (_, index) => index > 9 }, - { new int[] { 1, 2, 3, 4, 5 }, (_, __) => false }, - { new int[] { 1, 2, 3, 4, 5 }, (item, _) => item > 9 }, - { new int[] { 1, 2, 3, 4, 5 }, (_, index) => index > 9 }, + { new[] { 1, 2, 3, 4, 5 }, (_, __) => false }, + { new[] { 1, 2, 3, 4, 5 }, (item, _) => item > 9 }, + { new[] { 1, 2, 3, 4, 5 }, (_, index) => index > 9 }, }; public static TheoryData> SkipTakePredicateAtEmpty => - new TheoryData> + new() { { new int[] { }, 0, 9, (_, __) => false }, { new int[] { }, 0, 0, (_, __) => true }, { new int[] { }, 0, 9, (item, _) => item > 9 }, { new int[] { }, 0, 9, (_, index) => index > 9 }, - { new int[] { 1 }, 0, 0, (_, __) => true }, - { new int[] { 1 }, 0, 9, (_, __) => false }, - { new int[] { 1 }, 0, 9, (item, _) => item > 9 }, - { new int[] { 1 }, 0, 9, (_, index) => index > 9 }, + { new[] { 1 }, 0, 0, (_, __) => true }, + { new[] { 1 }, 0, 9, (_, __) => false }, + { new[] { 1 }, 0, 9, (item, _) => item > 9 }, + { new[] { 1 }, 0, 9, (_, index) => index > 9 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 0, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (_, __) => false }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (item, _) => item > 9 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index > 9 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 0, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (_, __) => false }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (item, _) => item > 9 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index > 9 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 0, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, (_, __) => false }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, (item, _) => item > 9 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index > 9 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 0, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, __) => false }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (item, _) => item > 9 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index > 9 }, }; public static TheoryData> SelectorEmpty => - new TheoryData> + new() { { new int[] { }, item => item.ToString() }, }; public static TheoryData> SkipTakeSelectorEmpty => - new TheoryData> + new() { { new int[] { }, 0, 0, item => item.ToString() }, { new int[] { }, 0, 9, item => item.ToString() }, - { new int[] { 1 }, 0, 0, item => item.ToString() }, - { new int[] { 1 }, 9, 9, item => item.ToString() }, + { new[] { 1 }, 0, 0, item => item.ToString() }, + { new[] { 1 }, 9, 9, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 0, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 9, 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 0, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 9, 9, item => item.ToString() }, }; public static TheoryData> SelectorAtEmpty => - new TheoryData> + new() { { new int[] { }, (item, index) => $"{item} {index}" }, }; public static TheoryData> SkipTakeSelectorAtEmpty => - new TheoryData> + new() { { new int[] { }, 0, 0, (item, index) => $"{item} {index}" }, { new int[] { }, 0, 9, (item, index) => $"{item} {index}" }, - { new int[] { 1 }, 0, 0, (item, index) => $"{item} {index}" }, - { new int[] { 1 }, 9, 9, (item, index) => $"{item} {index}" }, + { new[] { 1 }, 0, 0, (item, index) => $"{item} {index}" }, + { new[] { 1 }, 9, 9, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 0, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 9, 9, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 0, 0, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 9, 9, (item, index) => $"{item} {index}" }, }; public static TheoryData, Func> PredicateSelectorEmpty => - new TheoryData, Func> + new() { { new int[] { }, _ => false, item => item.ToString() }, { new int[] { }, _ => true, item => item.ToString() }, - { new int[] { 1 }, _ => false, item => item.ToString() }, - { new int[] { 1 }, item => item > 9, item => item.ToString() }, + { new[] { 1 }, _ => false, item => item.ToString() }, + { new[] { 1 }, item => item > 9, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, _ => false, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, item => item > 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, _ => false, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => item > 9, item => item.ToString() }, }; public static TheoryData, Func> SkipTakePredicateSelectorEmpty => - new TheoryData, Func> + new() { { new int[] { }, 0, 9, _ => false, item => item.ToString() }, { new int[] { }, 0, 0, _ => true, item => item.ToString() }, { new int[] { }, 0, 9, item => item > 9, item => item.ToString() }, - { new int[] { 1 }, 0, 0, _ => true, item => item.ToString() }, - { new int[] { 1 }, 9, 9, _ => true, item => item.ToString() }, - { new int[] { 1 }, 0, 9, _ => false, item => item.ToString() }, - { new int[] { 1 }, 0, 9, item => item > 9, item => item.ToString() }, + { new[] { 1 }, 0, 0, _ => true, item => item.ToString() }, + { new[] { 1 }, 9, 9, _ => true, item => item.ToString() }, + { new[] { 1 }, 0, 9, _ => false, item => item.ToString() }, + { new[] { 1 }, 0, 9, item => item > 9, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 0, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 9, 9, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item > 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 0, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 9, 9, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item > 9, item => item.ToString() }, }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs index 35d83699e..3c7181d1b 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs @@ -6,237 +6,237 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData Multiple => - new TheoryData + new() { - { new int[] { 1, 2, 3, 4, 5 } }, + { new[] { 1, 2, 3, 4, 5 } }, }; public static TheoryData SkipMultiple => - new TheoryData + new() { - { new int[] { 1, 2, 3, 4, 5 }, -1 }, - { new int[] { 1, 2, 3, 4, 5 }, 0 }, - { new int[] { 1, 2, 3, 4, 5 }, 2 }, + { new[] { 1, 2, 3, 4, 5 }, -1 }, + { new[] { 1, 2, 3, 4, 5 }, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 2 }, }; public static TheoryData TakeMultiple => - new TheoryData + new() { - { new int[] { 1, 2, 3, 4, 5 }, 2 }, - { new int[] { 1, 2, 3, 4, 5 }, 5 }, - { new int[] { 1, 2, 3, 4, 5 }, 9 }, + { new[] { 1, 2, 3, 4, 5 }, 2 }, + { new[] { 1, 2, 3, 4, 5 }, 5 }, + { new[] { 1, 2, 3, 4, 5 }, 9 }, }; public static TheoryData SkipTakeMultiple => - new TheoryData + new() { - { new int[] { 1, 2, 3, 4, 5 }, -1, 2 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 2 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 2 }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 5 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 5 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 3 }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 9 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9 }, + { new[] { 1, 2, 3, 4, 5 }, -1, 2 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 2 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 2 }, + { new[] { 1, 2, 3, 4, 5 }, -1, 5 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 5 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 3 }, + { new[] { 1, 2, 3, 4, 5 }, -1, 9 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9 }, }; public static TheoryData> PredicateMultiple => - new TheoryData> + new() { - { new int[] { 1, 2, 3, 4, 5 }, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5 }, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1 }, }; public static TheoryData> SkipTakePredicateMultiple => - new TheoryData> - { - { new int[] { 1, 2, 3, 4, 5 }, -1, 2, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 2, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 2, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 5, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 5, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 3, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 9, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, _ => true }, - - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, item => (item & 0x01) == 0 }, - - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, item => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, item => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, item => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, item => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, item => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, item => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, item => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, item => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, item => (item & 0x01) == 1 }, + new() + { + { new[] { 1, 2, 3, 4, 5 }, -1, 2, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 2, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 2, 2, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, -1, 5, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 5, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 2, 3, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, -1, 9, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, _ => true }, + + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, item => (item & 0x01) == 0 }, + + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, item => (item & 0x01) == 1 }, }; public static TheoryData, Func> PredicatePredicateMultiple => - new TheoryData, Func> + new() { - { new int[] { 1, 2, 3, 4, 5 }, _ => true, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, _ => true, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, _ => true, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, _ => true, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1, _ => true }, }; public static TheoryData, Func> SkipTakePredicatePredicateMultiple => - new TheoryData, Func> + new() { - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, item => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => (item & 0x01) == 1, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, item => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => (item & 0x01) == 1, _ => true }, }; public static TheoryData> PredicateAtMultiple => - new TheoryData> + new() { - { new int[] { 1, 2, 3, 4, 5 }, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, (item, _) => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5 }, (item, _) => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5 }, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5 }, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5 }, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, (item, _) => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5 }, (item, _) => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5 }, (_, index) => (index & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5 }, (_, index) => (index & 0x01) == 1 }, }; public static TheoryData> SkipTakePredicateAtMultiple => - new TheoryData> - { - { new int[] { 1, 2, 3, 4, 5 }, 0, 2, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 2, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 5, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 5, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 3, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 9, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, (_, __) => true }, - - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, (item, _) => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, (item, _) => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, (item, _) => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, (item, _) => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, (item, _) => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, (item, _) => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, (item, _) => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, (item, _) => (item & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (item, _) => (item & 0x01) == 0 }, - - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, (item, _) => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, (item, _) => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, (item, _) => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, (item, _) => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, (item, _) => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, (item, _) => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, (item, _) => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, (item, _) => (item & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (item, _) => (item & 0x01) == 1 }, - - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (_, index) => (index & 0x01) == 0 }, + new() + { + { new[] { 1, 2, 3, 4, 5 }, 0, 2, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 2, 2, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, -1, 5, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 5, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 2, 3, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, -1, 9, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, __) => true }, + + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, (item, _) => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, (item, _) => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, (item, _) => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, (item, _) => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, (item, _) => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, (item, _) => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, (item, _) => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, (item, _) => (item & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (item, _) => (item & 0x01) == 0 }, + + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, (item, _) => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, (item, _) => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, (item, _) => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, (item, _) => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, (item, _) => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, (item, _) => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, (item, _) => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, (item, _) => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (item, _) => (item & 0x01) == 1 }, + + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, (_, index) => (index & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, (_, index) => (index & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, (_, index) => (index & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, (_, index) => (index & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, (_, index) => (index & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, (_, index) => (index & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, (_, index) => (index & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, (_, index) => (index & 0x01) == 0 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (_, index) => (index & 0x01) == 0 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, (_, index) => (index & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, (_, index) => (index & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, (_, index) => (index & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, (_, index) => (index & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, (_, index) => (index & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, (_, index) => (index & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, (_, index) => (index & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, (_, index) => (index & 0x01) == 1 }, - { new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 4, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 4, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 9, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (_, index) => (index & 0x01) == 1 }, }; public static TheoryData> SelectorMultiple => - new TheoryData> + new() { - { new int[] { 1, 2, 3, 4, 5 }, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => item.ToString() }, }; public static TheoryData> SkipTakeSelectorMultiple => - new TheoryData> + new() { - { new int[] { 1, 2, 3, 4, 5 }, -1, 2, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 2, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 2, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 5, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 5, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 3, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 9, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, -1, 2, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 2, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 2, 2, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, -1, 5, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 5, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 2, 3, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, -1, 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, item => item.ToString() }, }; public static TheoryData> SelectorAtMultiple => - new TheoryData> + new() { - { new int[] { 1, 2, 3, 4, 5 }, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, (item, index) => $"{item} {index}" }, }; public static TheoryData> SkipTakeSelectorAtMultiple => - new TheoryData> + new() { - { new int[] { 1, 2, 3, 4, 5 }, -1, 2, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 2, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 2, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 5, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 5, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 3, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 9, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, -1, 2, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 0, 2, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 2, 2, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, -1, 5, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 0, 5, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 2, 3, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, -1, 9, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (item, index) => $"{item} {index}" }, }; public static TheoryData, Func> PredicateSelectorMultiple => - new TheoryData, Func> + new() { - { new int[] { 1, 2, 3, 4, 5 }, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 0, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 0, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1, item => item.ToString() }, }; public static TheoryData, Func> SkipTakePredicateSelectorMultiple => - new TheoryData, Func> - { - { new int[] { 1, 2, 3, 4, 5 }, -1, 2, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 2, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 2, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 5, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 5, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 3, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 9, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, _ => true, item => item.ToString() }, - - { new int[] { 1, 2, 3, 4, 5 }, -1, 5, item => (item & 0x01) == 0, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 5, item => (item & 0x01) == 0, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 9, item => (item & 0x01) == 0, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => (item & 0x01) == 0, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 1, 9, item => (item & 0x01) == 0, item => item.ToString() }, - - { new int[] { 1, 2, 3, 4, 5 }, -1, 5, item => (item & 0x01) == 1, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 5, item => (item & 0x01) == 1, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 9, item => (item & 0x01) == 1, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => (item & 0x01) == 1, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 1, 9, item => (item & 0x01) == 1, item => item.ToString() }, + new() + { + { new[] { 1, 2, 3, 4, 5 }, -1, 2, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 2, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 2, 2, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, -1, 5, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 5, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 2, 3, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, -1, 9, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, _ => true, item => item.ToString() }, + + { new[] { 1, 2, 3, 4, 5 }, -1, 5, item => (item & 0x01) == 0, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 5, item => (item & 0x01) == 0, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, -1, 9, item => (item & 0x01) == 0, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => (item & 0x01) == 0, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 1, 9, item => (item & 0x01) == 0, item => item.ToString() }, + + { new[] { 1, 2, 3, 4, 5 }, -1, 5, item => (item & 0x01) == 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 5, item => (item & 0x01) == 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, -1, 9, item => (item & 0x01) == 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => (item & 0x01) == 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 1, 9, item => (item & 0x01) == 1, item => item.ToString() }, }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs index 8a8e234cf..5a6128766 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs @@ -6,196 +6,196 @@ namespace NetFabric.Hyperlinq public static partial class TestData { public static TheoryData Single => - new TheoryData + new() { - { new int[] { 1 } }, + { new[] { 1 } }, }; public static TheoryData SkipSingle => - new TheoryData + new() { - { new int[] { 1 }, -1 }, - { new int[] { 1 }, 0 }, + { new[] { 1 }, -1 }, + { new[] { 1 }, 0 }, - { new int[] { 0, 1, 2 }, 2 }, + { new[] { 0, 1, 2 }, 2 }, }; public static TheoryData TakeSingle => - new TheoryData + new() { - { new int[] { 1 }, 1 }, + { new[] { 1 }, 1 }, - { new int[] { 1, 2, 3, 4, 5 }, 1 }, + { new[] { 1, 2, 3, 4, 5 }, 1 }, }; public static TheoryData SkipTakeSingle => - new TheoryData + new() { - { new int[] { 1 }, -1, 1 }, - { new int[] { 1 }, 0, 1 }, + { new[] { 1 }, -1, 1 }, + { new[] { 1 }, 0, 1 }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 1 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 1 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 1 }, - { new int[] { 1, 2, 3, 4, 5 }, 4, 1 }, + { new[] { 1, 2, 3, 4, 5 }, -1, 1 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 1 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 1 }, + { new[] { 1, 2, 3, 4, 5 }, 4, 1 }, }; public static TheoryData> PredicateSingle => - new TheoryData> + new() { - { new int[] { 1 }, _ => true }, - { new int[] { 1 }, item => item == 1 }, + { new[] { 1 }, _ => true }, + { new[] { 1 }, item => item == 1 }, - { new int[] { 1, 2, 3, 4, 5 }, item => item == 1 }, - { new int[] { 1, 2, 3, 4, 5 }, item => item == 3 }, - { new int[] { 1, 2, 3, 4, 5 }, item => item == 5 }, + { new[] { 1, 2, 3, 4, 5 }, item => item == 1 }, + { new[] { 1, 2, 3, 4, 5 }, item => item == 3 }, + { new[] { 1, 2, 3, 4, 5 }, item => item == 5 }, }; public static TheoryData> SkipTakePredicateSingle => - new TheoryData> + new() { - { new int[] { 1 }, -1, 9, _ => true }, - { new int[] { 1 }, 0, 1, _ => true }, - { new int[] { 1 }, 0, 9, _ => true }, - { new int[] { 1 }, 0, 9, item => item == 1 }, + { new[] { 1 }, -1, 9, _ => true }, + { new[] { 1 }, 0, 1, _ => true }, + { new[] { 1 }, 0, 9, _ => true }, + { new[] { 1 }, 0, 9, item => item == 1 }, - { new int[] { 1, 2, 3, 4, 5 }, -1, 1, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 1, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 1, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 4, 1, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 1 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 3 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 5 }, + { new[] { 1, 2, 3, 4, 5 }, -1, 1, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 1, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 2, 1, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 4, 1, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 1 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 3 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 5 }, }; public static TheoryData, Func> PredicatePredicateSingle => - new TheoryData, Func> + new() { - { new int[] { 1 }, _ => true, _ => true }, + { new[] { 1 }, _ => true, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, item => item == 3, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, _ => true, item => item == 3 }, + { new[] { 1, 2, 3, 4, 5 }, item => item == 3, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, _ => true, item => item == 3 }, }; public static TheoryData, Func> SkipTakePredicatePredicateSingle => - new TheoryData, Func> + new() { - { new int[] { 1 }, 0, 9, _ => true, _ => true }, + { new[] { 1 }, 0, 9, _ => true, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 3, _ => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, item => item == 3 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 3, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, item => item == 3 }, }; public static TheoryData> PredicateAtSingle => - new TheoryData> + new() { - { new int[] { 1 }, (_, __) => true }, - { new int[] { 1 }, (item, _) => item == 1 }, - { new int[] { 1 }, (_, index) => index == 0 }, + { new[] { 1 }, (_, __) => true }, + { new[] { 1 }, (item, _) => item == 1 }, + { new[] { 1 }, (_, index) => index == 0 }, - { new int[] { 1, 2, 3, 4, 5 }, (item, _) => item == 1 }, - { new int[] { 1, 2, 3, 4, 5 }, (item, _) => item == 3 }, - { new int[] { 1, 2, 3, 4, 5 }, (item, _) => item == 5 }, - { new int[] { 1, 2, 3, 4, 5 }, (_, index) => index == 0 }, - { new int[] { 1, 2, 3, 4, 5 }, (_, index) => index == 2 }, - { new int[] { 1, 2, 3, 4, 5 }, (_, index) => index == 4 }, + { new[] { 1, 2, 3, 4, 5 }, (item, _) => item == 1 }, + { new[] { 1, 2, 3, 4, 5 }, (item, _) => item == 3 }, + { new[] { 1, 2, 3, 4, 5 }, (item, _) => item == 5 }, + { new[] { 1, 2, 3, 4, 5 }, (_, index) => index == 0 }, + { new[] { 1, 2, 3, 4, 5 }, (_, index) => index == 2 }, + { new[] { 1, 2, 3, 4, 5 }, (_, index) => index == 4 }, }; public static TheoryData> SkipTakePredicateAtSingle => - new TheoryData> - { - { new int[] { 1 }, -1, 1, (_, __) => true }, - { new int[] { 1 }, 0, 1, (_, __) => true }, - { new int[] { 1 }, 0, 1, (item, _) => item == 1 }, - { new int[] { 1 }, 0, 1, (_, index) => index == 0 }, - - { new int[] { 1 }, -1, 9, (_, __) => true }, - { new int[] { 1 }, 0, 9, (_, __) => true }, - { new int[] { 1 }, 0, 9, (item, _) => item == 1 }, - { new int[] { 1 }, 0, 9, (_, index) => index == 0 }, - - { new int[] { 1, 2, 3, 4, 5 }, -1, 1, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 1, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 1, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 4, 1, (_, __) => true }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (item, _) => item == 1 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (item, _) => item == 3 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (item, _) => item == 5 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index == 0 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index == 2 }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index == 4 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index == 0 }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index == 2 }, + new() + { + { new[] { 1 }, -1, 1, (_, __) => true }, + { new[] { 1 }, 0, 1, (_, __) => true }, + { new[] { 1 }, 0, 1, (item, _) => item == 1 }, + { new[] { 1 }, 0, 1, (_, index) => index == 0 }, + + { new[] { 1 }, -1, 9, (_, __) => true }, + { new[] { 1 }, 0, 9, (_, __) => true }, + { new[] { 1 }, 0, 9, (item, _) => item == 1 }, + { new[] { 1 }, 0, 9, (_, index) => index == 0 }, + + { new[] { 1, 2, 3, 4, 5 }, -1, 1, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 1, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 2, 1, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 4, 1, (_, __) => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (item, _) => item == 1 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (item, _) => item == 3 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (item, _) => item == 5 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index == 0 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index == 2 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index == 4 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index == 0 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index == 2 }, }; public static TheoryData> SelectorSingle => - new TheoryData> + new() { - { new int[] { 1 }, item => item.ToString() }, + { new[] { 1 }, item => item.ToString() }, }; public static TheoryData> SkipTakeSelectorSingle => - new TheoryData> + new() { - { new int[] { 1 }, 0, 1, item => item.ToString() }, + { new[] { 1 }, 0, 1, item => item.ToString() }, - { new int[] { 1 }, -1, 9, item => item.ToString() }, - { new int[] { 1 }, 0, 9, item => item.ToString() }, + { new[] { 1 }, -1, 9, item => item.ToString() }, + { new[] { 1 }, 0, 9, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 1, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 1, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 4, 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 2, 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 4, 1, item => item.ToString() }, }; public static TheoryData> SelectorAtSingle => - new TheoryData> + new() { - { new int[] { 1 }, (item, index) => $"{item} {index}" }, + { new[] { 1 }, (item, index) => $"{item} {index}" }, }; public static TheoryData> SkipTakeSelectorAtSingle => - new TheoryData> + new() { - { new int[] { 1 }, -1, 1, (item, index) => $"{item} {index}" }, - { new int[] { 1 }, 0, 1, (item, index) => $"{item} {index}" }, + { new[] { 1 }, -1, 1, (item, index) => $"{item} {index}" }, + { new[] { 1 }, 0, 1, (item, index) => $"{item} {index}" }, - { new int[] { 1 }, -1, 9, (item, index) => $"{item} {index}" }, - { new int[] { 1 }, 0, 9, (item, index) => $"{item} {index}" }, + { new[] { 1 }, -1, 9, (item, index) => $"{item} {index}" }, + { new[] { 1 }, 0, 9, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 1, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 1, (item, index) => $"{item} {index}" }, - { new int[] { 1, 2, 3, 4, 5 }, 4, 1, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 0, 1, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 2, 1, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 4, 1, (item, index) => $"{item} {index}" }, }; public static TheoryData, Func> PredicateSelectorSingle => - new TheoryData, Func> + new() { - { new int[] { 1 }, _ => true, item => item.ToString() }, - { new int[] { 1 }, item => item == 1, item => item.ToString() }, + { new[] { 1 }, _ => true, item => item.ToString() }, + { new[] { 1 }, item => item == 1, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, item => item == 1, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, item => item == 3, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, item => item == 5, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => item == 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => item == 3, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => item == 5, item => item.ToString() }, }; public static TheoryData, Func> SkipTakePredicateSelectorSingle => - new TheoryData, Func> - { - { new int[] { 1 }, -1, 1, _ => true, item => item.ToString() }, - { new int[] { 1 }, 0, 1, _ => true, item => item.ToString() }, - { new int[] { 1 }, 0, 1, item => item == 1, item => item.ToString() }, - - { new int[] { 1 }, -1, 9, _ => true, item => item.ToString() }, - { new int[] { 1 }, 0, 9, _ => true, item => item.ToString() }, - { new int[] { 1 }, 0, 9, item => item == 1, item => item.ToString() }, - - { new int[] { 1, 2, 3, 4, 5 }, -1, 1, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 1, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 2, 1, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 4, 1, _ => true, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 1, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 3, item => item.ToString() }, - { new int[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 5, item => item.ToString() }, + new() + { + { new[] { 1 }, -1, 1, _ => true, item => item.ToString() }, + { new[] { 1 }, 0, 1, _ => true, item => item.ToString() }, + { new[] { 1 }, 0, 1, item => item == 1, item => item.ToString() }, + + { new[] { 1 }, -1, 9, _ => true, item => item.ToString() }, + { new[] { 1 }, 0, 9, _ => true, item => item.ToString() }, + { new[] { 1 }, 0, 9, item => item == 1, item => item.ToString() }, + + { new[] { 1, 2, 3, 4, 5 }, -1, 1, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 1, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 2, 1, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 4, 1, _ => true, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 3, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 5, item => item.ToString() }, }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs b/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs index 6a1b2cdaa..35bd6a456 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs @@ -6,36 +6,57 @@ namespace NetFabric.Hyperlinq.UnitTests { static class SpanExtensions { - public static bool SequenceEqual(this IMemoryOwner first, IEnumerable second, IEqualityComparer comparer = null) + public static bool SequenceEqual(this IMemoryOwner first, IEnumerable second, IEqualityComparer? comparer = default) => SequenceEqual((ReadOnlySpan)first.Memory.Span, second, comparer); - public static bool SequenceEqual(this Memory first, IEnumerable second, IEqualityComparer comparer = null) + public static bool SequenceEqual(this Memory first, IEnumerable second, IEqualityComparer? comparer = default) => SequenceEqual((ReadOnlySpan)first.Span, second, comparer); - public static bool SequenceEqual(this ReadOnlyMemory first, IEnumerable second, IEqualityComparer comparer = null) + public static bool SequenceEqual(this ReadOnlyMemory first, IEnumerable second, IEqualityComparer? comparer = default) => SequenceEqual(first.Span, second, comparer); - public static bool SequenceEqual(this Span first, IEnumerable second, IEqualityComparer comparer = null) + public static bool SequenceEqual(this Span first, IEnumerable second, IEqualityComparer? comparer = default) => SequenceEqual((ReadOnlySpan)first, second, comparer); - public static bool SequenceEqual(this ReadOnlySpan first, IEnumerable second, IEqualityComparer comparer = null) + public static bool SequenceEqual(this ReadOnlySpan first, IEnumerable second, IEqualityComparer? comparer = default) { - comparer ??= EqualityComparer.Default; + if (Utils.UseDefault(comparer)) + { + using var enumerator = second.GetEnumerator(); + for (var index = 0; true; index++) + { + var resultEnded = index == first.Length; + var expectedEnded = !enumerator.MoveNext(); + + if (resultEnded != expectedEnded) + return false; + + if (resultEnded) + return true; - using var enumerator = second.GetEnumerator(); - for (var index = 0; true; index++) + if (!EqualityComparer.Default.Equals(first[index], enumerator.Current)) + return false; + } + } + else { - var resultEnded = index == first.Length; - var expectedEnded = !enumerator.MoveNext(); + comparer ??= EqualityComparer.Default; + + using var enumerator = second.GetEnumerator(); + for (var index = 0; true; index++) + { + var resultEnded = index == first.Length; + var expectedEnded = !enumerator.MoveNext(); - if (resultEnded != expectedEnded) - return false; + if (resultEnded != expectedEnded) + return false; - if (resultEnded) - return true; + if (resultEnded) + return true; - if (!comparer.Equals(first[index], enumerator.Current)) - return false; + if (!comparer.Equals(first[index], enumerator.Current)) + return false; + } } } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index 5849568db..c6d25858e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -38,7 +38,7 @@ public readonly TSource this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if ((uint)index >= (uint)source.Count) Throw.IndexOutOfRangeException(); + if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); return source.Array![source.Offset + index]; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index 101c0702a..291020b0a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -312,7 +312,7 @@ public bool AnyAt(TPredicate predicate) => source.Span.AnyAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer = null) + public bool Contains(TSource value, IEqualityComparer? comparer = default) => source.Span.Contains(value, comparer); #endregion @@ -325,7 +325,7 @@ public MemoryDistinctEnumerable Distinct(IEqualityComparer? co #endregion - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; @@ -350,7 +350,7 @@ public bool SequenceEqual(IEnumerable other, IEqualityComparer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this MemoryValueEnumerable source) - => source.source.Span.Count(); + => source.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemoryValueEnumerable source) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index dd9b1b778..98868a4c0 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -256,7 +256,7 @@ public bool SequenceEqual(IEnumerable other, IEqualityComparer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this SpanValueEnumerable source) - => source.source.Count(); + => source.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SpanValueEnumerable source) diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs index c83d06289..7eb60a283 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs @@ -7,11 +7,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - static Dictionary ToDictionary(this ReadOnlySpan source, Func keySelector, IEqualityComparer? comparer = null) + static Dictionary ToDictionary(this ReadOnlySpan source, Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull => source.ToDictionary(new FunctionWrapper(keySelector), comparer); - static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer = null) + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction { @@ -75,11 +75,11 @@ static Dictionary ToDictionary ToDictionary(this ReadOnlySpan source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = null) + static Dictionary ToDictionary(this ReadOnlySpan source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) where TKey : notnull => source.ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = null) + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction where TElementSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs index 8bd23b0a6..29d8eb9cb 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs @@ -13,7 +13,7 @@ public static partial class AsyncValueEnumerableExtensions public static ValueTask> ToDictionaryAsync( this TEnumerable source, Func> keySelector, - IEqualityComparer? comparer = null, + IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -23,7 +23,7 @@ public static ValueTask> ToDictionaryAsync> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, - IEqualityComparer? comparer = null, + IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -174,7 +174,7 @@ public static ValueTask> ToDictionaryAsync> keySelector, Func> elementSelector, - IEqualityComparer? comparer = null, + IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -185,7 +185,7 @@ public static ValueTask> ToDictionaryAsync? comparer = null, + IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs index 33acafd38..efdf0da8f 100644 --- a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs @@ -5,7 +5,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - public static bool SequenceEqual(this ReadOnlySpan first, TEnumerable second, IEqualityComparer? comparer = null) + public static bool SequenceEqual(this ReadOnlySpan first, TEnumerable second, IEqualityComparer? comparer = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { @@ -28,7 +28,7 @@ public static bool SequenceEqual(this ReadOnl } } - //public static bool SequenceEqual(this ReadOnlySpan first, TEnumerable second, IEqualityComparer? comparer = null) + //public static bool SequenceEqual(this ReadOnlySpan first, TEnumerable second, IEqualityComparer? comparer = default) // where TEnumerable : IValueReadOnlyList // where TEnumerator : struct, IEnumerator //{ diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index 9bc2af7eb..0c65025a5 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -223,7 +223,7 @@ public Dictionary ToDictionary other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index 7f6319e36..76b299555 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -169,7 +169,7 @@ public Dictionary ToDictionary other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index 72cb4e50f..29a558be8 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -214,7 +214,7 @@ public Dictionary ToDictionaryAt other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index 65997a6c8..0c59826d2 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -160,7 +160,7 @@ public Dictionary ToDictionary other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index 671fe619c..723d0c1be 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -249,7 +249,7 @@ public Dictionary ToDictionary other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index 09dd074f7..dbd725365 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -125,7 +125,7 @@ public Dictionary ToDictionary other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs index 47528d3f1..fd5f6de8e 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs @@ -23,7 +23,7 @@ public TSource this[int index] => Throw.IndexOutOfRangeException(); TSource IList.this[int index] { - get => this[index]; + get => Throw.IndexOutOfRangeException(); [ExcludeFromCodeCoverage] // ReSharper disable once ValueParameterNotUsed diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs index 842a5fb42..9aa6bfa2f 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs @@ -30,12 +30,11 @@ public readonly int Count public readonly TSource this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get + get => index switch { - if (index is not 0) Throw.IndexOutOfRangeException(); - - return value; - } + 0 => value, + _ => Throw.IndexOutOfRangeException() + }; } TSource IReadOnlyList.this[int index] => this[index]; diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index fd1e8c2ae..55de6ce7c 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -34,14 +34,17 @@ internal ArraySegmentSelectEnumerable(in ArraySegment source, TSelector => (this.source, this.selector) = (source, selector); public readonly int Count - => source.Count; + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source.Count; + } public TResult this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (index < 0 || index >= source.Count) Throw.IndexOutOfRangeException(); + if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); return selector.Invoke(source.Array![index + source.Offset]); } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index 76fed7f4f..e72097bd4 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -210,7 +210,7 @@ public List ToList() #endregion - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index b5c18276c..7b9caf95e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -109,7 +109,7 @@ public List ToList() #endregion - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 9d1b553dc..877c9f621 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -37,14 +37,17 @@ internal ArraySegmentSelectAtEnumerable(in ArraySegment source, TSelect } public readonly int Count - => source.Count; + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source.Count; + } public TResult this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (index < 0 || index >= source.Count) Throw.IndexOutOfRangeException(); + if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); return selector.Invoke(source.Array![index + source.Offset], index); } @@ -210,7 +213,7 @@ public List ToList() #endregion - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 0fc489393..e3ef90e72 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -204,7 +204,7 @@ public List ToList() #endregion - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index 61acaa5e4..e1a1903cc 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -109,7 +109,7 @@ public List ToList() #endregion - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs index 102ec24a1..a897b04b0 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs @@ -41,7 +41,6 @@ public partial struct RangeSelectVectorEnumerable count; + public readonly int Count { get; } public TResult this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (index < 0 || index >= count) Throw.IndexOutOfRangeException(); + if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); return selector.Invoke(start + index); } @@ -96,10 +94,10 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { - if (span.Length < count) + if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - ArrayExtensions.CopyRange(start, count, span, vectorSelector, selector); + ArrayExtensions.CopyRange(start, Count, span, vectorSelector, selector); } void ICollection.CopyTo(TResult[] array, int arrayIndex) @@ -112,12 +110,12 @@ void ICollection.Clear() public unsafe bool Contains(TResult item) { - if (count is 0) + if (Count is 0) return false; var index = 0; - if (Vector.IsHardwareAccelerated && count > Vector.Count * 2) + if (Vector.IsHardwareAccelerated && Count > Vector.Count * 2) { var seed = stackalloc int[Vector.Count]; if (start is 0) @@ -138,7 +136,7 @@ public unsafe bool Contains(TResult item) var vectorIncrement = new Vector(Vector.Count); vector += vectorIncrement; - for (index = 0; index < count - Vector.Count; index += Vector.Count) + for (index = 0; index < Count - Vector.Count; index += Vector.Count) { if (Vector.EqualsAny(vectorSelector.Invoke(vector), vectorItem)) return true; @@ -147,7 +145,7 @@ public unsafe bool Contains(TResult item) } } - var end = start + count; + var end = start + Count; for (var value = index + start; value < end; value++) { if (GenericsOperator.Equals(selector.Invoke(value), item)) @@ -161,7 +159,7 @@ bool ICollection.Remove(TResult item) => Throw.NotSupportedException(); int IList.IndexOf(TResult item) { - var end = start + count; + var end = start + Count; for (var value = start; value < end; value++) { if (EqualityComparer.Default.Equals(selector.Invoke(value), item)) @@ -186,7 +184,7 @@ internal Enumerator(in RangeSelectVectorEnumerable count is not 0; + => Count is not 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TResult value, IEqualityComparer? comparer) @@ -268,29 +266,30 @@ public bool Contains(TResult value, IEqualityComparer? comparer) public TResult[] ToArray() { - var result = Utils.AllocateUninitializedArray(count); - ArrayExtensions.CopyRange(start, count, result.AsSpan(), vectorSelector, selector); + var result = Utils.AllocateUninitializedArray(Count); + ArrayExtensions.CopyRange(start, Count, result.AsSpan(), vectorSelector, selector); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) { - var result = pool.RentSliced(count); - ArrayExtensions.CopyRange(start, count, result.Memory.Span, vectorSelector, selector); + var result = pool.RentSliced(Count); + ArrayExtensions.CopyRange(start, Count, result.Memory.Span, vectorSelector, selector); return result; } public List ToList() - => count switch + => Count switch { + // ReSharper disable once HeapView.ObjectAllocation.Evident 0 => new List(), _ => ToArray().AsList() }; #endregion - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; @@ -324,31 +323,31 @@ public static int Count(this RangeSelectVec public static int Sum(this RangeSelectVectorEnumerable source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.count, source.vectorSelector, source.selector); + => SumRange(source.start, source.Count, source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this RangeSelectVectorEnumerable source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.count, source.vectorSelector, source.selector); + => SumRange(source.start, source.Count, source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this RangeSelectVectorEnumerable source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.count, source.vectorSelector, source.selector); + => SumRange(source.start, source.Count, source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this RangeSelectVectorEnumerable source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.count, source.vectorSelector, source.selector); + => SumRange(source.start, source.Count, source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this RangeSelectVectorEnumerable source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.count, source.vectorSelector, source.selector); + => SumRange(source.start, source.Count, source.vectorSelector, source.selector); } } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs index 4d039a2b5..3f4ac1320 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -14,7 +14,7 @@ public static partial class ArrayExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryDistinctEnumerable Distinct( this ReadOnlyMemory source, - IEqualityComparer? comparer = null) + IEqualityComparer? comparer = default) => new(source, comparer); [StructLayout(LayoutKind.Auto)] @@ -128,7 +128,7 @@ public readonly List ToList() _ => GetSet().ToList() }; - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs index a84144c03..77b6027f1 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs @@ -12,7 +12,7 @@ public static partial class ArrayExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanDistinctEnumerable Distinct( this ReadOnlySpan source, - IEqualityComparer? comparer = null) + IEqualityComparer? comparer = default) => new(source, comparer); [StructLayout(LayoutKind.Auto)] @@ -112,7 +112,7 @@ public readonly List ToList() _ => GetSet().ToList() }; - public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) + public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; From 587aa01d476e02b10d06b2fa02cded041208f4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Sat, 13 Mar 2021 21:55:04 +0000 Subject: [PATCH 19/61] Add GeneratorBindingsAttribute (#348) --- .../NetFabric.Hyperlinq.Abstractions.csproj | 3 +- .../NetFabric.Hyperlinq.Immutable.csproj | 1 - .../CollectExtensionMethodsTests.cs | 28 +- .../GenerateSourceTests.cs | 90 +++--- ...Hyperlinq.SourceGenerator.UnitTests.csproj | 1 - .../TestData/Results/Dictionary.Select.cs | 2 + .../TestData/Results/Dictionary.Where.cs | 2 + .../Results/Distinct.ValueEnumerable.Where.cs | 3 + .../TestData/Results/Range.Count.cs | 1 + .../TestData/Results/Range.Select.cs | 2 + .../TestData/Results/Range.Where.cs | 2 + .../TestData/Results/Repeat.Count.cs | 1 + .../Results/Select.ArraySegment.Any.cs | 2 + .../Results/Select.ValueEnumerable.Any.cs | 3 + .../Results/Select.ValueEnumerable.First.cs | 1 + .../Results/Select.ValueEnumerable.Where.cs | 2 + .../Results/Where.ArraySegment.Count.cs | 1 + .../Results/Where.ValueEnumerable.Count.cs | 1 + .../Results/Where.ValueEnumerable.Distinct.cs | 1 + .../Results/Where.ValueEnumerable.First.cs | 1 + .../Results/Where.ValueEnumerable.Select.cs | 2 + .../Common/GeneratorMappingAttribute.cs | 17 -- .../TestData/Source/ExtensionMethods.cs | 12 +- .../TestData/Source/NoExtensionMethods.cs | 46 +-- .../TestData/Source/Select.ArraySegment.cs | 6 +- .../TestData/Source/Where.ArraySegment.cs | 6 +- .../Verifier.cs | 28 +- .../Attributes/GeneratorBindingsAttribute.cs | 31 +++ .../Attributes}/GeneratorIgnoreAttribute.cs | 3 +- .../Attributes}/GeneratorMappingAttribute.cs | 3 +- .../CompilationContext.cs | 31 +++ ...NetFabric.Hyperlinq.SourceGenerator.csproj | 5 +- .../OverloadsGenerator.cs | 194 ++++++++----- .../Utils/DictionarySet.cs | 37 +++ .../Utils/MethodSymbolExtensions.cs | 8 +- .../Utils/StringExtensions.cs | 40 ++- .../Utils/SymbolExtensions.cs | 75 ++++- .../Utils/TypeParameterSymbolExtensions.cs | 2 +- .../Utils/TypeSymbolExtensions.cs | 35 +-- ...ValueEnumerable.ValueReadOnlyList.Tests.cs | 129 +-------- .../Utils/Wrappers/Wrap.AsValueList.cs | 2 +- .../Wrappers/Wrap.AsValueReadOnlyList.cs | 2 +- .../Aggregation/Count/Count.ReadOnlySpan.cs | 1 + .../Count/CountAsync.AsyncValueEnumerable.cs | 4 +- .../Sum/SumAsync.AsyncValueEnumerable.cs | 10 +- .../AsValueEnumerable'1.Enumerable.cs | 6 +- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 6 +- .../AsValueEnumerable'1.ValueEnumerable.cs | 7 +- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 7 +- .../AsValueEnumerable'6.Enumerable.cs | 5 +- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 5 +- .../AsValueEnumerable'6.ValueEnumerable.cs | 56 ++-- ...lueEnumerable'6.ValueReadOnlyCollection.cs | 6 +- .../AsValueEnumerable.Array.cs | 1 + .../AsValueEnumerable.ArraySegment.cs | 11 +- .../AsValueEnumerable.Memory.cs | 1 + .../AsValueEnumerable.ReadOnlyList.cs | 5 + .../AsValueEnumerable.ReadOnlyMemory.cs | 94 +------ .../AsValueEnumerable.ReadOnlySpan.cs | 93 +------ .../AsValueEnumerable.Span.cs | 1 + .../AsValueEnumerable.ValuesReadOnlyList.cs | 262 +----------------- .../ToArray/ToArray.ReadOnlyList.cs | 46 +-- .../ToArray/ToArray.ReadOnlySpan.cs | 53 ++-- .../ToArray/ToArray.ValueEnumerable.cs | 30 +- .../ToArray.ValueReadOnlyCollection.cs | 24 +- .../ToArrayAsync.AsyncValueEnumerable.cs | 40 +-- .../ToDictionary/ToDictionary.ReadOnlySpan.cs | 4 + .../ToDictionaryAsync.AsyncValueEnumerable.cs | 16 +- .../Conversion/ToList/ToList.ReadOnlySpan.cs | 1 + .../ToListAsync.AsyncValueEnumerable.cs | 20 +- .../ElementAt/ElementAt.ReadOnlySpan.cs | 3 +- .../ElementAtAsync.AsyncValueEnumerable.cs | 30 +- .../Element/First/First.ReadOnlySpan.cs | 3 +- .../First/FirstAsync.AsyncValueEnumerable.cs | 10 +- .../Element/Single/Single.ReadOnlySpan.cs | 1 + .../SingleAsync.AsyncValueEnumerable.cs | 20 +- .../SequenceEqual.ReadOnlySpan.cs | 2 +- .../Where/Where/Where.ArraySegment.cs | 4 +- .../Where/Where/Where.AsyncValueEnumerable.cs | 38 +-- .../Where/Where/Where.ReadOnlyList.cs | 2 +- .../Where/Where/Where.ReadOnlyMemory.cs | 6 +- .../Where/Where/Where.ReadOnlySpan.cs | 6 +- .../Where/Where/Where.ValueEnumerable.cs | 76 +---- .../Where/Where.ValueReadOnlyCollection.cs | 2 +- .../Where/WhereAt/WhereAt.ArraySegment.cs | 2 +- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 38 +-- .../Where/WhereAt/WhereAt.ReadOnlyList.cs | 2 +- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 6 +- .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 2 +- .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 2 +- .../WhereAt.ValueReadOnlyCollection.cs | 2 +- .../WhereSelect/WhereSelect.ArraySegment.cs | 2 +- .../WhereSelect.AsyncValueEnumerable.cs | 34 +-- .../WhereSelect/WhereSelect.ReadOnlyList.cs | 2 +- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 2 +- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 2 +- .../WhereSelect.ValueEnumerable.cs | 2 +- .../WhereSelect.ValueReadOnlyCollection.cs | 2 +- .../NetFabric.Hyperlinq.csproj | 7 + .../Select/Select/Select.ArraySegment.cs | 2 +- .../Select/Select.AsyncValueEnumerable.cs | 32 +-- .../Select/Select/Select.ReadOnlyList.cs | 2 +- .../Select/Select/Select.ReadOnlyMemory.cs | 4 +- .../Select/Select/Select.ReadOnlySpan.cs | 4 +- .../Select/Select/Select.ValueEnumerable.cs | 2 +- .../Select/Select.ValueReadOnlyCollection.cs | 2 +- .../Select/SelectAt/SelectAt.ArraySegment.cs | 2 +- .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 32 +-- .../Select/SelectAt/SelectAt.ReadOnlyList.cs | 2 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 4 +- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 4 +- .../SelectAt/SelectAt.ValueEnumerable.cs | 2 +- .../SelectAt.ValueReadOnlyCollection.cs | 2 +- .../SelectVector/SelectVector.ReadOnlySpan.cs | 8 +- .../Quantifier/All/All.ReadOnlySpan.cs | 8 +- .../Quantifier/Any/Any.ReadOnlySpan.cs | 9 +- .../Quantifier/Any/Any.Span.cs | 32 --- .../Contains/Contains.ReadOnlyList.cs | 1 + .../Contains/Contains.ReadOnlySpan.cs | 1 + .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 3 +- .../Set/Distinct/Distinct.ReadOnlySpan.cs | 3 +- .../ToArrayBuilder.AsyncValueEnumerable.cs | 10 +- .../ToArrayBuilder.ReadOnlyList.cs | 6 +- .../ToArrayBuilder.ReadOnlySpan.cs | 6 +- .../ToArrayBuilder.ValueEnumerable.cs | 10 +- ...oArrayBuilderAsync.AsyncValueEnumerable.cs | 20 +- .../Generator/GeneratorIgnoreAttribute.cs | 15 - 127 files changed, 938 insertions(+), 1277 deletions(-) delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/GeneratorMappingAttribute.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorBindingsAttribute.cs rename {NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common => NetFabric.Hyperlinq.SourceGenerator/Attributes}/GeneratorIgnoreAttribute.cs (83%) rename {NetFabric.Hyperlinq/Utils/Generator => NetFabric.Hyperlinq.SourceGenerator/Attributes}/GeneratorMappingAttribute.cs (87%) create mode 100644 NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator/Utils/DictionarySet.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/Any/Any.Span.cs delete mode 100644 NetFabric.Hyperlinq/Utils/Generator/GeneratorIgnoreAttribute.cs diff --git a/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj b/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj index 8d49ed430..f2abf5f42 100644 --- a/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj +++ b/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj @@ -10,8 +10,7 @@ LICENSE netfabric, hyperlinq, abstractions, linq, enumeration, performance true - Added IFunctionIn and related interfaces. - enable + diff --git a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj index 7d32a6d02..6900f3537 100644 --- a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj +++ b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj @@ -10,7 +10,6 @@ LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance true - enable diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs index 6e6255b90..1bf2b271d 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs @@ -10,18 +10,19 @@ namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests public class CollectExtensionMethodsTests { public static TheoryData ExtensionMethods - => new TheoryData { - { new string[] { "TestData/Source/NoExtensionMethods.cs" }, 0 }, - { new string[] { "TestData/Source/Distinct.ArraySegment.cs" }, 0 }, - { new string[] { "TestData/Source/Where.ArraySegment.cs" }, 0 }, - { new string[] { "TestData/Source/Select.ArraySegment.cs" }, 0 }, + => new() + { + { new[] { "TestData/Source/NoExtensionMethods.cs" }, 0 }, + { new[] { "TestData/Source/ExtensionMethods.cs" }, 3 }, - { new string[] { "TestData/Source/ExtensionMethods.cs" }, 1 }, - { new string[] { "TestData/Source/Count.ValueEnumerable.cs" }, 1 }, - { new string[] { "TestData/Source/Distinct.ValueEnumerable.cs" }, 1 }, + { new[] { "TestData/Source/Distinct.ArraySegment.cs" }, 1}, + { new[] { "TestData/Source/Count.ValueEnumerable.cs" }, 1 }, + { new[] { "TestData/Source/Distinct.ValueEnumerable.cs" }, 1 }, - { new string[] { "TestData/Source/Where.ValueEnumerable.cs" }, 2 }, - { new string[] { "TestData/Source/Select.ValueEnumerable.cs" }, 2 }, + { new[] { "TestData/Source/Where.ArraySegment.cs" }, 2 }, + { new[] { "TestData/Source/Select.ArraySegment.cs" }, 2 }, + { new[] { "TestData/Source/Where.ValueEnumerable.cs" }, 2 }, + { new[] { "TestData/Source/Select.ValueEnumerable.cs" }, 2 }, }; [Theory] @@ -33,14 +34,15 @@ public async Task ShouldCollectExpectedNumberOfExtensionMethods(string[] paths, var project = Verifier.CreateProject( paths .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) + .Concat(Directory.EnumerateFiles("../../../../NetFabric.Hyperlinq.SourceGenerator/Attributes/", "*.cs", SearchOption.AllDirectories)) .Select(path => File.ReadAllText(path))); - var compilation = await project.GetCompilationAsync().ConfigureAwait(false); + var context = new CompilationContext(await project.GetCompilationAsync().ConfigureAwait(false) ?? throw new System.Exception("Error getting compilation!")); // Act - var result = generator.CollectExtensionMethods(compilation!); + var result = generator.CollectExtensionMethods(context); // Assert - _ = result.Values.SelectMany(item => item).Count().Must() + _ = result.Count.Must() .BeEqualTo(expected); } } diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs index 4ca6cd257..c90719d02 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs @@ -10,14 +10,15 @@ namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests public class GenerateSourceTests { public static TheoryData ClassesWithOverloads - => new TheoryData { - new string[] { + => new() + { + new[] { "TestData/Source/Count.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Source/Where.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Source/Select.ValueEnumerable.cs", }, }; @@ -31,12 +32,13 @@ public async Task ClassesWithOverloadsShouldNotGenerate(string[] paths) var project = Verifier.CreateProject( paths .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) + .Concat(Directory.EnumerateFiles("../../../../NetFabric.Hyperlinq.SourceGenerator/Attributes/", "*.cs", SearchOption.AllDirectories)) .Select(path => File.ReadAllText(path))); - var compilation = await project.GetCompilationAsync().ConfigureAwait(false); + var context = new CompilationContext(await project.GetCompilationAsync().ConfigureAwait(false) ?? throw new System.Exception("Error getting compilation!")); // Act - var extensionMethods = generator.CollectExtensionMethods(compilation!); - var result = generator.GenerateSource(compilation!, extensionMethods); + var extensionMethods = generator.CollectExtensionMethods(context); + var result = generator.GenerateSource(extensionMethods, context); // Assert _ = result.Must() @@ -47,9 +49,10 @@ public async Task ClassesWithOverloadsShouldNotGenerate(string[] paths) // ----------------------------------------------------- public static TheoryData GeneratorSources - => new TheoryData { + => new() + { { - new string[] { + new[] { "TestData/Source/Range.cs", "TestData/Source/Contains.ValueEnumerable.cs", }, @@ -57,7 +60,7 @@ public static TheoryData GeneratorSources } }, { - new string[] { + new[] { "TestData/Source/Select.ArraySegment.cs", "TestData/Source/Contains.ValueEnumerable.cs", }, @@ -65,52 +68,52 @@ public static TheoryData GeneratorSources } }, { - new string[] { + new[] { "TestData/Source/Range.cs", "TestData/Source/Count.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Range.Count.cs", } }, { - new string[] { + new[] { "TestData/Source/Repeat.cs", "TestData/Source/Count.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Repeat.Count.cs", } }, { - new string[] { + new[] { "TestData/Source/Range.cs", "TestData/Source/Where.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Range.Where.cs", } }, { - new string[] { + new[] { "TestData/Source/Range.cs", "TestData/Source/Select.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Range.Select.cs", } }, { - new string[] { + new[] { "TestData/Source/Count.ValueEnumerable.cs", "TestData/Source/Where.ArraySegment.cs", }, - new string[] { + new[] { "TestData/Results/Where.ArraySegment.Count.cs", } }, { - new string[] { + new[] { "TestData/Source/Any.ArraySegment.cs", "TestData/Source/Any.ReadOnlyList.cs", "TestData/Source/Any.ValueEnumerable.cs", @@ -121,91 +124,91 @@ public static TheoryData GeneratorSources } }, { - new string[] { + new[] { "TestData/Source/Any.ArraySegment.cs", "TestData/Source/Any.ReadOnlyList.cs", "TestData/Source/Any.ValueEnumerable.cs", "TestData/Source/Any.ValueReadOnlyCollection.cs", "TestData/Source/Select.ArraySegment.cs", }, - new string[] { + new[] { "TestData/Results/Select.ArraySegment.Any.cs", } }, { - new string[] { + new[] { "TestData/Source/Any.ArraySegment.cs", "TestData/Source/Any.ReadOnlyList.cs", "TestData/Source/Any.ValueEnumerable.cs", "TestData/Source/Any.ValueReadOnlyCollection.cs", "TestData/Source/Select.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Select.ValueEnumerable.Any.cs", } }, { - new string[] { + new[] { "TestData/Source/Count.ValueEnumerable.cs", "TestData/Source/Where.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Where.ValueEnumerable.Count.cs", } }, { - new string[] { + new[] { "TestData/Source/First.ValueEnumerable.cs", "TestData/Source/Where.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Where.ValueEnumerable.First.cs", } }, { - new string[] { + new[] { "TestData/Source/First.ValueEnumerable.cs", "TestData/Source/Select.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Select.ValueEnumerable.First.cs", } }, { - new string[] { + new[] { "TestData/Source/Where.ValueEnumerable.cs", "TestData/Source/Distinct.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Where.ValueEnumerable.Distinct.cs", "TestData/Results/Distinct.ValueEnumerable.Where.cs", } }, { - new string[] { + new[] { "TestData/Source/Where.ValueEnumerable.cs", "TestData/Source/Select.ValueEnumerable.cs", }, - new string[] { + new[] { "TestData/Results/Where.ValueEnumerable.Select.cs", "TestData/Results/Select.ValueEnumerable.Where.cs", } }, { - new string[] { + new[] { "TestData/Source/Where.ValueEnumerable.cs", "TestData/Source/Dictionary.Bindings.cs", }, - new string[] { + new[] { "TestData/Results/Dictionary.Where.cs", } }, { - new string[] { + new[] { "TestData/Source/Select.ValueEnumerable.cs", "TestData/Source/Dictionary.Bindings.cs", }, - new string[] { + new[] { "TestData/Results/Dictionary.Select.cs", } }, @@ -214,18 +217,19 @@ public static TheoryData GeneratorSources [Theory] [MemberData(nameof(GeneratorSources))] public async Task GenerateSourceShouldGenerate(string[] paths, string[] expected) - { + { // Arrange var generator = new OverloadsGenerator(); var project = Verifier.CreateProject( paths .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) + .Concat(Directory.EnumerateFiles("../../../../NetFabric.Hyperlinq.SourceGenerator/Attributes/", "*.cs", SearchOption.AllDirectories)) .Select(path => File.ReadAllText(path))); - var compilation = await project.GetCompilationAsync().ConfigureAwait(false); + var context = new CompilationContext(await project.GetCompilationAsync().ConfigureAwait(false) ?? throw new System.Exception("Error getting compilation!")); // Act - var extensionMethods = generator.CollectExtensionMethods(compilation!); - var result = generator.GenerateSource(compilation!, extensionMethods); + var extensionMethods = generator.CollectExtensionMethods(context); + var result = generator.GenerateSource(extensionMethods, context); // Assert _ = result.Select(item => item.Source) diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj index 59b3eb9fe..ce285556c 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj @@ -4,7 +4,6 @@ net5.0 false - enable diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs index ad5c7e588..00caa8d8c 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs @@ -12,11 +12,13 @@ public static partial class DictionaryBindings public partial struct ValueWrapper { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult, NetFabric.Hyperlinq.FunctionWrapper, TResult>> Select(System.Func, TResult> selector) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult>(this, selector); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult, TSelector> Select(TSelector selector = default) where TSelector : struct, NetFabric.Hyperlinq.IFunction, TResult> diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs index b0c43413d..1e44137c6 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs @@ -12,11 +12,13 @@ public static partial class DictionaryBindings public partial struct ValueWrapper { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, NetFabric.Hyperlinq.FunctionWrapper, bool>> Where(System.Func, bool> predicate) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair>(this, predicate); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, NetFabric.Hyperlinq.IFunction, bool> diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs index 4ad7f8437..85119f091 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs @@ -12,17 +12,20 @@ public static partial class ValueEnumerableExtensions public partial struct DistinctEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource, NetFabric.Hyperlinq.FunctionWrapper> Where(System.Func predicate) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource>(this, predicate); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, NetFabric.Hyperlinq.IFunction => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource, TPredicate>(this, predicate); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource> Distinct() => NetFabric.Hyperlinq.ValueEnumerableExtensions.Distinct, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource>(this); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs index 2e88d9b0c..cad14e728 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs @@ -11,6 +11,7 @@ public static partial class ValueEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this NetFabric.Hyperlinq.ValueEnumerable.RangeEnumerable source) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count(source); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs index a59fc2be7..87cf749f7 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs @@ -12,11 +12,13 @@ public static partial class ValueEnumerable public partial struct RangeEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable> Select(System.Func selector) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select(this, selector); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable Select(TSelector selector = default) where TSelector : struct, NetFabric.Hyperlinq.IFunction diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs index 7d6a65e34..14219e17f 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs @@ -12,11 +12,13 @@ public static partial class ValueEnumerable public partial struct RangeEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable> Where(System.Func predicate) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where(this, predicate); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable Where(TPredicate predicate = default) where TPredicate : struct, NetFabric.Hyperlinq.IFunction diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs index 1957b9a43..41ac35b3f 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs @@ -11,6 +11,7 @@ public static partial class ValueEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable source) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count, NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable.DisposableEnumerator, TSource>(source); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs index 3c386baf5..d0fc592f7 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs @@ -12,11 +12,13 @@ public static partial class ArrayExtensions public partial struct ArraySegmentSelectEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Any(System.Func predicate) => NetFabric.Hyperlinq.ReadOnlyListExtensions.Any, TResult>(this, predicate); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Any(TPredicate predicate = default) where TPredicate : struct, NetFabric.Hyperlinq.IFunction diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs index 1cb77b73d..76ba1132a 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs @@ -12,16 +12,19 @@ public static partial class ValueEnumerableExtensions public partial struct SelectEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Any() => NetFabric.Hyperlinq.ValueEnumerableExtensions.Any, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Any(System.Func predicate) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Any, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this, predicate); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Any(TPredicate predicate = default) where TPredicate : struct, NetFabric.Hyperlinq.IFunction diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs index aee9f5219..77c913be7 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs @@ -12,6 +12,7 @@ public static partial class ValueEnumerableExtensions public partial struct SelectEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.Option First() => NetFabric.Hyperlinq.ValueEnumerableExtensions.First, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs index e688b8599..6c9ed4726 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs @@ -12,11 +12,13 @@ public static partial class ValueEnumerableExtensions public partial struct SelectEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, NetFabric.Hyperlinq.FunctionWrapper> Where(System.Func predicate) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this, predicate); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, NetFabric.Hyperlinq.IFunction diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs index 2f20d750a..444845022 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs @@ -12,6 +12,7 @@ public static partial class ArrayExtensions public partial struct ArraySegmentWhereEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly int Count() => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentWhereEnumerable.DisposableEnumerator, TSource>(this); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs index ab03bd3f1..a68c8d6da 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs @@ -12,6 +12,7 @@ public static partial class ValueEnumerableExtensions public partial struct WhereEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly int Count() => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource>(this); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs index ecf3034cb..6f5f15c16 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs @@ -12,6 +12,7 @@ public static partial class ValueEnumerableExtensions public partial struct WhereEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource> Distinct() => NetFabric.Hyperlinq.ValueEnumerableExtensions.Distinct, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource>(this); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs index 3712ad11c..8b13b25f7 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs @@ -12,6 +12,7 @@ public static partial class ValueEnumerableExtensions public partial struct WhereEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.Option First() => NetFabric.Hyperlinq.ValueEnumerableExtensions.First, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource>(this); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs index 091ba4c12..c9b3e7b9b 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs @@ -12,11 +12,13 @@ public static partial class ValueEnumerableExtensions public partial struct WhereEnumerable { [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult, NetFabric.Hyperlinq.FunctionWrapper> Select(System.Func selector) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult>(this, selector); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] + [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) where TSelector : struct, NetFabric.Hyperlinq.IFunction diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/GeneratorMappingAttribute.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/GeneratorMappingAttribute.cs deleted file mode 100644 index 662fc83f5..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/GeneratorMappingAttribute.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; - -namespace NetFabric.Hyperlinq -{ - [ExcludeFromCodeCoverage] - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method, AllowMultiple = true)] - public sealed class GeneratorMappingAttribute : Attribute - { - public string From { get; } - public string To { get; } - public bool IsConcreteType { get; } - - public GeneratorMappingAttribute(string from, string to, bool isConcreteType = false) - => (From, To, IsConcreteType) = (from, to , isConcreteType); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs index 55bca4934..1f4fdfdab 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs @@ -5,8 +5,16 @@ namespace NetFabric.Hyperlinq { public static class ExtensionMethods { - public static void ExtensionMethod(this TEnumerable _) - where TEnumerable : IEnumerable + public static void NotConstrainedExtensionMethod(this ArraySegment _) { } + + [GeneratorIgnore(false)] + static void NotIgnoredExtensionMethod(this TEnumerable _) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + { } + + public static void PublicExtensionMethod(this TEnumerable _) + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { } } diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs index 2fa47b425..9b7e6861a 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs @@ -3,35 +3,37 @@ namespace NetFabric.Hyperlinq { - public class NotStaticClass - { - } + //public class NotStaticClass + //{ + // public void Method(TEnumerable _) + // where TEnumerable : IValueEnumerable + // where TEnumerator : struct, IEnumerator + // { } + //} - static class NotPublicStaticClass - { - public static void ExtensionMethod(this TEnumerable _) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - { } - } + //static class NotPublicStaticClass + //{ + // public static void ExtensionMethod(this TEnumerable _) + // where TEnumerable : IValueEnumerable + // where TEnumerator : struct, IEnumerator + // { } + //} public static class NoExtensionMethods { - public static void NotConstrainedExtensionMethod(this ArraySegment _) { } - - public static void NotExtensionMethod(TEnumerable _) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - { } - - static void NotPublicExtensionMethod(this TEnumerable _) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - { } + //public static void NotExtensionMethod(TEnumerable _) + // where TEnumerable : IValueEnumerable + // where TEnumerator : struct, IEnumerator + //{ } + + //static void NotPublicExtensionMethod(this TEnumerable _) + // where TEnumerable : IValueEnumerable + // where TEnumerator : struct, IEnumerator + //{ } [GeneratorIgnore] public static void IgnoredExtensionMethod(this TEnumerable _) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { } } diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs index 8f8a25337..1bf08457f 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs @@ -7,11 +7,13 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - public static ArraySegmentSelectEnumerable> Select(this in ArraySegment source, Func selector) + static ArraySegmentSelectEnumerable> Select(this in ArraySegment source, Func selector) => Select>(source, new FunctionWrapper(selector)); - public static ArraySegmentSelectEnumerable Select(this in ArraySegment source, TSelector selector = default) + [GeneratorIgnore(false)] + static ArraySegmentSelectEnumerable Select(this in ArraySegment source, TSelector selector = default) where TSelector : struct, IFunction => new(source, selector); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs index cbd69ba77..db226e601 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs @@ -6,11 +6,13 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - public static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) + static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) => Where(source, new FunctionWrapper(predicate)); - public static ArraySegmentWhereEnumerable Where(this in ArraySegment source, TPredicate predicate = default) + [GeneratorIgnore(false)] + static ArraySegmentWhereEnumerable Where(this in ArraySegment source, TPredicate predicate = default) where TPredicate : struct, IFunction => new(source, predicate); diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs index 1598e66b1..a22381d28 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs @@ -6,32 +6,32 @@ namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests { - class Verifier + sealed class Verifier { - static readonly MetadataReference CorlibReference = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); - static readonly MetadataReference SystemCoreReference = MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location); - static readonly MetadataReference CSharpSymbolsReference = MetadataReference.CreateFromFile(typeof(CSharpCompilation).Assembly.Location); - static readonly MetadataReference CodeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location); + static readonly MetadataReference corlibReference = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); + static readonly MetadataReference systemCoreReference = MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location); + static readonly MetadataReference cSharpSymbolsReference = MetadataReference.CreateFromFile(typeof(CSharpCompilation).Assembly.Location); + static readonly MetadataReference codeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location); - static string DefaultFilePathPrefix = "Test"; - static string TestProjectName = "TestProject"; + static readonly string defaultFilePathPrefix = "Test"; + static readonly string testProjectName = "TestProject"; public static Project CreateProject(IEnumerable sources) { - var projectId = ProjectId.CreateNewId(debugName: TestProjectName); + var projectId = ProjectId.CreateNewId(debugName: testProjectName); var solution = new AdhocWorkspace() .CurrentSolution - .AddProject(projectId, TestProjectName, TestProjectName, LanguageNames.CSharp) - .AddMetadataReference(projectId, CorlibReference) - .AddMetadataReference(projectId, SystemCoreReference) - .AddMetadataReference(projectId, CSharpSymbolsReference) - .AddMetadataReference(projectId, CodeAnalysisReference); + .AddProject(projectId, testProjectName, testProjectName, LanguageNames.CSharp) + .AddMetadataReference(projectId, corlibReference) + .AddMetadataReference(projectId, systemCoreReference) + .AddMetadataReference(projectId, cSharpSymbolsReference) + .AddMetadataReference(projectId, codeAnalysisReference); var count = 0; foreach (var source in sources) { - var newFileName = DefaultFilePathPrefix + count + ".cs"; + var newFileName = defaultFilePathPrefix + count + ".cs"; var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName); solution = solution.AddDocument(documentId, newFileName, SourceText.From(source)); count++; diff --git a/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorBindingsAttribute.cs b/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorBindingsAttribute.cs new file mode 100644 index 000000000..65a9076f5 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorBindingsAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace NetFabric.Hyperlinq +{ + [ExcludeFromCodeCoverage] + [AttributeUsage(AttributeTargets.Struct)] + public sealed class GeneratorBindingsAttribute + : Attribute + { + public string Source { get; } + public string ElementType { get; } + public string? SourceImplements { get; } + public string? EnumerableType { get; } + public string? EnumeratorType { get; } + public string? ExtraTypeParameters { get; } + public string? ExtraParameters { get; } + + public GeneratorBindingsAttribute( + string source = "this", + string elementType = "TSource", + string? sourceImplements = default, + string? enumerableType = default, + string? enumeratorType = default, + string? extraTypeParameters = default, + string? extraParameters = default + ) + => (Source, ElementType, SourceImplements, EnumerableType, EnumeratorType, ExtraTypeParameters, ExtraParameters) + = (source, elementType, sourceImplements, enumerableType, enumeratorType, extraTypeParameters, extraParameters); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/GeneratorIgnoreAttribute.cs b/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorIgnoreAttribute.cs similarity index 83% rename from NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/GeneratorIgnoreAttribute.cs rename to NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorIgnoreAttribute.cs index d7e78203d..5a6e3ac40 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/GeneratorIgnoreAttribute.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorIgnoreAttribute.cs @@ -5,7 +5,8 @@ namespace NetFabric.Hyperlinq { [ExcludeFromCodeCoverage] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method)] - public sealed class GeneratorIgnoreAttribute : Attribute + public sealed class GeneratorIgnoreAttribute + : Attribute { public bool Value { get; } diff --git a/NetFabric.Hyperlinq/Utils/Generator/GeneratorMappingAttribute.cs b/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorMappingAttribute.cs similarity index 87% rename from NetFabric.Hyperlinq/Utils/Generator/GeneratorMappingAttribute.cs rename to NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorMappingAttribute.cs index e17af8931..5c76a2336 100644 --- a/NetFabric.Hyperlinq/Utils/Generator/GeneratorMappingAttribute.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorMappingAttribute.cs @@ -5,7 +5,8 @@ namespace NetFabric.Hyperlinq { [ExcludeFromCodeCoverage] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method, AllowMultiple = true)] - public sealed class GeneratorMappingAttribute : Attribute + public sealed class GeneratorMappingAttribute + : Attribute { public string From { get; } public string To { get; } diff --git a/NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs b/NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs new file mode 100644 index 000000000..7dedf96f5 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs @@ -0,0 +1,31 @@ +using Microsoft.CodeAnalysis; +using System; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + sealed class CompilationContext + { + public Compilation Compilation { get; } + public string GeneratedCodeAttribute { get; } + public INamedTypeSymbol GeneratorIgnoreAttribute { get; } + public INamedTypeSymbol GeneratorBindingsAttribute { get; } + public INamedTypeSymbol GeneratorMappingAttribute { get; } + + public CompilationContext(Compilation compilation) + { + Compilation = compilation; + + var generatorAssembly = GetType().Assembly; + var generatorAssemblyName = generatorAssembly.GetName().Name; + var generatorAssemblyVersion = AttributeExtensions.GetCustomAttribute(generatorAssembly)?.InformationalVersion ?? string.Empty; + GeneratedCodeAttribute = $"[GeneratedCode(\"{generatorAssemblyName}\", \"{generatorAssemblyVersion}\")]"; + + GeneratorIgnoreAttribute = compilation.GetTypeByMetadataName(typeof(GeneratorIgnoreAttribute).FullName) + ?? throw new Exception("GeneratorIgnoreAttribute symbol not found!"); + GeneratorBindingsAttribute = compilation.GetTypeByMetadataName(typeof(GeneratorBindingsAttribute).FullName) + ?? throw new Exception("GeneratorBindingsAttribute symbol not found!"); + GeneratorMappingAttribute = compilation.GetTypeByMetadataName(typeof(GeneratorMappingAttribute).FullName) + ?? throw new Exception("GeneratorMappingAttribute symbol not found!"); + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj index 986ef8b40..89eecd2a8 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj @@ -3,7 +3,6 @@ netstandard2.0 preview - enable true @@ -14,6 +13,10 @@ + + all + runtime; build; native; contentfiles; analyzers + diff --git a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs index 47a4bfa06..b3b674711 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs @@ -1,27 +1,28 @@ using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; -using System.IO; using System.Linq; using System.Text; namespace NetFabric.Hyperlinq.SourceGenerator { [Generator] - public class OverloadsGenerator: ISourceGenerator + public class OverloadsGenerator + : ISourceGenerator { static readonly DiagnosticDescriptor unhandledExceptionError = new( id: "HPLG001", - title: "Unhandled exception while generating oveloads", - messageFormat: "Unhandled exception while generating oveloads: {0}", + title: "Unhandled exception while generating overloads", + messageFormat: "Unhandled exception while generating overloads: {0}", category: "OverloadsGenerator", DiagnosticSeverity.Error, isEnabledByDefault: true); + public void Initialize(GeneratorInitializationContext context) { } @@ -30,12 +31,14 @@ public void Execute(GeneratorExecutionContext context) { //_ = Debugger.Launch(); // uncomment to debug this source generator + var compilationContext = new CompilationContext(context.Compilation); + try { - var collectedExtensionMethods = CollectExtensionMethods(context.Compilation); + var collectedExtensionMethods = CollectExtensionMethods(compilationContext); - var generatedSources = GenerateSource(context.Compilation, collectedExtensionMethods); - foreach ((var containerClass, var extendingType, var generatedSource) in generatedSources) + var generatedSources = GenerateSource(collectedExtensionMethods, compilationContext); + foreach (var (containerClass, extendingType, generatedSource) in generatedSources) { var hitName = $"{containerClass.OriginalDefinition.MetadataName}.{extendingType.OriginalDefinition.MetadataName}.g.cs"; hitName = hitName.Replace('`', '.'); @@ -49,17 +52,27 @@ public void Execute(GeneratorExecutionContext context) } } + bool ConsiderExtensionMethod(IMethodSymbol symbol, CompilationContext context) + { + var attribute = symbol.GetIgnoreAttribute(context); + return attribute switch + { + null => symbol.IsPublic(), + _ => !attribute.Value + }; + } + /// /// Collects all the extension methods defined /// /// /// A dictionary containing collections of the extension methods per type extended. - internal ImmutableDictionary> CollectExtensionMethods(Compilation compilation) + internal DictionarySet CollectExtensionMethods(CompilationContext context) { - var result = ImmutableDictionary.CreateBuilder>(); - + var collectedExtensionMethods = new DictionarySet(); + // go through all implemented static types and get all the extension methods implemented - var extensionMethods = compilation.SourceModule.GlobalNamespace + var extensionMethods = context.Compilation.SourceModule.GlobalNamespace .GetAllTypes() .Where(typeSymbol => typeSymbol.IsStatic @@ -68,9 +81,8 @@ internal ImmutableDictionary> CollectExtensionMethods(C typeSymbol.GetMembers() .OfType() .Where(methodSymbol => - methodSymbol.IsExtensionMethod - && methodSymbol.IsPublic() - && !methodSymbol.ShouldIgnore(compilation))); + methodSymbol.IsExtensionMethod + && ConsiderExtensionMethod(methodSymbol, context))); // go through all extension methods and store the ones where the extended type is a constrained generic parameter foreach (var extensionMethod in extensionMethods) @@ -80,21 +92,35 @@ internal ImmutableDictionary> CollectExtensionMethods(C .FirstOrDefault(typeParameter => typeParameter.ConstraintTypes.Length > 0 && typeParameter.Name == extensionType.Name); - if (generic is not null) + if (generic is null) { - var extendingType = generic.ConstraintTypes[0]; // assume it's the first constraint - var key = extendingType.OriginalDefinition.MetadataName; - if (!result.TryGetValue(key, out var list)) + var name = extensionMethod.Parameters[0].Type.OriginalDefinition.MetadataName; + switch (name) { - list = new List(); - result.Add(key, list); + case "ArraySegment`1": + case "ReadOnlySpan`1": + case "ReadOnlyMemory`1": + collectedExtensionMethods.Add(name, extensionMethod.GetInfo(context, 1)); + break; + } + } + else + { + var extendingType = generic.ConstraintTypes[0]; + var name = extendingType.OriginalDefinition.MetadataName; + switch (name) + { + case "IValueEnumerable`2": + case "IValueReadOnlyCollection`2": + case "IReadOnlyList`1": + case "IAsyncValueEnumerable`2": + collectedExtensionMethods.Add(name, extensionMethod.GetInfo(context, 1)); + break; } - var info = extensionMethod.GetInfo(compilation, 1); - list.Add(info); } } - return result.ToImmutable(); + return collectedExtensionMethods; } /// @@ -103,48 +129,49 @@ internal ImmutableDictionary> CollectExtensionMethods(C /// /// A dictionary containing the defined extension methods. /// The path where to serialize the generated code for debugging. - internal IEnumerable<(INamedTypeSymbol ContainerClass, INamedTypeSymbol ExtendedType, string Source)> GenerateSource(Compilation compilation, ImmutableDictionary> collectedExtensionMethods) + internal IEnumerable<(INamedTypeSymbol ContainerClass, INamedTypeSymbol ExtendedType, string Source)> GenerateSource(DictionarySet collectedExtensionMethods, CompilationContext context) { - // cache a GeneratedCodeAttribute string to use on all generated methods - var generatorAssembly = GetType().Assembly; - var generatorAssemblyName = generatorAssembly.GetName().Name; - var generatorAssemblyVersion = AttributeExtensions.GetCustomAttribute(generatorAssembly)?.InformationalVersion ?? string.Empty; - var generatedCodeAttribute = $"[GeneratedCode(\"{generatorAssemblyName}\", \"{generatorAssemblyVersion}\")]"; - // go through all candidate types to be extended // these are inner types of a public static class that are not static and not interfaces - foreach (var extendingType in compilation.SourceModule.GlobalNamespace + foreach (var extendingType in context.Compilation.SourceModule.GlobalNamespace .GetAllTypes() - .Where(type => type.IsStatic && type.IsReferenceType && type.IsPublic() && !type.ShouldIgnore(compilation)) + .Where(type => type.IsStatic && type.IsReferenceType && type.IsPublic() && !type.ShouldIgnore(context)) .SelectMany(containerType => containerType.GetTypeMembers().OfType() - .Where(type => !(type.IsStatic || type.IsInterface() || type.ShouldIgnore(compilation))))) + .Where(type => !(type.IsStatic || type.IsInterface() || type.ShouldIgnore(context))))) { - // check if it's a value enumerable and keep a reference to the implemented interface - var valueEnumerableInterface = extendingType.GetAllInterfaces() - .FirstOrDefault(@interface => @interface.Name is "IValueEnumerable" or "IAsyncValueEnumerable"); - if (valueEnumerableInterface is null) - continue; + var bindingAttribute = extendingType.GetBindingsAttribute(context); + foreach (var source in GenerateSource(collectedExtensionMethods, context, extendingType, bindingAttribute)) + yield return source; + } + } + IEnumerable<(INamedTypeSymbol ContainerClass, INamedTypeSymbol ExtendedType, string Source)> GenerateSource(DictionarySet collectedExtensionMethods, CompilationContext context, INamedTypeSymbol extendingType, GeneratorBindingsAttribute? bindingsAttribute) + { + // check if it's a value enumerable and keep a reference to the implemented interface + var valueEnumerableInterface = extendingType.GetAllInterfaces() + .FirstOrDefault(@interface => @interface.Name is "IValueEnumerable" or "IAsyncValueEnumerable"); + if (valueEnumerableInterface is not null || bindingsAttribute is not null) + { // get the types of the enumerable, enumerator and source from the generic parameters declaration var enumerableType = extendingType; - var enumeratorType = valueEnumerableInterface.TypeArguments[1]; - var sourceType = valueEnumerableInterface.TypeArguments[0]; + var enumeratorType = valueEnumerableInterface?.TypeArguments[1]; + var sourceType = valueEnumerableInterface?.TypeArguments[0]; // get the type mappings from the GeneratorMappingsAttribute, if found. - var typeGenericsMapping = extendingType.GetGenericsMappings(compilation); + var typeGenericsMapping = extendingType.GetGenericsMappings(context); // get the info of all the instance methods declared in the type to be extended var implementedInstanceMethods = extendingType.GetMembers().OfType() .Where(method => method.Name is not ".ctor") // ignore the constructors - .Select(method => method.GetInfo(compilation)) + .Select(method => method.GetInfo(context)) .ToArray(); // get the extension methods for this type declared in the outter static type var implementedExtensionMethods = extendingType.ContainingType.GetMembers().OfType() - .Where(method - => method.IsExtensionMethod + .Where(method + => method.IsExtensionMethod && method.Parameters[0].Type.ToDisplayString() == extendingType.ToDisplayString()) - .Select(method => method.GetInfo(compilation, 1)) + .Select(method => method.GetInfo(context, 1)) .ToArray(); // join the two lists together as these are the implemented methods for this type @@ -157,13 +184,14 @@ internal ImmutableDictionary> CollectExtensionMethods(C // go through all the implemented interfaces so that // the overloads are generated based on the extension methods defined for these - var extendingTypeInterfaces = extendingType.AllInterfaces; - for (var interfaceIndex = 0; interfaceIndex < extendingTypeInterfaces.Length; interfaceIndex++) - { - var extendingTypeInterface = extendingTypeInterfaces[interfaceIndex]; + var implementedTypes = + bindingsAttribute?.SourceImplements?.Split(',') + ?? extendingType.AllInterfaces.Select(type => type.OriginalDefinition.MetadataName); + foreach (var implementedType in implementedTypes) + { // get the extension methods collected for this interface - if (!collectedExtensionMethods.TryGetValue(extendingTypeInterface.OriginalDefinition.MetadataName, out var overloadingMethods)) + if (!collectedExtensionMethods.TryGetValue(implementedType, out var overloadingMethods)) continue; // check which ones should be generated @@ -174,7 +202,7 @@ internal ImmutableDictionary> CollectExtensionMethods(C // check if already implemented var mappedOverloadingMethods = overloadingMethod.ApplyMappings(typeGenericsMapping); - if (!implementedMethods.Any(method => method.IsOverload(mappedOverloadingMethods)) + if (!implementedMethods.Any(method => method.IsOverload(mappedOverloadingMethods)) && !((mappedOverloadingMethods.Name is "Select" || mappedOverloadingMethods.Name is "SelectAt") && (extendingType.Name.EndsWith("SelectEnumerable") || extendingType.Name.EndsWith("SelectAtEnumerable")))) // these cases are hard to fix other way { // check if there's a collision with a property @@ -182,7 +210,7 @@ internal ImmutableDictionary> CollectExtensionMethods(C .Any(property => property.Name == mappedOverloadingMethods.Name)) { // this method will be generated as an extension method - extensionMethodsToBeGenerated.Add(mappedOverloadingMethods); + extensionMethodsToBeGenerated.Add(mappedOverloadingMethods); } else { @@ -229,13 +257,13 @@ internal ImmutableDictionary> CollectExtensionMethods(C var entity = extendingType.IsValueType ? "struct" - : "class"; + : "class"; using (builder.AppendBlock($"public partial {entity} {extendingType.Name}{extendingTypeGenericParameters}")) { foreach (var instanceMethod in instanceMethodsToBeGenerated) { var methodGenericsMapping = typeGenericsMapping.AddRange(instanceMethod.GenericsMapping); - GenerateMethodSource(builder, extendingType, instanceMethod, enumerableType, enumeratorType, sourceType, generatedCodeAttribute, methodGenericsMapping, false); + GenerateMethodSource(builder, context, extendingType, instanceMethod, enumerableType, enumeratorType, sourceType, methodGenericsMapping, false, bindingsAttribute); } } } @@ -245,7 +273,7 @@ internal ImmutableDictionary> CollectExtensionMethods(C foreach (var extensionMethod in extensionMethodsToBeGenerated) { var methodGenericsMapping = typeGenericsMapping.AddRange(extensionMethod.GenericsMapping); - GenerateMethodSource(builder, extendingType, extensionMethod, enumerableType, enumeratorType, sourceType, generatedCodeAttribute, methodGenericsMapping, true); + GenerateMethodSource(builder, context, extendingType, extensionMethod, enumerableType, enumeratorType, sourceType, methodGenericsMapping, true, bindingsAttribute); } } } @@ -256,7 +284,7 @@ internal ImmutableDictionary> CollectExtensionMethods(C } } - void GenerateMethodSource(CodeBuilder builder, INamedTypeSymbol extendingType, MethodInfo methodToGenerate, ITypeSymbol enumerableType, ITypeSymbol enumeratorType, ITypeSymbol sourceType, string generatedCodeAttribute, ImmutableArray<(string, string, bool)> genericsMapping, bool isExtensionMethod) + void GenerateMethodSource(CodeBuilder builder, CompilationContext context, INamedTypeSymbol extendingType, MethodInfo methodToGenerate, ITypeSymbol? enumerableType, ITypeSymbol? enumeratorType, ITypeSymbol sourceType, ImmutableArray genericsMapping, bool isExtensionMethod, GeneratorBindingsAttribute? bindingsAttribute) { var extendingTypeTypeArguments = extendingType.MappedTypeArguments(genericsMapping) .ToArray(); @@ -280,7 +308,10 @@ void GenerateMethodSource(CodeBuilder builder, INamedTypeSymbol extendingType, M methodReturnType = methodReturnType.Substring(0, genericsIndex); if (methodToGenerate.ReturnType is INamedTypeSymbol namedMethodReturnType) { - methodReturnType += MapTypeProperties(namedMethodReturnType.TypeArguments.Select(argument => argument.ToDisplayString()), enumerableType, enumeratorType, sourceType, genericsMapping); + if (bindingsAttribute is null) + methodReturnType += MapTypeProperties(namedMethodReturnType.TypeArguments.Select(argument => argument.ToDisplayString()), enumerableType!, enumeratorType!, sourceType, genericsMapping); + else + methodReturnType += MapTypeProperties(namedMethodReturnType.TypeArguments.Select(argument => argument.ToDisplayString()), bindingsAttribute); } } if (methodReturnType is "TEnumerable") @@ -302,40 +333,47 @@ void GenerateMethodSource(CodeBuilder builder, INamedTypeSymbol extendingType, M var returnKeyword = string.Empty; var callContainingType = methodToGenerate.ContainingType; - var callTypeParameters = MapTypeProperties(methodToGenerate.TypeParameters.Select(parameter => parameter.Name), enumerableType, enumeratorType, sourceType, genericsMapping); + var callTypeParameters = bindingsAttribute is null + ? MapTypeProperties(methodToGenerate.TypeParameters.Select(parameter => parameter.Name), enumerableType!, enumeratorType!, sourceType, genericsMapping) + : MapTypeProperties(methodToGenerate.TypeParameters.Select(parameter => parameter.Name), bindingsAttribute); var callParameters = methodToGenerate.Parameters.Select(parameter => parameter.Name).ToCommaSeparated(); // generate the source _ = builder - .AppendLine(generatedCodeAttribute) - //.AppendLine("[DebuggerNonUserCode]") + .AppendLine(context.GeneratedCodeAttribute) + .AppendLine("[DebuggerNonUserCode]") .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]"); + + var firstCallParameter = bindingsAttribute?.Source ?? "this"; + if (isExtensionMethod) { - callParameters = string.IsNullOrEmpty(callParameters) - ? "source" - : $"source, {callParameters}"; - _ = builder.AppendLine($"public static {methodReturnType} {methodName}{methodGenericParametersString}(this {methodExtensionType} source{methodParameters})"); + + firstCallParameter = bindingsAttribute is null + ? "source" + : $"source.{bindingsAttribute.Source}"; } else { - callParameters = string.IsNullOrEmpty(callParameters) - ? "this" - : $"this, {callParameters}"; - var methodReadonly = extendingType.IsValueType ? "readonly" : string.Empty; _ = builder.AppendLine($"public {methodReadonly} {methodReturnType} {methodName}{methodGenericParametersString}({methodParameters})"); } foreach (var (name, constraints, _) in typeParameters.Where(typeParameter => typeParameter.Constraints.Any())) _ = builder.AppendLine($"where {name} : {constraints}"); + + callParameters = StringExtensions.CommaSeparateIfNotNullOrEmpty(firstCallParameter, callParameters); + + if (!string.IsNullOrEmpty(bindingsAttribute?.ExtraParameters)) + callParameters = StringExtensions.CommaSeparateIfNotNullOrEmpty(callParameters, bindingsAttribute!.ExtraParameters); + _ = builder .AppendLine($"=> {callContainingType}.{methodName}{callTypeParameters}({callParameters});") .AppendLine(); } - string MapTypeProperties(IEnumerable typePropertyNames, ITypeSymbol enumerableType, ITypeSymbol enumeratorType, ITypeSymbol sourceType, ImmutableArray<(string, string, bool)> genericsMapping) + string MapTypeProperties(IEnumerable typePropertyNames, ITypeSymbol enumerableType, ITypeSymbol enumeratorType, ITypeSymbol sourceType, ImmutableArray genericsMapping) { var str = typePropertyNames.Select(typePropertyName => typePropertyName switch { @@ -348,5 +386,21 @@ string MapTypeProperties(IEnumerable typePropertyNames, ITypeSymbol enum return string.IsNullOrEmpty(str) ? string.Empty : $"<{str}>"; } + + string MapTypeProperties(IEnumerable typePropertyNames, GeneratorBindingsAttribute? bindingsAttribute) + { + var str = typePropertyNames.Select(typePropertyName => typePropertyName switch + { + "TEnumerable" or "TList" => bindingsAttribute?.EnumerableType ?? typePropertyName, + "TEnumerator" => bindingsAttribute?.EnumeratorType ?? typePropertyName, + "TSource" => bindingsAttribute?.ElementType ?? typePropertyName, + _ => typePropertyName, + }) + .ToCommaSeparated(); + + str = StringExtensions.CommaSeparateIfNotNullOrEmpty(str, bindingsAttribute?.ExtraTypeParameters); + + return string.IsNullOrEmpty(str) ? string.Empty : $"<{str}>"; + } } } diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/DictionarySet.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/DictionarySet.cs new file mode 100644 index 000000000..4f13b7371 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/DictionarySet.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + class DictionarySet + where TKey : notnull + { + readonly Dictionary> dictionary = new(); + + public int Count { get; private set; } + + public void Add(TKey key, TValue value) + { + if (!dictionary.TryGetValue(key, out var list)) + { + list = new List(); + dictionary.Add(key, list); + } + list.Add(value); + Count++; + } + + public bool TryGetValue(TKey key, [NotNullWhen(true)] out IReadOnlyList? values) + { + if (dictionary.TryGetValue(key, out var list)) + { + values = list; + return true; + } + + values = default; + return false; + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs index 925d1aba1..3ec912676 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs @@ -13,7 +13,7 @@ struct MethodInfo public string Name { get; set; } public IReadOnlyList<(string Name, string Constraints, bool IsConcreteType)> TypeParameters { get; set; } public IReadOnlyList<(string Name, string Type, string? DefaultValue)> Parameters { get; set; } - public ImmutableArray<(string, string, bool)> GenericsMapping { get; set; } + public ImmutableArray GenericsMapping { get; set; } } static class MethodSymbolExtensions @@ -29,7 +29,7 @@ public static IEnumerable GetTypeParameterSymbols(this IMe } } - public static MethodInfo GetInfo(this IMethodSymbol method, Compilation compilation, int skip = default) + public static MethodInfo GetInfo(this IMethodSymbol method, CompilationContext context, int skip = default) { try { @@ -46,7 +46,7 @@ public static MethodInfo GetInfo(this IMethodSymbol method, Compilation compilat method.ContainingType.TypeParameters.Concat(method.TypeParameters) .Select(parameter => (parameter.ToDisplayString(), parameter.AsConstraintsStrings().ToCommaSeparated(), false)) .ToArray(), - GenericsMapping = method.GetGenericsMappings(compilation), + GenericsMapping = method.GetGenericsMappings(context), }; } catch (Exception ex) @@ -55,7 +55,7 @@ public static MethodInfo GetInfo(this IMethodSymbol method, Compilation compilat } } - public static MethodInfo ApplyMappings(this MethodInfo method, ImmutableArray<(string, string, bool)> typeGenericsMapping) + public static MethodInfo ApplyMappings(this MethodInfo method, ImmutableArray typeGenericsMapping) { var genericsMapping = typeGenericsMapping.AddRange(method.GenericsMapping); if (genericsMapping.IsDefault) diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs index dea43c04a..c6f648b86 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs @@ -22,37 +22,55 @@ public static string ToCommaSeparated(this IReadOnlyList strings) }; public static StringBuilder AppendCommaSeparated(this StringBuilder builder, IReadOnlyList strings) - => strings.Count switch + { + return strings.Count switch { 0 => builder, 1 => builder.Append(strings[0]), _ => PerformAppendCommaSeparated(builder, strings), }; - static StringBuilder PerformAppendCommaSeparated(this StringBuilder builder, IReadOnlyList strings) + static StringBuilder PerformAppendCommaSeparated(StringBuilder builder, IReadOnlyList strings) + { + _ = builder.Append(strings[0]); + for (var index = 1; index < strings.Count; index++) + { + _ = builder.Append(", ").Append(strings[index]); + } + return builder; + } + } + + public static string CommaSeparateIfNotNullOrEmpty(params string?[] args) { - _ = builder.Append(strings[0]); - for (var index = 1; index < strings.Count; index++) + var builder = new StringBuilder(); + foreach(var arg in args) { - _ = builder.Append(", ").Append(strings[index]); + if (!string.IsNullOrEmpty(arg)) + { + if (builder.Length is not 0) + _ = builder.Append(", "); + + _ = builder.Append(arg); + } } - return builder; + return builder.ToString(); } - public static string ApplyMappings(this string value, ImmutableArray<(string, string, bool)> genericsMapping, out bool isConcreteType) + public static string ApplyMappings(this string value, ImmutableArray genericsMapping, out bool isConcreteType) { var result = value; isConcreteType = false; if (!genericsMapping.IsDefault) { - foreach (var (from, to, isConcreteType2) in genericsMapping.Reverse()) + foreach (var mapping in genericsMapping.Reverse()) { - if (value == from && isConcreteType2) + if (value == mapping.From && mapping.IsType) { isConcreteType = true; - return value.Replace(from, to); + return value.Replace(mapping.From, mapping.To); } - result = result.Replace(from, to); + result = result.Replace(mapping.From, mapping.To); } } return result; diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs index db0483322..dd8f1d59a 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs @@ -1,5 +1,7 @@ using Microsoft.CodeAnalysis; +using System.Collections.Immutable; using System.Linq; +using System.Reflection; namespace NetFabric.Hyperlinq.SourceGenerator { @@ -8,20 +10,71 @@ static class SymbolExtensions public static bool IsPublic(this ISymbol typeSymbol) => typeSymbol.DeclaredAccessibility == Accessibility.Public; - public static bool ShouldIgnore(this ISymbol symbol, Compilation compilation) + public static ImmutableArray GetGenericsMappings(this ISymbol type, CompilationContext compilation) { - var attributeSymbol = compilation.GetTypeByMetadataName("NetFabric.Hyperlinq.GeneratorIgnoreAttribute"); - if (attributeSymbol is null) - return false; - var attribute = symbol.GetAttribute(attributeSymbol); - return attribute is not null - && (bool)attribute.ConstructorArguments[0].Value!; + var attributes = type.GetAttributes() + .Where(attribute => SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, compilation.GeneratorMappingAttribute)) + .Select(attribute => new GeneratorMappingAttribute( + (string)attribute.ConstructorArguments[0].Value!, + (string)attribute.ConstructorArguments[1].Value!, + (bool)attribute.ConstructorArguments[2].Value!)); + + return ImmutableArray.CreateRange(attributes); + } + + public static GeneratorBindingsAttribute? GetBindingsAttribute(this ISymbol type, CompilationContext compilation) + { + var attribute = type.GetAttributes() + .FirstOrDefault(attribute => SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, compilation.GeneratorBindingsAttribute)); + + return attribute switch + { + null => null, + _ => new GeneratorBindingsAttribute( + (string)attribute.ConstructorArguments[0].Value!, + (string)attribute.ConstructorArguments[1].Value!, + (string?)attribute.ConstructorArguments[2].Value, + (string?)attribute.ConstructorArguments[3].Value, + (string?)attribute.ConstructorArguments[4].Value, + (string?)attribute.ConstructorArguments[5].Value) + }; + } + + public static GeneratorIgnoreAttribute? GetIgnoreAttribute(this ISymbol type, CompilationContext compilation) + { + var attribute = type.GetAttributes() + .FirstOrDefault(attribute => SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, compilation.GeneratorIgnoreAttribute)); + + return attribute switch + { + null => null, + _ => new GeneratorIgnoreAttribute((bool)attribute.ConstructorArguments[0].Value!) + }; } - public static AttributeData? GetAttribute(this ISymbol property, INamedTypeSymbol attributeClassSymbol) - => property.GetAttributes() - .FirstOrDefault(attribute - => SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, attributeClassSymbol)); + public static bool ShouldIgnore(this ISymbol symbol, CompilationContext context) + => symbol.GetIgnoreAttribute(context)?.Value ?? false; + + + public static bool ShouldNotIgnore(this ISymbol symbol, CompilationContext context) + { + var attribute = symbol.GetIgnoreAttribute(context); + return attribute switch + { + null => false, + _ => !attribute.Value + }; + } + + public static (bool, string, bool) IsMapped(this ISymbol type, ImmutableArray genericsMapping) + { + foreach (var mapping in genericsMapping) + { + if (type.Name == mapping.From) + return (true, mapping.To, mapping.IsType); + } + return default; + } } } diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeParameterSymbolExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeParameterSymbolExtensions.cs index 151c76e36..7d163a680 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeParameterSymbolExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeParameterSymbolExtensions.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq.SourceGenerator { static class TypeParameterSymbolExtensions { - public static IEnumerable AsConstraintsStrings(this ITypeParameterSymbol parameter, ImmutableArray<(string, string, bool)> genericsMapping = default) + public static IEnumerable AsConstraintsStrings(this ITypeParameterSymbol parameter, ImmutableArray genericsMapping = default) { if (parameter.HasConstructorConstraint) yield return "new"; diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs index 49066684a..21733e322 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs @@ -37,38 +37,25 @@ public static IEnumerable GetAllInterfaces(this ITypeSymbol ty } while (currentTypeSymbol is not null && currentTypeSymbol.SpecialType != SpecialType.System_Object); } - public static ImmutableArray<(string, string, bool)> GetGenericsMappings(this ISymbol type, Compilation compilation) - { - var mappingAttributeSymbol = compilation.GetTypeByMetadataName("NetFabric.Hyperlinq.GeneratorMappingAttribute"); - var mappings = type.GetAttributes() - .Where(attribute => SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, mappingAttributeSymbol)) - .Select(attribute => ( - (string)attribute.ConstructorArguments[0].Value!, - (string)attribute.ConstructorArguments[1].Value!, - (bool)attribute.ConstructorArguments[2].Value!)); - - return ImmutableArray.CreateRange(mappings); - } - - public static string ToDisplayString(this ITypeSymbol type, ImmutableArray<(string, string, bool)> genericsMapping) + public static string ToDisplayString(this ITypeSymbol type, ImmutableArray genericsMapping) => type.ToDisplayString().ApplyMappings(genericsMapping, out _); static IEnumerable GetTypeArguments(ITypeSymbol typeSymbol) { - if (typeSymbol is INamedTypeSymbol namedType && namedType.IsGenericType) + if (typeSymbol is INamedTypeSymbol {IsGenericType: true} namedType) { var typeArguments = namedType.TypeArguments; - for (var index = 0; index < typeArguments.Length; index++) + foreach (var typeArgument in typeArguments) { - var typeArgument = typeArguments[index]; if (typeArgument is ITypeParameterSymbol typeParameter) yield return typeParameter; } } } - static IEnumerable<(string Name, ITypeParameterSymbol TypeParameter)> MapTypeParameters(IEnumerable typeParameters, ImmutableArray<(string, string, bool)> genericsMapping) + static IEnumerable<(string Name, ITypeParameterSymbol TypeParameter)> MapTypeParameters(IEnumerable typeParameters, ImmutableArray genericsMapping) { + // ReSharper disable once HeapView.ObjectAllocation.Evident var set = new HashSet(); foreach (var typeParameter in typeParameters) @@ -90,21 +77,11 @@ static IEnumerable GetTypeArguments(ITypeSymbol typeSymbol } } - public static IEnumerable<(string Name, string Constraints)> MappedTypeArguments(this ITypeSymbol type, ImmutableArray<(string, string, bool)> genericsMapping) + public static IEnumerable<(string Name, string Constraints)> MappedTypeArguments(this ITypeSymbol type, ImmutableArray genericsMapping) { var methodParameters = GetTypeArguments(type); return MapTypeParameters(methodParameters, genericsMapping) .Select(typeArgument => (typeArgument.Name, typeArgument.TypeParameter.AsConstraintsStrings(genericsMapping).ToCommaSeparated())); } - - static (bool, string, bool) IsMapped(this ITypeSymbol type, ImmutableArray<(string, string, bool)> genericsMapping) - { - foreach (var (from, to, isConcreteType) in genericsMapping) - { - if (type.Name == from) - return (true, to, isConcreteType); - } - return default; - } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs index 1bb2126fb..a0ce037d6 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs @@ -1,7 +1,5 @@ using NetFabric.Assertive; using Xunit; -using System.Collections.Generic; -using System.Linq; namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable { @@ -23,134 +21,9 @@ public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) // Assert _ = result.Must() - .BeOfType, Wrap.Enumerator, int>>() + .BeOfType, int>>() .BeEnumerableOf() .BeEqualTo(wrapped); } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .ToArray(); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] - public void AsValueEnumerable_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Skip(count0) - .Skip(count1); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(count0) - .Skip(count1); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Take(count0) - .Take(count1); - - // Act - var result = wrapped - .AsValueEnumerable() - .Take(count0) - .Take(count1); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Count(); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Sum(); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs index 946833dd8..c93a9fcc4 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs @@ -68,7 +68,7 @@ void IList.RemoveAt(int index) => throw new NotSupportedException(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.ValueEnumerable, Enumerator, T> AsValueEnumerable() + public ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() => this.AsValueEnumerable, Enumerator, T>(); } } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs index 6c694d0c6..8a315e62f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs @@ -38,7 +38,7 @@ readonly IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.ValueEnumerable, Enumerator, T> AsValueEnumerable() + public ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() => this.AsValueEnumerable, Enumerator, T>(); } } diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs index bfe3aea7d..0d3687419 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs @@ -5,6 +5,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static int Count(this ReadOnlySpan source) => source.Length; diff --git a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs index 5f77da2ff..a76cd224a 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs @@ -27,7 +27,7 @@ public static async ValueTask CountAsync return counter; } - static async ValueTask CountAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask CountAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction @@ -52,7 +52,7 @@ static async ValueTask CountAsync CountAtAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask CountAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs index 5a7398494..9bea87bfb 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs @@ -25,7 +25,7 @@ public static async ValueTask SumAsync SumAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + internal static async ValueTask SumAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -49,7 +49,7 @@ internal static async ValueTask SumAsync SumAtAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + internal static async ValueTask SumAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -73,7 +73,7 @@ internal static async ValueTask SumAtAsync SumAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + internal static async ValueTask SumAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -96,7 +96,7 @@ internal static async ValueTask SumAsync SumAtAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + internal static async ValueTask SumAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -119,7 +119,7 @@ internal static async ValueTask SumAtAsync SumAsync(this TEnumerable source, TPredicate predicate, TSelector selector, CancellationToken cancellationToken) + internal static async ValueTask SumAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs index e29b5e75b..f6a1ef92d 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs @@ -7,7 +7,8 @@ namespace NetFabric.Hyperlinq { public static partial class EnumerableExtensions { - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueEnumerable AsValueEnumerable(this IEnumerable source) => new(source); @@ -35,6 +36,9 @@ IEnumerator IEnumerable.GetEnumerator() ValueEnumerable AsValueEnumerable() => this; + IEnumerable AsEnumerable() + => source; + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index 30f127cf1..a54ae40f7 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -9,7 +9,8 @@ namespace NetFabric.Hyperlinq { public static partial class ReadOnlyCollectionExtensions { - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueEnumerable AsValueEnumerable(this IReadOnlyCollection source) => new(source); @@ -79,6 +80,9 @@ bool ICollection.Remove(TSource item) ValueEnumerable AsValueEnumerable() => this; + IReadOnlyCollection AsEnumerable() + => source; + #endregion #region Quantifier diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs index c147ec255..6ac9098a4 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs @@ -7,12 +7,14 @@ namespace NetFabric.Hyperlinq { public static partial class ValueEnumerableExtensions { - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueEnumerable AsValueEnumerable(this IValueEnumerable source) where TEnumerator : struct, IEnumerator => new(source); + [GeneratorBindings(source: "source", sourceImplements: "IValueEnumerable`2", enumerableType: "IValueEnumerable")] [StructLayout(LayoutKind.Auto)] public readonly partial struct ValueEnumerable : IValueEnumerable @@ -39,6 +41,9 @@ IEnumerator IEnumerable.GetEnumerator() ValueEnumerable AsValueEnumerable() => this; + IEnumerable AsEnumerable() + => source; + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index 7fa8e661e..558866993 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -9,12 +9,14 @@ namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyCollectionExtensions { - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueEnumerable AsValueEnumerable(this IValueReadOnlyCollection source) where TEnumerator : struct, IEnumerator => new(source); + [GeneratorBindings(source: "source", sourceImplements: "IValueReadOnlyCollection`2,IValueEnumerable`2", enumerableType: "IValueReadOnlyCollection")] [StructLayout(LayoutKind.Auto)] public readonly partial struct ValueEnumerable : IValueReadOnlyCollection @@ -83,6 +85,9 @@ bool ICollection.Remove(TSource item) ValueEnumerable AsValueEnumerable() => this; + IReadOnlyCollection AsEnumerable() + => source; + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs index bc95fa35a..e1a65477d 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -41,7 +41,7 @@ public static ValueEnumerable where TGetEnumerator2 : struct, IFunction => new(source, getEnumerator, getEnumerator2); - + [StructLayout(LayoutKind.Auto)] public partial struct ValueEnumerable : IValueEnumerable @@ -74,6 +74,9 @@ IEnumerator IEnumerable.GetEnumerator() ValueEnumerable AsValueEnumerable() => this; + TEnumerable AsEnumerable() + => source; + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index db3bdf408..64525fc93 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -43,7 +43,7 @@ public static ValueEnumerable where TGetEnumerator2 : struct, IFunction => new(source, getEnumerator, getEnumerator2); - + [StructLayout(LayoutKind.Auto)] public partial struct ValueEnumerable : IValueReadOnlyCollection @@ -117,6 +117,9 @@ bool ICollection.Remove(TSource item) ValueEnumerable AsValueEnumerable() => this; + TEnumerable AsEnumerable() + => source; + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs index 0b28526f5..11501b987 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs @@ -41,19 +41,20 @@ public static ValueEnumerable where TGetEnumerator2 : struct, IFunction => new(source, getEnumerator, getEnumerator2); - + + [GeneratorBindings(source: "source", sourceImplements: "IValueEnumerable`2")] [StructLayout(LayoutKind.Auto)] public partial struct ValueEnumerable - : IValueEnumerable - where TEnumerable : IEnumerable + : IValueEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction { - readonly TEnumerable source; - TGetEnumerator getEnumerator; - TGetEnumerator2 getEnumerator2; + internal readonly TEnumerable source; + internal TGetEnumerator getEnumerator; + internal TGetEnumerator2 getEnumerator2; internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); @@ -76,97 +77,100 @@ IEnumerator IEnumerable.GetEnumerator() ValueEnumerable AsValueEnumerable() => this; + TEnumerable AsEnumerable() + => source; + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, int, int>(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, int?, int>(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, long, long>(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, long?, long>(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, float, float>(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, float?, float>(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, double, double>(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, double?, double>(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, decimal, decimal>(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable + where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TEnumerator2 : struct where TGetEnumerator : struct, IFunction where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, decimal?, decimal>(); + => source.source.Sum(); } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index a087a17e8..051a0300c 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -43,7 +43,8 @@ public static ValueEnumerable where TGetEnumerator2 : struct, IFunction => new(source, getEnumerator, getEnumerator2); - + + [GeneratorBindings(source: "source", sourceImplements: "IValueReadOnlyCollection`2,IValueEnumerable`2")] [StructLayout(LayoutKind.Auto)] public partial struct ValueEnumerable : IValueReadOnlyCollection @@ -119,6 +120,9 @@ bool ICollection.Remove(TSource item) ValueEnumerable AsValueEnumerable() => this; + TEnumerable AsEnumerable() + => source; + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs index 318d761c2..b9cd3a2dc 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs @@ -6,6 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ArraySegmentValueEnumerable AsValueEnumerable(this TSource[] source) => new(new ArraySegment(source)); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index c6d25858e..d12f3dd8b 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -12,11 +12,12 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ArraySegmentValueEnumerable AsValueEnumerable(this ArraySegment source) => new(source); - [GeneratorIgnore] + [GeneratorBindings(source: "((ReadOnlySpan)source.AsSpan())", sourceImplements: "ReadOnlySpan`1")] [StructLayout(LayoutKind.Auto)] public readonly partial struct ArraySegmentValueEnumerable : IValueReadOnlyList.DisposableEnumerator> @@ -161,14 +162,6 @@ public ArraySegmentValueEnumerable AsValueEnumerable() public TSource[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => ((ReadOnlySpan)source.AsSpan()).ToArray(memoryPool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToList(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs index 34330c106..ce41542a3 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs @@ -6,6 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static MemoryValueEnumerable AsValueEnumerable(this Memory source) => ((ReadOnlyMemory)source).AsValueEnumerable(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs index 5292f91b4..57e8f2a34 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs @@ -9,10 +9,12 @@ namespace NetFabric.Hyperlinq { public static partial class ReadOnlyListExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueEnumerable, TSource> AsValueEnumerable(this IReadOnlyList source) => AsValueEnumerable, TSource>(source); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueEnumerable AsValueEnumerable(this TList source) where TList : IReadOnlyList @@ -180,6 +182,9 @@ public readonly void Dispose() { } ValueEnumerable AsValueEnumerable() => this; + TList AsEnumerable() + => source; + #endregion #region Partitioning diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index 291020b0a..b486fffd3 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -1,5 +1,4 @@ using System; -using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -12,13 +11,14 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static MemoryValueEnumerable AsValueEnumerable(this ReadOnlyMemory source) => new(source); - [GeneratorIgnore] + [GeneratorBindings(source: "source.Span", sourceImplements: "ReadOnlySpan`1")] [StructLayout(LayoutKind.Auto)] - public readonly struct MemoryValueEnumerable + public readonly partial struct MemoryValueEnumerable : IValueReadOnlyList.DisposableEnumerator> , IList { @@ -147,54 +147,10 @@ public MemoryValueEnumerable AsEnumerable() public MemoryValueEnumerable AsValueEnumerable() => this; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TSource[] ToArray() - => source.Span.ToArray(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.Span.ToArray(memoryPool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.Span.ToList(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.Span.ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - => source.Span.ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.Span.ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => source.Span.ToDictionary(keySelector, elementSelector, comparer); - #endregion #region Element - public Option ElementAt(int index) - => source.Span.ElementAt(index); - - public Option First() - => source.Span.First(); - - public Option Single() - => source.Span.Single(); - #endregion #region Filtering @@ -271,50 +227,6 @@ public MemorySelectManyEnumerable predicate) - => All(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate predicate) - where TPredicate : struct, IFunction - => source.Span.All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => source.Span.All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate predicate) - where TPredicate : struct, IFunction - => source.Span.AllAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.Span.Any(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => source.Span.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate predicate) - where TPredicate : struct, IFunction - => source.Span.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => source.Span.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate predicate) - where TPredicate : struct, IFunction - => source.Span.AnyAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer = default) - => source.Span.Contains(value, comparer); - #endregion #region Set diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index 98868a4c0..7b33b3122 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -10,13 +10,14 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SpanValueEnumerable AsValueEnumerable(this ReadOnlySpan source) => new(source); - [GeneratorIgnore] + [GeneratorBindings(source: "source", sourceImplements: "ReadOnlySpan`1")] [StructLayout(LayoutKind.Auto)] - public readonly ref struct SpanValueEnumerable + public readonly ref partial struct SpanValueEnumerable { internal readonly ReadOnlySpan source; @@ -53,54 +54,10 @@ public SpanValueEnumerable AsEnumerable() public SpanValueEnumerable AsValueEnumerable() => this; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TSource[] ToArray() - => source.ToArray(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(memoryPool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.ToList(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - => source.ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => source.ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => source.ToDictionary(keySelector, elementSelector, comparer); - #endregion #region Element - public Option ElementAt(int index) - => source.ElementAt(index); - - public Option First() - => source.First(); - - public Option Single() - => source.Single(); - #endregion #region Filtering @@ -177,50 +134,6 @@ public SpanSelectManyEnumerable predicate) - => All(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate predicate) - where TPredicate : struct, IFunction - => source.All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => source.All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate predicate) - where TPredicate : struct, IFunction - => source.AllAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.Any(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => source.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate predicate) - where TPredicate : struct, IFunction - => source.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => source.Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate predicate) - where TPredicate : struct, IFunction - => source.AnyAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer = null) - => source.Contains(value, comparer); - #endregion #region Set diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs index d35dcce67..821f8da57 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs @@ -6,6 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SpanValueEnumerable AsValueEnumerable(this Span source) => ((ReadOnlySpan)source).AsValueEnumerable(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs index bd5ed7afb..62c8a5a6e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs @@ -1,269 +1,21 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; +using System.Collections.Generic; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, TEnumerator, TSource> AsValueEnumerable(this IValueReadOnlyList source) + public static ReadOnlyListExtensions.ValueEnumerable, TSource> AsValueEnumerable(this IValueReadOnlyList source) where TEnumerator : struct, IEnumerator - => AsValueEnumerable, TEnumerator, TSource>(source); + => ReadOnlyListExtensions.AsValueEnumerable(source); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TList source) + public static ReadOnlyListExtensions.ValueEnumerable AsValueEnumerable(this TList source) where TList : IValueReadOnlyList where TEnumerator : struct, IEnumerator - => new(source, 0, source.Count); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueReadOnlyList.DisposableEnumerator> - , IList - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - { - internal readonly TList source; - internal readonly int offset; - - internal ValueEnumerable(TList source, int offset, int count) - => (this.source, this.offset, Count) = (source, offset, count); - - public readonly int Count { get; } - - public readonly TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); - - return source[index + offset]; - } - } - - TSource IReadOnlyList.this[int index] - => this[index]; - - TSource IList.this[int index] - { - get => this[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() - => new(in this); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - ReadOnlyListExtensions.Copy(this, 0, span, Count); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => Count is not 0 && source.Contains(item); - - public int IndexOf(TSource item) - => ReadOnlyListExtensions.IndexOf(source, item, offset, Count); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - { - readonly TList source; - readonly int end; - int index; - - internal Enumerator(in ValueEnumerable enumerable) - { - source = enumerable.source; - index = enumerable.offset - 1; - end = index + enumerable.Count; - } - - public TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - } - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly TList source; - readonly int end; - int index; - - internal DisposableEnumerator(in ValueEnumerable enumerable) - { - source = enumerable.source; - index = enumerable.offset - 1; - end = index + enumerable.Count; - } - - public TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - TSource IEnumerator.Current - => source[index]; - object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source[index]; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public readonly void Dispose() { } - } - - #region Conversion - - ValueEnumerable AsValueEnumerable() - => this; - - #endregion - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable Skip(int count) - { - var (skipCount, takeCount) = Utils.Skip(Count, count); - return new ValueEnumerable(source, offset + skipCount, takeCount); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable Take(int count) - => new(source, offset, Utils.Take(Count, count)); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => source.source.Sum(source.offset, source.Count); + => ReadOnlyListExtensions.AsValueEnumerable(source); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs index f4d5bb954..5d0618caa 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs @@ -28,10 +28,10 @@ static TSource[] BuildArray(TList source, int offset, int count) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IMemoryOwner ToArray(this TList source, MemoryPool pool) where TList : struct, IReadOnlyList - => source.ToArray(0, source.Count, pool); + => source.ToArray(pool, 0, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TList source, int offset, int count, MemoryPool pool) + static IMemoryOwner ToArray(this TList source, MemoryPool pool, int offset, int count) where TList : struct, IReadOnlyList { return count switch @@ -64,25 +64,25 @@ static TSource[] ToArray(this TList source, TPredica static TSource[] BuildArray(TList source, TPredicate predicate, int offset, int count) { - using var arrayBuilder = ToArrayBuilder(source, predicate, offset, count, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, offset, count); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TList source, TPredicate predicate, int offset, int count, MemoryPool pool) + static IMemoryOwner ToArray(this TList source, MemoryPool pool, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction { return count switch { 0 => pool.Rent(0), - _ => BuildArray(source, predicate, offset, count, pool) + _ => BuildArray(source, pool, predicate, offset, count) }; - static IMemoryOwner BuildArray(TList source, TPredicate predicate, int offset, int count, MemoryPool pool) + static IMemoryOwner BuildArray(TList source, MemoryPool pool, TPredicate predicate, int offset, int count) { - using var arrayBuilder = ToArrayBuilder(source, predicate, offset, count, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, offset, count); return arrayBuilder.ToArray(pool); } } @@ -103,25 +103,25 @@ static TSource[] ToArrayAt(this TList source, TPredi static TSource[] BuildArray(TList source, TPredicate predicate, int offset, int count) { - using var arrayBuilder = ToArrayBuilderAt(source, predicate, offset, count, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate, offset, count); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TList source, TPredicate predicate, int offset, int count, MemoryPool pool) + static IMemoryOwner ToArrayAt(this TList source, MemoryPool pool, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction { return count switch { 0 => pool.Rent(0), - _ => BuildArray(source, predicate, offset, count, pool) + _ => BuildArray(source, pool, predicate, offset, count) }; - static IMemoryOwner BuildArray(TList source, TPredicate predicate, int offset, int count, MemoryPool pool) + static IMemoryOwner BuildArray(TList source, MemoryPool pool, TPredicate predicate, int offset, int count) { - using var arrayBuilder = ToArrayBuilderAt(source, predicate, offset, count, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate, offset, count); return arrayBuilder.ToArray(pool); } } @@ -149,17 +149,17 @@ static TResult[] BuildArray(TList source, TSelector selector, int offset, int co } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TList source, TSelector selector, int offset, int count, MemoryPool pool) + static IMemoryOwner ToArray(this TList source, MemoryPool pool, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction { return count switch { 0 => pool.Rent(0), - _ => BuildArray(source, selector, offset, count, pool) + _ => BuildArray(source, pool, selector, offset, count) }; - static IMemoryOwner BuildArray(TList source, TSelector selector, int offset, int count, MemoryPool pool) + static IMemoryOwner BuildArray(TList source, MemoryPool pool, TSelector selector, int offset, int count) { var result = pool.RentSliced(count); Copy(source, offset, result.Memory.Span, count, selector); @@ -190,17 +190,17 @@ static TResult[] BuildArray(TList source, TSelector selector, int offset, int co } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TList source, TSelector selector, int offset, int count, MemoryPool pool) + static IMemoryOwner ToArrayAt(this TList source, MemoryPool pool, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction { return count switch { 0 => pool.Rent(0), - _ => BuildArray(source, selector, offset, count, pool) + _ => BuildArray(source, pool, selector, offset, count) }; - static IMemoryOwner BuildArray(TList source, TSelector selector, int offset, int count, MemoryPool pool) + static IMemoryOwner BuildArray(TList source, MemoryPool pool, TSelector selector, int offset, int count) { var result = pool.RentSliced(count); CopyAt(source, offset, result.Memory.Span, count, selector); @@ -225,13 +225,13 @@ static TResult[] ToArray(this TL static TResult[] BuildArray(TList source, TPredicate predicate, TSelector selector, int offset, int count) { - using var arrayBuilder = ToArrayBuilder(source, predicate, selector, offset, count, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector, offset, count); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TList source, TPredicate predicate, TSelector selector, int offset, int count, MemoryPool pool) + static IMemoryOwner ToArray(this TList source, MemoryPool pool, TPredicate predicate, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction where TSelector : struct, IFunction @@ -239,12 +239,12 @@ static IMemoryOwner ToArray pool.Rent(0), - _ => BuildArray(source, predicate, selector, offset, count, pool) + _ => BuildArray(source, pool, predicate, selector, offset, count) }; - static IMemoryOwner BuildArray(TList source, TPredicate predicate, TSelector selector, int offset, int count, MemoryPool pool) + static IMemoryOwner BuildArray(TList source, MemoryPool pool, TPredicate predicate, TSelector selector, int offset, int count) { - using var arrayBuilder = ToArrayBuilder(source, predicate, selector, offset, count, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector, offset, count); return arrayBuilder.ToArray(pool); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index 05a73aaa6..60372b4c5 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -7,7 +7,12 @@ namespace NetFabric.Hyperlinq { static partial class ArrayExtensions { + [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static TSource[] ToArray(this ReadOnlySpan source) + => source.ToArray(); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool) { @@ -39,24 +44,24 @@ static TSource[] ToArray(this ReadOnlySpan source, static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) { - using var arrayBuilder = ToArrayBuilder(source, predicate, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this ReadOnlySpan source, TPredicate predicate, MemoryPool pool) + static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool, TPredicate predicate) where TPredicate : struct, IFunction { return source switch { { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, predicate, pool) + _ => BuildArray(source, pool, predicate) }; - static IMemoryOwner BuildArray(ReadOnlySpan source, TPredicate predicate, MemoryPool pool) + static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TPredicate predicate) { - using var arrayBuilder = ToArrayBuilder(source, predicate, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate); return arrayBuilder.ToArray(pool); } } @@ -76,24 +81,24 @@ static TSource[] ToArrayAt(this ReadOnlySpan sourc static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) { - using var arrayBuilder = ToArrayBuilderAt(source, predicate, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this ReadOnlySpan source, TPredicate predicate, MemoryPool pool) + static IMemoryOwner ToArrayAt(this ReadOnlySpan source, MemoryPool pool, TPredicate predicate) where TPredicate : struct, IFunction { return source switch { { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, predicate, pool) + _ => BuildArray(source, pool, predicate) }; - static IMemoryOwner BuildArray(ReadOnlySpan source, TPredicate predicate, MemoryPool pool) + static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TPredicate predicate) { - using var arrayBuilder = ToArrayBuilderAt(source, predicate, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate); return arrayBuilder.ToArray(pool); } } @@ -141,7 +146,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TVectorSelector vector } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector, MemoryPool pool) + static IMemoryOwner ToArrayVector(this ReadOnlySpan source, MemoryPool pool, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct @@ -150,10 +155,10 @@ static IMemoryOwner ToArrayVector pool.Rent(0), - _ => BuildArray(source, vectorSelector, selector, pool) + _ => BuildArray(source, pool, vectorSelector, selector) }; - static IMemoryOwner BuildArray(ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector, MemoryPool pool) + static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TVectorSelector vectorSelector, TSelector selector) { var result = pool.RentSliced(source.Length); CopyVector(source, result.Memory.Span, vectorSelector, selector); @@ -162,16 +167,16 @@ static IMemoryOwner BuildArray(ReadOnlySpan source, TVectorSel } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this ReadOnlySpan source, TSelector selector, MemoryPool pool) + static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool, TSelector selector) where TSelector : struct, IFunction { return source switch { { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, selector, pool) + _ => BuildArray(source, pool, selector) }; - static IMemoryOwner BuildArray(ReadOnlySpan source, TSelector selector, MemoryPool pool) + static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TSelector selector) { var result = pool.RentSliced(source.Length); Copy(source, result.Memory.Span, selector); @@ -200,16 +205,16 @@ static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this ReadOnlySpan source, TSelector selector, MemoryPool pool) + static IMemoryOwner ToArrayAt(this ReadOnlySpan source, MemoryPool pool, TSelector selector) where TSelector : struct, IFunction { return source switch { { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, selector, pool) + _ => BuildArray(source, pool, selector) }; - static IMemoryOwner BuildArray(ReadOnlySpan source, TSelector selector, MemoryPool pool) + static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TSelector selector) { var result = pool.RentSliced(source.Length); CopyAt(source, result.Memory.Span, selector); @@ -233,25 +238,25 @@ static TResult[] ToArray(this ReadOnlyS static TResult[] BuildArray(ReadOnlySpan source, TPredicate predicate, TSelector selector) { - using var arrayBuilder = ToArrayBuilder(source, predicate, selector, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this ReadOnlySpan source, TPredicate predicate, TSelector selector, MemoryPool pool) + static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction { return source switch { { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, predicate, selector, pool) + _ => BuildArray(source, pool, predicate, selector) }; - static IMemoryOwner BuildArray(ReadOnlySpan source, TPredicate predicate, TSelector selector, MemoryPool pool) + static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TPredicate predicate, TSelector selector) { - using var arrayBuilder = ToArrayBuilder(source, predicate, selector, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector); return arrayBuilder.ToArray(pool); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index eddfe1768..776cdb82d 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -49,17 +49,17 @@ internal static TSource[] ToArray where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, predicate, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static IMemoryOwner ToArray(this TEnumerable source, TPredicate predicate, MemoryPool pool) + internal static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, predicate, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate); return arrayBuilder.ToArray(pool); } @@ -72,17 +72,17 @@ internal static TSource[] ToArrayAt where TPredicate : struct, IFunction { - using var arrayBuilder = ToArrayBuilderAt(source, predicate, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static IMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, MemoryPool pool) + internal static IMemoryOwner ToArrayAt(this TEnumerable source, MemoryPool pool, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction { - using var arrayBuilder = ToArrayBuilderAt(source, predicate, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate); return arrayBuilder.ToArray(pool); } @@ -95,17 +95,17 @@ static TResult[] ToArray( where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, selector, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, selector); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TEnumerable source, TSelector selector, MemoryPool pool) + static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, selector, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, selector); return arrayBuilder.ToArray(pool); } @@ -117,17 +117,17 @@ static TResult[] ToArrayAt where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilderAt(source, selector, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, selector); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TEnumerable source, TSelector selector, MemoryPool pool) + static IMemoryOwner ToArrayAt(this TEnumerable source, MemoryPool pool, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilderAt(source, selector, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, selector); return arrayBuilder.ToArray(pool); } @@ -141,18 +141,18 @@ internal static TResult[] ToArray where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, predicate, selector, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static IMemoryOwner ToArray(this TEnumerable source, TPredicate predicate, TSelector selector, MemoryPool pool) + internal static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, predicate, selector, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector); return arrayBuilder.ToArray(pool); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index 1efd93618..d9f09ef03 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -68,14 +68,14 @@ static TSource[] ToArray(this TEn }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TEnumerable source, TPredicate predicate, MemoryPool pool) + static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction => source switch { { Count: 0 } => pool.Rent(0), - _ => ValueEnumerableExtensions.ToArray(source, predicate, pool) + _ => ValueEnumerableExtensions.ToArray(source, pool, predicate) }; ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -92,14 +92,14 @@ static TSource[] ToArrayAt(this T }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, MemoryPool pool) + static IMemoryOwner ToArrayAt(this TEnumerable source, MemoryPool pool, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction => source switch { { Count: 0 } => pool.Rent(0), - _ => ValueEnumerableExtensions.ToArrayAt(source, predicate, pool) + _ => ValueEnumerableExtensions.ToArrayAt(source, pool, predicate) }; ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -126,7 +126,7 @@ static TResult[] BuildArray(TEnumerable source, TSelector selector) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TEnumerable source, TSelector selector, MemoryPool pool) + static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -134,10 +134,10 @@ static IMemoryOwner ToArray pool.Rent(0), - _ => BuildArray(source, selector, pool) + _ => BuildArray(source, pool, selector) }; - static IMemoryOwner BuildArray(TEnumerable source, TSelector selector, MemoryPool pool) + static IMemoryOwner BuildArray(TEnumerable source, MemoryPool pool, TSelector selector) { var result = pool.RentSliced(source.Count); Copy(source, result.Memory.Span, selector); @@ -170,7 +170,7 @@ static TResult[] BuildArray(TEnumerable source, TSelector selector) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TEnumerable source, TSelector selector, MemoryPool pool) + static IMemoryOwner ToArrayAt(this TEnumerable source, MemoryPool pool, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -178,10 +178,10 @@ static IMemoryOwner ToArrayAt pool.Rent(0), - _ => BuildArray(source, selector, pool) + _ => BuildArray(source, pool, selector) }; - static IMemoryOwner BuildArray(TEnumerable source, TSelector selector, MemoryPool pool) + static IMemoryOwner BuildArray(TEnumerable source, MemoryPool pool, TSelector selector) { var result = pool.RentSliced(source.Count); CopyAt(source, result.Memory.Span, selector); @@ -204,7 +204,7 @@ static TResult[] ToArray ToArray(this TEnumerable source, TPredicate predicate, TSelector selector, MemoryPool pool) + static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction @@ -212,7 +212,7 @@ static IMemoryOwner ToArray source switch { { Count: 0 } => pool.Rent(0), - _ => ValueEnumerableExtensions.ToArray(source, predicate, selector, pool) + _ => ValueEnumerableExtensions.ToArray(source, pool, predicate, selector) }; } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs index fdf164f95..0f0c13a12 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs @@ -24,83 +24,83 @@ public static async ValueTask> ToArrayAsync ToArrayAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(predicate, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAsync(this TEnumerable source, TPredicate predicate, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(predicate, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, predicate).ConfigureAwait(false)).ToArray(pool); ////////////////////////////////////////////////////////////////////////////////////////////////// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask ToArrayAtAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayBuilderAtAsync(predicate, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAtAsync(this TEnumerable source, TPredicate predicate, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayAtAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayBuilderAtAsync(predicate, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, cancellationToken, predicate).ConfigureAwait(false)).ToArray(pool); ////////////////////////////////////////////////////////////////////////////////////////////////// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask ToArrayAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + static async ValueTask ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(selector, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, selector).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAsync(this TEnumerable source, TSelector selector, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(selector, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, selector).ConfigureAwait(false)).ToArray(pool); ////////////////////////////////////////////////////////////////////////////////////////////////// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask ToArrayAtAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + static async ValueTask ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAtAsync(selector, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, cancellationToken, selector).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAtAsync(this TEnumerable source, TSelector selector, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayAtAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAtAsync(selector, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, cancellationToken, selector).ConfigureAwait(false)).ToArray(pool); ////////////////////////////////////////////////////////////////////////////////////////////////// [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask ToArrayAsync(this TEnumerable source, TPredicate predicate, TSelector selector, CancellationToken cancellationToken) + static async ValueTask ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(predicate, selector, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, predicate, selector).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAsync(this TEnumerable source, TPredicate predicate, TSelector selector, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(predicate, selector, ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, predicate, selector).ConfigureAwait(false)).ToArray(pool); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs index 7eb60a283..98d15e5ba 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs @@ -6,11 +6,13 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Dictionary ToDictionary(this ReadOnlySpan source, Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull => source.ToDictionary(new FunctionWrapper(keySelector), comparer); + [GeneratorIgnore(false)] static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction @@ -74,11 +76,13 @@ static Dictionary ToDictionary ToDictionary(this ReadOnlySpan source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) where TKey : notnull => source.ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); + [GeneratorIgnore(false)] static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs index 29d8eb9cb..a63b0ea6b 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs @@ -62,8 +62,8 @@ static async ValueTask> ToDictionaryAsync? comparer, - TPredicate predicate, - CancellationToken cancellationToken) + CancellationToken cancellationToken, + TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TKey : notnull @@ -96,8 +96,8 @@ static async ValueTask> ToDictionaryAtAsync? comparer, - TPredicate predicate, - CancellationToken cancellationToken) + CancellationToken cancellationToken, + TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TKey : notnull @@ -225,8 +225,8 @@ static async ValueTask> ToDictionaryAsync? comparer, - TPredicate predicate, - CancellationToken cancellationToken) + CancellationToken cancellationToken, + TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TKey : notnull @@ -261,8 +261,8 @@ static async ValueTask> ToDictionaryAtAsync? comparer, - TPredicate predicate, - CancellationToken cancellationToken) + CancellationToken cancellationToken, + TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TKey : notnull diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs index 7a1163ffb..797924e6e 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs @@ -9,6 +9,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source) => source switch diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs index 9ec3fa66d..69a678254 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs @@ -17,43 +17,43 @@ public static async ValueTask> ToListAsync> ToListAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayAsync(predicate, cancellationToken).ConfigureAwait(false)).AsList(); + => (await source.ToArrayAsync(cancellationToken, predicate).ConfigureAwait(false)).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToListAtAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask> ToListAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayAtAsync(predicate, cancellationToken).ConfigureAwait(false)).AsList(); + => (await source.ToArrayAtAsync(cancellationToken, predicate).ConfigureAwait(false)).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToListAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayAsync(selector, cancellationToken).ConfigureAwait(false)).AsList(); + => (await source.ToArrayAsync(cancellationToken, selector).ConfigureAwait(false)).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToListAtAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + static async ValueTask> ToListAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayAtAsync(selector, cancellationToken).ConfigureAwait(false)).AsList(); + => (await source.ToArrayAtAsync(cancellationToken, selector).ConfigureAwait(false)).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToListAsync(this TEnumerable source, TPredicate predicate, TSelector selector, CancellationToken cancellationToken) + static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => (await source.ToArrayAsync(predicate, selector, cancellationToken).ConfigureAwait(false)).AsList(); + => (await source.ToArrayAsync(cancellationToken, predicate, selector).ConfigureAwait(false)).AsList(); } } diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs index 3da1b3d3f..df7963c4a 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs @@ -5,7 +5,8 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - + + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this ReadOnlySpan source, int index) => index < 0 || index >= source.Length diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs index f1c13b773..5567464d1 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs @@ -35,16 +35,16 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - static ValueTask> ElementAtAsync(this TEnumerable source, int index, TPredicate predicate, CancellationToken cancellationToken) + static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction { return index < 0 ? new ValueTask>(Option.None) - : ExecuteAsync(source, index, predicate, cancellationToken); + : ExecuteAsync(source, index, cancellationToken, predicate); - static async ValueTask> ExecuteAsync(TEnumerable source, int index, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask> ExecuteAsync(TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) { var enumerator = source.GetAsyncEnumerator(cancellationToken); try @@ -64,16 +64,16 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, TPredicate predicate, CancellationToken cancellationToken) + static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction { return index < 0 ? new ValueTask>(Option.None) - : ExecuteAsync(source, index, predicate, cancellationToken); + : ExecuteAsync(source, index, cancellationToken, predicate); - static async ValueTask> ExecuteAsync(TEnumerable source, int index, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask> ExecuteAsync(TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) { var enumerator = source.GetAsyncEnumerator(cancellationToken); try @@ -96,16 +96,16 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - static ValueTask> ElementAtAsync(this TEnumerable source, int index, TSelector selector, CancellationToken cancellationToken) + static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction { return index < 0 ? new ValueTask>(Option.None) - : ExecuteAsync(source, index, selector, cancellationToken); + : ExecuteAsync(source, index, cancellationToken, selector); - static async ValueTask> ExecuteAsync(TEnumerable source, int index, TSelector selector, CancellationToken cancellationToken) + static async ValueTask> ExecuteAsync(TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) { var enumerator = source.GetAsyncEnumerator(cancellationToken); try @@ -125,16 +125,16 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, TSelector selector, CancellationToken cancellationToken) + static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction { return index < 0 ? new ValueTask>(Option.None) - : ExecuteAsync(source, index, selector, cancellationToken); + : ExecuteAsync(source, index, cancellationToken, selector); - static async ValueTask> ExecuteAsync(TEnumerable source, int index, TSelector selector, CancellationToken cancellationToken) + static async ValueTask> ExecuteAsync(TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) { var enumerator = source.GetAsyncEnumerator(cancellationToken); try @@ -157,7 +157,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - static ValueTask> ElementAtAsync(this TEnumerable source, int index, TPredicate predicate, TSelector selector, CancellationToken cancellationToken) + static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -165,9 +165,9 @@ static ValueTask> ElementAtAsync>(Option.None) - : ExecuteAsync(source, index, predicate, selector, cancellationToken); + : ExecuteAsync(source, index, cancellationToken, predicate, selector); - static async ValueTask> ExecuteAsync(TEnumerable source, int index, TPredicate predicate, TSelector selector, CancellationToken cancellationToken) + static async ValueTask> ExecuteAsync(TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) { var enumerator = source.GetAsyncEnumerator(cancellationToken); try diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs index cb0afa961..7794746f9 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs @@ -5,7 +5,8 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - + + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this ReadOnlySpan source) => source switch diff --git a/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs index 630cdb85c..bd7a36a8b 100644 --- a/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs @@ -28,7 +28,7 @@ public static async ValueTask> FirstAsync> FirstAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -51,7 +51,7 @@ static async ValueTask> FirstAsync> FirstAtAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask> FirstAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -78,7 +78,7 @@ static async ValueTask> FirstAtAsync> FirstAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + static async ValueTask> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -100,7 +100,7 @@ static async ValueTask> FirstAsync> FirstAtAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + static async ValueTask> FirstAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -121,7 +121,7 @@ static async ValueTask> FirstAtAsync> FirstAsync(this TEnumerable source, TPredicate predicate, TSelector selector, CancellationToken cancellationToken) + static async ValueTask> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs index e97e96e42..5ac9e144a 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs @@ -5,6 +5,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore(false)] static Option Single(this ReadOnlySpan source) => source switch { diff --git a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs index 2f0b15eaf..1c11e84d5 100644 --- a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs @@ -16,23 +16,23 @@ public static ValueTask> SingleAsync> SingleAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken = default) + static ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.GetSingleAsync(predicate, cancellationToken); + => source.GetSingleAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueTask> SingleAtAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken = default) + static ValueTask> SingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.GetSingleAtAsync(predicate, cancellationToken); + => source.GetSingleAtAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> SingleAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken = default) + static async ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -43,7 +43,7 @@ static async ValueTask> SingleAsync> SingleAtAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken = default) + static async ValueTask> SingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -66,13 +66,13 @@ public ValueTask InvokeAsync(TSource item, CancellationToken cancellati } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> SingleAsync(this TEnumerable source, TPredicate predicate, TSelector selector, CancellationToken cancellationToken = default) + static async ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction { - var option = await source.GetSingleAsync(predicate, cancellationToken).ConfigureAwait(false); + var option = await source.GetSingleAsync(cancellationToken, predicate).ConfigureAwait(false); return await option.SelectAsync(selector, cancellationToken).ConfigureAwait(false); } @@ -100,7 +100,7 @@ static async ValueTask> GetSingleAsync> GetSingleAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask> GetSingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -134,7 +134,7 @@ static async ValueTask> GetSingleAsync> GetSingleAtAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask> GetSingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs index efdf0da8f..d3e204471 100644 --- a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs @@ -5,7 +5,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - public static bool SequenceEqual(this ReadOnlySpan first, TEnumerable second, IEqualityComparer? comparer = default) + static bool SequenceEqual(this ReadOnlySpan first, TEnumerable second, IEqualityComparer? comparer = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index 9be1537d7..57c87b757 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -10,11 +10,13 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) => source.Where(new FunctionWrapper(predicate)); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereEnumerable Where(this in ArraySegment source, TPredicate predicate = default) where TPredicate : struct, IFunction @@ -200,7 +202,7 @@ public TSource[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate, memoryPool); + => ((ReadOnlySpan)source.AsSpan()).ToArray(memoryPool, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index 07578d5b2..48f2e4473 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -200,7 +200,7 @@ void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAsync(CancellationToken cancellationToken = default) - => source.CountAsync(predicate, cancellationToken); + => source.CountAsync(cancellationToken, predicate); #endregion #region Quantifier @@ -287,32 +287,32 @@ public WhereAtEnumerable> ElementAtAsync(int index, CancellationToken cancellationToken = default) - => source.ElementAtAsync(index, predicate, cancellationToken); + => source.ElementAtAsync(index, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> FirstAsync(CancellationToken cancellationToken = default) - => source.FirstAsync(predicate, cancellationToken); + => source.FirstAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> SingleAsync(CancellationToken cancellationToken = default) - => source.SingleAsync(predicate, cancellationToken); + => source.SingleAsync(cancellationToken, predicate); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask ToArrayAsync(CancellationToken cancellationToken = default) - => source.ToArrayAsync(predicate, cancellationToken); + => source.ToArrayAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAsync(predicate, pool, cancellationToken); + => source.ToArrayAsync(pool, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) - => source.ToListAsync(predicate, cancellationToken); + => source.ToListAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(Func> keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) @@ -323,7 +323,7 @@ public ValueTask> ToDictionaryAsync(Func> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull where TKeySelector : struct, IAsyncFunction - => source.ToDictionaryAsync(keySelector, comparer, predicate, cancellationToken); + => source.ToDictionaryAsync(keySelector, comparer, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(Func> keySelector, Func> elementSelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) @@ -335,7 +335,7 @@ public ValueTask> ToDictionaryAsync where TElementSelector : struct, IAsyncFunction - => source.ToDictionaryAsync(keySelector, elementSelector, comparer, predicate, cancellationToken); + => source.ToDictionaryAsync(keySelector, elementSelector, comparer, cancellationToken, predicate); #endregion } @@ -345,70 +345,70 @@ public static ValueTask SumAsync(this where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs index 27253530d..4cad17a7f 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs @@ -253,7 +253,7 @@ public TSource[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(predicate, offset, count, memoryPool); + => source.ToArray(memoryPool, predicate, offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index 0c65025a5..f13985846 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -10,11 +10,13 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.Where(new FunctionWrapper(predicate)); - + + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereEnumerable Where(this ReadOnlyMemory source, TPredicate predicate = default) where TPredicate : struct, IFunction @@ -193,7 +195,7 @@ public TSource[] ToArray() => source.Span.ToArray(predicate); public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.Span.ToArray(predicate, memoryPool); + => source.Span.ToArray(memoryPool, predicate); public List ToList() => source.Span.ToList(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index 76b299555..9bb883d6d 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -9,11 +9,13 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereEnumerable> Where(this ReadOnlySpan source, Func predicate) => source.Where(new FunctionWrapper(predicate)); - + + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereEnumerable Where(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction @@ -139,7 +141,7 @@ public TSource[] ToArray() => source.ToArray(predicate); public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(predicate, memoryPool); + => source.ToArray(memoryPool, predicate); public List ToList() => source.ToList(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index 9a4161b2a..104a5a310 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -25,6 +25,7 @@ public static WhereEnumerable Whe where TPredicate : struct, IFunction => new(in source, predicate); + // [GeneratorBindings(source: "source", implementedTypes: "IValueEnumerable`2", extraTypeParameters: "TPredicate", extraParameters: "predicate")] [StructLayout(LayoutKind.Auto)] public readonly partial struct WhereEnumerable : IValueEnumerable.Enumerator> @@ -94,17 +95,18 @@ public void Dispose() #region Aggregation - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count() - => source.Count(predicate); + #endregion + #region Conversion + + WhereEnumerable AsValueEnumerable() + => this; + + WhereEnumerable AsEnumerable() + => this; #endregion #region Quantifier - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All() - => source.All(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) => All(new FunctionWrapper(predicate)); @@ -168,70 +170,10 @@ public WhereAtEnumerable> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereSelectEnumerable Select(TSelector selector = default) - where TSelector : struct, IFunction - => source.WhereSelect(predicate, selector); #endregion #region Element - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option ElementAt(int index) - => source.ElementAt(index, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option First() - => source.First(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option Single() -#pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() - => source.Single(predicate); -#pragma warning restore HLQ005 // Avoid Single() and SingleOrDefault() - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TSource[] ToArray() - => source.ToArray(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(predicate, memoryPool); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.ToList(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary(new FunctionWrapper(keySelector), comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - => source.ToDictionary(keySelector, comparer, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => source.ToDictionary(keySelector, elementSelector, comparer, predicate); #endregion } diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index c709b2b5c..58a1c4af3 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -204,7 +204,7 @@ public TSource[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => ValueReadOnlyCollectionExtensions.ToArray(source, predicate, memoryPool); + => ValueReadOnlyCollectionExtensions.ToArray(source, memoryPool, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index a0b787703..47eca0a51 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -198,7 +198,7 @@ public TSource[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(predicate, memoryPool); + => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(memoryPool, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index 997dc074c..4fbdf3a50 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -202,7 +202,7 @@ void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAsync(CancellationToken cancellationToken = default) - => source.CountAtAsync(predicate, cancellationToken); + => source.CountAtAsync(cancellationToken, predicate); #endregion #region Quantifier @@ -280,32 +280,32 @@ public WhereAtEnumerable> ElementAtAsync(int index, CancellationToken cancellationToken = default) - => source.ElementAtAtAsync(index, predicate, cancellationToken); + => source.ElementAtAtAsync(index, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> FirstAsync(CancellationToken cancellationToken = default) - => source.FirstAtAsync(predicate, cancellationToken); + => source.FirstAtAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> SingleAsync(CancellationToken cancellationToken = default) - => source.SingleAtAsync(predicate, cancellationToken); + => source.SingleAtAsync(cancellationToken, predicate); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask ToArrayAsync(CancellationToken cancellationToken = default) - => source.ToArrayAtAsync(predicate, cancellationToken); + => source.ToArrayAtAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAtAsync(predicate, pool, cancellationToken); + => source.ToArrayAtAsync(pool, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) - => source.ToListAtAsync(predicate, cancellationToken); + => source.ToListAtAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(Func> keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) @@ -316,7 +316,7 @@ public ValueTask> ToDictionaryAsync(Func> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull where TKeySelector : struct, IAsyncFunction - => source.ToDictionaryAtAsync(keySelector, comparer, predicate, cancellationToken); + => source.ToDictionaryAtAsync(keySelector, comparer, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(Func> keySelector, Func> elementSelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) @@ -328,7 +328,7 @@ public ValueTask> ToDictionaryAsync where TElementSelector : struct, IAsyncFunction - => source.ToDictionaryAtAsync(keySelector, elementSelector, comparer, predicate, cancellationToken); + => source.ToDictionaryAtAsync(keySelector, elementSelector, comparer, cancellationToken, predicate); #endregion } @@ -338,70 +338,70 @@ public static ValueTask SumAsync(this where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => source.source.SumAtAsync(source.predicate, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs index a1488e499..08e1fe93a 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs @@ -247,7 +247,7 @@ public TSource[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArrayAt(predicate, offset, count, memoryPool); + => source.ToArrayAt(memoryPool, predicate, offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index 29a558be8..62a92c5cc 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -11,11 +11,13 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereAtEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); - + + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereAtEnumerable WhereAt(this ReadOnlyMemory source, TPredicate predicate = default) where TPredicate : struct, IFunction @@ -184,7 +186,7 @@ public TSource[] ToArray() => source.Span.ToArrayAt(predicate); public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.Span.ToArrayAt(predicate, memoryPool); + => source.Span.ToArrayAt(memoryPool, predicate); public List ToList() => source.Span.ToListAt(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index 0c59826d2..e92d93d57 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -130,7 +130,7 @@ public TSource[] ToArray() => source.ToArrayAt(predicate); public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArrayAt(predicate, memoryPool); + => source.ToArrayAt(memoryPool, predicate); public List ToList() => source.ToListAt(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index 8e2d697e1..cef6a201d 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -201,7 +201,7 @@ public TSource[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArrayAt(predicate, memoryPool); + => source.ToArrayAt(memoryPool, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index 294ecdda6..951b226e4 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -200,7 +200,7 @@ public TSource[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => ToArrayAt(source, predicate, memoryPool); + => ToArrayAt(source, memoryPool, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index b17948e5c..93b50dd7f 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -214,7 +214,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate, selector, memoryPool); + => ((ReadOnlySpan)source.AsSpan()).ToArray(memoryPool, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index 82bd919bd..52b449141 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -227,7 +227,7 @@ void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAsync(CancellationToken cancellationToken = default) - => source.CountAsync(predicate, cancellationToken); + => source.CountAsync(cancellationToken, predicate); #endregion #region Quantifier @@ -314,32 +314,32 @@ public WhereSelectEnumerable> ElementAtAsync(int index, CancellationToken cancellationToken = default) - => source.ElementAtAsync(index, predicate, selector, cancellationToken); + => source.ElementAtAsync(index, cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> FirstAsync(CancellationToken cancellationToken = default) - => source.FirstAsync(predicate, selector, cancellationToken); + => source.FirstAsync(cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> SingleAsync(CancellationToken cancellationToken = default) - => source.SingleAsync(predicate, selector, cancellationToken); + => source.SingleAsync(cancellationToken, predicate, selector); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask ToArrayAsync(CancellationToken cancellationToken = default) - => source.ToArrayAsync(predicate, selector, cancellationToken); + => source.ToArrayAsync(cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAsync(predicate, selector, pool, cancellationToken); + => source.ToArrayAsync(pool, cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) - => source.ToListAsync(predicate, selector, cancellationToken); + => source.ToListAsync(cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(Func> keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) @@ -373,7 +373,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) @@ -381,7 +381,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) @@ -389,7 +389,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) @@ -397,7 +397,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) @@ -405,7 +405,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) @@ -413,7 +413,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) @@ -421,7 +421,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) @@ -429,7 +429,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) @@ -437,7 +437,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) @@ -445,7 +445,7 @@ public static ValueTask SumAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.predicate, source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); } } diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs index 21e819613..32dffa8b9 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs @@ -268,7 +268,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(predicate, selector, offset, count, pool); + => source.ToArray(pool, predicate, selector, offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index 723d0c1be..3a4375e94 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -218,7 +218,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.Span.ToArray(predicate, selector, memoryPool); + => source.Span.ToArray(memoryPool, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index dbd725365..bc5351e19 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -94,7 +94,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(predicate, selector, memoryPool); + => source.ToArray(memoryPool, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index 3bc24ed8e..26cb5a182 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -222,7 +222,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(predicate, selector, pool); + => source.ToArray(pool, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index ca1f5d712..69e770be4 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -222,7 +222,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => ValueReadOnlyCollectionExtensions.ToArray(source, predicate, selector, pool); + => ValueReadOnlyCollectionExtensions.ToArray(source, pool, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 384932e46..336592ab6 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -20,6 +20,12 @@ $(NoWarn);8600;8601;8602;8603;8604 + + + + + + @@ -77,6 +83,7 @@ + diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 55de6ce7c..86f2b3613 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -211,7 +211,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => ((ReadOnlySpan)source.AsSpan()).ToArray(selector, pool); + => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs index 48e010b89..97863d6d0 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -236,30 +236,30 @@ public SelectAtEnumerable> ElementAtAsync(int index, CancellationToken cancellationToken = default) - => source.ElementAtAsync(index, selector, cancellationToken); + => source.ElementAtAsync(index, cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> FirstAsync(CancellationToken cancellationToken = default) - => source.FirstAsync(selector, cancellationToken); + => source.FirstAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> SingleAsync(CancellationToken cancellationToken = default) - => source.SingleAsync(selector, cancellationToken); + => source.SingleAsync(cancellationToken, selector); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask ToArrayAsync(CancellationToken cancellationToken = default) - => source.ToArrayAsync(selector, cancellationToken); + => source.ToArrayAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAsync(selector, pool, cancellationToken); + => source.ToArrayAsync(pool, cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) - => source.ToListAsync(selector, cancellationToken); + => source.ToListAsync(cancellationToken, selector); #endregion } @@ -269,70 +269,70 @@ public static ValueTask SumAsync where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAsync(source.selector, cancellationToken); + => source.source.SumAsync(cancellationToken, source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs index 738b45c69..1c7a68eca 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs @@ -275,7 +275,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(selector, offset, Count, pool); + => source.ToArray(pool, selector, offset, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index e72097bd4..f08446e21 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -11,11 +11,13 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.Select>(new FunctionWrapper(selector)); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectEnumerable Select(this ReadOnlyMemory source, TSelector selector = default) where TSelector : struct, IFunction @@ -203,7 +205,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.Span.ToArray(selector, pool); + => source.Span.ToArray(pool, selector); public List ToList() => source.Span.ToList(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index 7b9caf95e..4ab310a89 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -9,11 +9,13 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectEnumerable> Select(this ReadOnlySpan source, Func selector) => source.Select>(new FunctionWrapper(selector)); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectEnumerable Select(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction @@ -102,7 +104,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(selector, pool); + => source.ToArray(pool, selector); public List ToList() => source.ToList(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index 1792f52a2..7049b8d40 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -159,7 +159,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(selector, pool); + => source.ToArray(pool, selector); public List ToList() => source.ToList(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index 8f1905fca..c00ad0465 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -196,7 +196,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => ValueReadOnlyCollectionExtensions.ToArray(source, selector, pool); + => ValueReadOnlyCollectionExtensions.ToArray(source, pool, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 877c9f621..375a7a65a 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -205,7 +205,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(selector, pool); + => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index a76137f3a..7bcf61c44 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -238,30 +238,30 @@ public SelectAtEnumerable> ElementAtAsync(int index, CancellationToken cancellationToken = default) - => source.ElementAtAtAsync(index, selector, cancellationToken); + => source.ElementAtAtAsync(index, cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> FirstAsync(CancellationToken cancellationToken = default) - => source.FirstAtAsync(selector, cancellationToken); + => source.FirstAtAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> SingleAsync(CancellationToken cancellationToken = default) - => source.SingleAtAsync(selector, cancellationToken); + => source.SingleAtAsync(cancellationToken, selector); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask ToArrayAsync(CancellationToken cancellationToken = default) - => source.ToArrayAtAsync(selector, cancellationToken); + => source.ToArrayAtAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAtAsync(selector, pool, cancellationToken); + => source.ToArrayAtAsync(pool, cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) - => source.ToListAtAsync(selector, cancellationToken); + => source.ToListAtAsync(cancellationToken, selector); #endregion } @@ -271,70 +271,70 @@ public static ValueTask SumAsync where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => source.source.SumAtAsync(source.selector, cancellationToken); + => source.source.SumAtAsync(cancellationToken, source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs index cdc96ffeb..6a2db9ad6 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs @@ -295,7 +295,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArrayAt(selector, offset, Count, pool); + => source.ToArrayAt(pool, selector, offset, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index e3ef90e72..97e1bf9fc 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -11,11 +11,13 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectAtEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectAtEnumerable SelectAt(this ReadOnlyMemory source, TSelector selector = default) where TSelector : struct, IFunction @@ -197,7 +199,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.Span.ToArrayAt(selector, pool); + => source.Span.ToArrayAt(pool, selector); public List ToList() => source.Span.ToListAt(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index e1a1903cc..e26d28541 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -9,11 +9,13 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectAtEnumerable> Select(this ReadOnlySpan source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectAtEnumerable SelectAt(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction @@ -102,7 +104,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArrayAt(selector, pool); + => source.ToArrayAt(pool, selector); public List ToList() => source.ToListAt(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index 5a113de9d..64bcd4454 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -169,7 +169,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArrayAt(selector, pool); + => source.ToArrayAt(pool, selector); public List ToList() => source.ToListAt(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index 3c1eedf76..0e22d4ebc 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -205,7 +205,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => ToArrayAt(source, selector, pool); + => ToArrayAt(source, pool, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs index 11a84a12b..ace8dec3b 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs @@ -10,14 +10,14 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + [GeneratorIgnore(true)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ReadOnlySpan source, Func, Vector> vectorSelector, Func selector) where TSource : struct where TResult : struct => source.SelectVector, Vector>, FunctionWrapper>(new FunctionWrapper, Vector>(vectorSelector), new FunctionWrapper(selector)); - [GeneratorIgnore] + [GeneratorIgnore(true)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectVectorContext SelectVector(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction, Vector>, IFunction @@ -25,7 +25,7 @@ static SpanSelectVectorContext SelectVec where TResult : struct => source.SelectVector(selector, selector); - [GeneratorIgnore] + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectVectorContext SelectVector(this ReadOnlySpan source, TVectorSelector vectorSelector = default, TSelector selector = default) where TVectorSelector : struct, IFunction, Vector> @@ -90,7 +90,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArrayVector(vectorSelector, selector, pool); + => source.ToArrayVector(pool, vectorSelector, selector); public List ToList() => source.ToListVector(vectorSelector, selector); diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs index e7093ea5f..8d8277415 100644 --- a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs @@ -5,10 +5,12 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool All(this ReadOnlySpan source, Func predicate) => source.All(new FunctionWrapper(predicate)); - + + [GeneratorIgnore(false)] static bool All(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { @@ -20,10 +22,12 @@ static bool All(this ReadOnlySpan source, TPredica return true; } + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool All(this ReadOnlySpan source, Func predicate) => source.AllAt(new FunctionWrapper(predicate)); - + + [GeneratorIgnore(false)] static bool AllAt(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs index cb40ee140..eebd88585 100644 --- a/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs @@ -5,16 +5,19 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - + + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool Any(this ReadOnlySpan source) => source.Length is not 0; + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool Any(this in ReadOnlySpan source, Func predicate) => source.Any(new FunctionWrapper(predicate)); - + + [GeneratorIgnore(false)] static bool Any(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { @@ -26,10 +29,12 @@ static bool Any(this ReadOnlySpan source, TPredica return false; } + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool Any(this in ReadOnlySpan source, Func predicate) => source.AnyAt(new FunctionWrapper(predicate)); + [GeneratorIgnore(false)] static bool AnyAt(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.Span.cs b/NetFabric.Hyperlinq/Quantifier/Any/Any.Span.cs deleted file mode 100644 index 97b47ea5f..000000000 --- a/NetFabric.Hyperlinq/Quantifier/Any/Any.Span.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool Any(this Span source) - => source.Length is not 0; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool Any(this Span source, Func predicate) - => source.Any(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool Any(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source).Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool Any(this Span source, Func predicate) - => source.AnyAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool AnyAt(this Span source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source).AnyAt(predicate); - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs index 7d02cad93..df47f3c35 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs @@ -17,6 +17,7 @@ static bool Contains(this TList source, TSource value, IEquality if (Utils.UseDefault(comparer)) { + // ReSharper disable once HeapView.BoxingAllocation if (offset is 0 && count == source.Count && source is ICollection collection) return collection.Contains(value); diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs index 0a87fcc84..c8482fc4e 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs @@ -5,6 +5,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore(false)] static bool Contains(this ReadOnlySpan source, TSource value, IEqualityComparer? comparer = default) { return source switch diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs index 3f4ac1320..2a4ac1fa7 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -10,7 +10,8 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - + + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryDistinctEnumerable Distinct( this ReadOnlyMemory source, diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs index 77b6027f1..e40dbed74 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs @@ -8,7 +8,8 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - + + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanDistinctEnumerable Distinct( this ReadOnlySpan source, diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs index 1c551c8e8..cf6290c33 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs @@ -29,7 +29,7 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, TPredicate predicate, ArrayPool arrayPool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -54,7 +54,7 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAtAsync(this TEnumerable source, TPredicate predicate, ArrayPool arrayPool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -82,7 +82,7 @@ static async ValueTask> ToArrayBuilderAtAsync> ToArrayBuilderAsync(this TEnumerable source, TSelector selector, ArrayPool arrayPool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -105,7 +105,7 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAtAsync(this TEnumerable source, TSelector selector, ArrayPool arrayPool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -131,7 +131,7 @@ static async ValueTask> ToArrayBuilderAtAsync> ToArrayBuilderAsync(this TEnumerable source, TPredicate predicate, TSelector selector, ArrayPool arrayPool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs index a1e598724..da3a548fa 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - static LargeArrayBuilder ToArrayBuilder(in TList source, TPredicate predicate, int offset, int count, ArrayPool pool) + static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate: struct, IFunction { @@ -21,7 +21,7 @@ static LargeArrayBuilder ToArrayBuilder(in return builder; } - static LargeArrayBuilder ToArrayBuilderAt(in TList source, TPredicate predicate, int offset, int count, ArrayPool pool) + static LargeArrayBuilder ToArrayBuilderAt(in TList source, ArrayPool pool, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate: struct, IFunction { @@ -48,7 +48,7 @@ static LargeArrayBuilder ToArrayBuilderAt(i return builder; } - static LargeArrayBuilder ToArrayBuilder(in TList source, TPredicate predicate, TSelector selector, int offset, int count, ArrayPool pool) + static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, TPredicate predicate, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector: struct, IFunction where TPredicate: struct, IFunction diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs index 565a2c716..ebf472a96 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, TPredicate predicate, ArrayPool arrayPool) + static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, TPredicate predicate) where TPredicate: struct, IFunction { var builder = new LargeArrayBuilder(arrayPool); @@ -18,7 +18,7 @@ static LargeArrayBuilder ToArrayBuilder(ReadOnlySp return builder; } - static LargeArrayBuilder ToArrayBuilderAt(ReadOnlySpan source, TPredicate predicate, ArrayPool arrayPool) + static LargeArrayBuilder ToArrayBuilderAt(ReadOnlySpan source, ArrayPool arrayPool, TPredicate predicate) where TPredicate: struct, IFunction { var builder = new LargeArrayBuilder(arrayPool); @@ -31,7 +31,7 @@ static LargeArrayBuilder ToArrayBuilderAt(ReadOnly return builder; } - static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, TPredicate predicate, TSelector selector, ArrayPool arrayPool) + static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, TPredicate predicate, TSelector selector) where TPredicate: struct, IFunction where TSelector: struct, IFunction { diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs index aa28964d1..24e54987b 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs @@ -17,7 +17,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilder(TEnumerable source, TPredicate predicate, ArrayPool arrayPool) + static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction @@ -33,7 +33,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderAt(TEnumerable source, TPredicate predicate, ArrayPool arrayPool) + static LargeArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction @@ -49,7 +49,7 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, TSelector selector, ArrayPool arrayPool) + static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -61,7 +61,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderAt(TEnumerable source, TSelector selector, ArrayPool arrayPool) + static LargeArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -76,7 +76,7 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, TPredicate predicate, TSelector selector, ArrayPool arrayPool) + static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs index a23dcd2de..2a24bd922 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs @@ -52,7 +52,7 @@ public static async ValueTask> ToArrayBuilderAsync ToArrayBuilderAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask ToArrayBuilderAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction @@ -77,7 +77,7 @@ static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, TPredicate predicate, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction @@ -104,7 +104,7 @@ static async ValueTask> ToArrayBuilderAsync ToArrayBuilderAtAsync(this TEnumerable source, TPredicate predicate, CancellationToken cancellationToken) + static async ValueTask ToArrayBuilderAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction @@ -132,7 +132,7 @@ static async ValueTask ToArrayBuilderAtAsync> ToArrayBuilderAtAsync(this TEnumerable source, TPredicate predicate, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction @@ -162,7 +162,7 @@ static async ValueTask> ToArrayBuilderAtAsync ToArrayBuilderAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + static async ValueTask ToArrayBuilderAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector: struct, IAsyncFunction @@ -185,7 +185,7 @@ static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, TSelector selector, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector: struct, IAsyncFunction @@ -210,7 +210,7 @@ static async ValueTask> ToArrayBuilderAsync ToArrayBuilderAtAsync(this TEnumerable source, TSelector selector, CancellationToken cancellationToken) + static async ValueTask ToArrayBuilderAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector: struct, IAsyncFunction @@ -236,7 +236,7 @@ static async ValueTask ToArrayBuilderAtAsync> ToArrayBuilderAtAsync(this TEnumerable source, TSelector selector, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector: struct, IAsyncFunction @@ -264,7 +264,7 @@ static async ValueTask> ToArrayBuilderAtAsync ToArrayBuilderAsync(this TEnumerable source, TPredicate predicate, TSelector selector, CancellationToken cancellationToken) + static async ValueTask ToArrayBuilderAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction @@ -290,7 +290,7 @@ static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, TPredicate predicate, TSelector selector, MemoryPool pool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Utils/Generator/GeneratorIgnoreAttribute.cs b/NetFabric.Hyperlinq/Utils/Generator/GeneratorIgnoreAttribute.cs deleted file mode 100644 index d7e78203d..000000000 --- a/NetFabric.Hyperlinq/Utils/Generator/GeneratorIgnoreAttribute.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; - -namespace NetFabric.Hyperlinq -{ - [ExcludeFromCodeCoverage] - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method)] - public sealed class GeneratorIgnoreAttribute : Attribute - { - public bool Value { get; } - - public GeneratorIgnoreAttribute(bool value = true) - => Value = value; - } -} \ No newline at end of file From a4baad316d891188b2846b25023f9836dece7c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Sat, 13 Mar 2021 23:12:13 +0000 Subject: [PATCH 20/61] Upgrade to .NET 6.0 (#349) --- .github/workflows/dotnetcore.yml | 6 +++--- .../NetFabric.Hyperlinq.Benchmarks.csproj | 2 +- ...ic.Hyperlinq.SourceGenerator.UnitTests.csproj | 2 +- .../NetFabric.Hyperlinq.UnitTests.csproj | 2 +- .../Generic/PriorityQueueExtensions.cs | 16 ++++++++-------- NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index d12ba49b3..a6013e986 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -12,18 +12,18 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1.7.2 with: - dotnet-version: '5.0.x' + dotnet-version: '6.0.100-preview.2.21155.3' - name: Test source generator run: dotnet test ./NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj - name: Build solution run: dotnet build - name: Tests and coverage - run: dotnet test ./NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj -f:net5.0 -p:CollectCoverage=true -p:CoverletOutputFormat=lcov -p:CoverletOutput=TestResults/ + run: dotnet test ./NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj -f:net6.0 -p:CollectCoverage=true -p:CoverletOutputFormat=lcov -p:CoverletOutput=TestResults/ - name: Publish coverage report to coveralls.io uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./NetFabric.Hyperlinq.UnitTests/TestResults/coverage.net5.0.info + path-to-lcov: ./NetFabric.Hyperlinq.UnitTests/TestResults/coverage.net6.0.info diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index 7cd5c5a5e..e6020590c 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -1,7 +1,7 @@  Exe - net5.0 + net6.0 false true diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj index ce285556c..f4c4fe6cb 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 false diff --git a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj index a94851a7d..78f63b5ea 100644 --- a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj +++ b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj @@ -1,7 +1,7 @@  - net461;netcoreapp2.1;netcoreapp3.1;net5.0 + net461;netcoreapp2.1;netcoreapp3.1;net6.0 false diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs index 042612cc9..292eeb24d 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs @@ -1,4 +1,4 @@ -#if NET60_OR_GREATER +#if NET6_0_OR_GREATER using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -9,18 +9,18 @@ namespace NetFabric.Hyperlinq public static class PriorityQueueExtensions { - // PriorityQueue is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - + // PriorityQueue.UnorderedItemsCollection is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator + [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, PriorityQueue.Enumerator, PriorityQueue.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this PriorityQueue source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, PriorityQueue.Enumerator, TSource, GetEnumerator>(source); + public static ReadOnlyCollectionExtensions.ValueEnumerable.UnorderedItemsCollection, PriorityQueue.UnorderedItemsCollection.Enumerator, PriorityQueue.UnorderedItemsCollection.Enumerator, (TElement Element, TPriority Priority), GetEnumerator, GetEnumerator> AsValueEnumerable(this PriorityQueue.UnorderedItemsCollection source) + => ReadOnlyCollectionExtensions.AsValueEnumerable.UnorderedItemsCollection, PriorityQueue.UnorderedItemsCollection.Enumerator, (TElement Element, TPriority Priority), GetEnumerator>(source); [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, PriorityQueue.Enumerator> + public readonly struct GetEnumerator + : IFunction.UnorderedItemsCollection, PriorityQueue.UnorderedItemsCollection.Enumerator> { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public PriorityQueue.Enumerator Invoke(PriorityQueue source) + public PriorityQueue.UnorderedItemsCollection.Enumerator Invoke(PriorityQueue.UnorderedItemsCollection source) => source.GetEnumerator(); } } diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 336592ab6..a645e3c48 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -1,7 +1,7 @@  - net461;netstandard2.0;netcoreapp3.1;net5.0 + net461;netstandard2.0;netcoreapp3.1;net5.0;net6.0 NetFabric.Hyperlinq NetFabric.Hyperlinq High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays, Memory and Span. From cc437fc010e564e3608805fb3a2d6e60d4179fc5 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sun, 14 Mar 2021 11:09:27 +0000 Subject: [PATCH 21/61] Fix benchmarks --- Benchmarks/AllBenchmarks.md | 68 +++++++++---------- Benchmarks/ArrayIterationBenchmarks.md | 36 +++++----- .../Benchmarks/ArrayIterationBenchmarks.cs | 21 +++--- .../BenchmarksBase.cs | 2 +- .../NetFabric.Hyperlinq.Benchmarks.csproj | 2 +- NuGet.config | 12 ++-- 6 files changed, 70 insertions(+), 71 deletions(-) diff --git a/Benchmarks/AllBenchmarks.md b/Benchmarks/AllBenchmarks.md index 79479cd75..9ca9c4cad 100644 --- a/Benchmarks/AllBenchmarks.md +++ b/Benchmarks/AllBenchmarks.md @@ -4,7 +4,7 @@ [AllBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + .NET 6.0 : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Job=.NET 6.0 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 587.8 ns | 1.31 ns | 1.10 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 192.6 ns | 0.41 ns | 0.37 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 744.7 ns | 1.03 ns | 0.92 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 198.2 ns | 0.44 ns | 0.34 ns | 0.27 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 745.6 ns | 2.88 ns | 2.55 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 200.8 ns | 1.18 ns | 0.98 ns | 0.27 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 749.5 ns | 6.41 ns | 6.00 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 978.6 ns | 2.46 ns | 2.30 ns | 1.31 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,159.0 ns | 3.01 ns | 2.82 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 317.9 ns | 0.81 ns | 0.75 ns | 0.15 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 589.4 ns | 3.72 ns | 3.11 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 538.8 ns | 1.38 ns | 1.23 ns | 0.91 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 587.3 ns | 1.53 ns | 1.44 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 514.3 ns | 2.35 ns | 1.83 ns | 0.88 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 537.9 ns | 1.32 ns | 1.10 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 925.7 ns | 2.96 ns | 2.31 ns | 1.72 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,057.2 ns | 3.16 ns | 2.95 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 345.4 ns | 0.48 ns | 0.45 ns | 0.17 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 608.4 ns | 8.10 ns | 7.96 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 221.1 ns | 0.87 ns | 0.77 ns | 0.36 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 781.2 ns | 9.45 ns | 7.38 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 208.2 ns | 1.49 ns | 1.17 ns | 0.27 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 770.5 ns | 4.33 ns | 3.84 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 212.3 ns | 1.64 ns | 1.28 ns | 0.28 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 752.9 ns | 10.18 ns | 9.52 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 920.3 ns | 13.31 ns | 11.79 ns | 1.22 | 0.02 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,920.2 ns | 8.37 ns | 6.99 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 279.0 ns | 1.49 ns | 1.40 ns | 0.15 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 537.2 ns | 10.22 ns | 11.77 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 608.8 ns | 5.31 ns | 4.70 ns | 1.13 | 0.03 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 528.5 ns | 3.67 ns | 3.26 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 556.2 ns | 3.01 ns | 2.67 ns | 1.05 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 581.1 ns | 11.64 ns | 10.32 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 930.1 ns | 15.48 ns | 15.20 ns | 1.60 | 0.03 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,856.0 ns | 36.36 ns | 34.01 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 302.0 ns | 1.03 ns | 0.86 ns | 0.16 | 0.00 | 0.0191 | - | - | 40 B | diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 0a8544489..6eae55d50 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -4,7 +4,7 @@ [ArrayIterationBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,24 +14,24 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + .NET 6.0 : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Job=.NET 6.0 Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | -|----------------------------- |--------- |----------:|----------:|----------:|------:| -| Foreach | 10000000 | 5.695 ms | 0.0092 ms | 0.0086 ms | 1.00 | -| For | 10000000 | 4.515 ms | 0.0097 ms | 0.0086 ms | 0.79 | -| For_Unsafe | 10000000 | 4.460 ms | 0.0114 ms | 0.0107 ms | 0.78 | -| ForAdamczewski | 10000000 | 4.371 ms | 0.0168 ms | 0.0149 ms | 0.77 | -| ForAdamczewskiUnsafe | 10000000 | 3.878 ms | 0.0153 ms | 0.0128 ms | 0.68 | -| Span | 10000000 | 4.459 ms | 0.0083 ms | 0.0069 ms | 0.78 | -| Memory | 10000000 | 5.725 ms | 0.0208 ms | 0.0184 ms | 1.01 | -| ArraySegment_Foreach | 10000000 | 28.060 ms | 0.0959 ms | 0.0748 ms | 4.93 | -| ArraySegment_For | 10000000 | 5.701 ms | 0.0169 ms | 0.0150 ms | 1.00 | -| ArraySegment_Wrapper_Foreach | 10000000 | 14.684 ms | 0.0342 ms | 0.0320 ms | 2.58 | +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | +|----------------------------- |--------- |----------:|----------:|----------:|------:|--------:| +| Foreach | 10000000 | 4.859 ms | 0.0885 ms | 0.0828 ms | 1.00 | 0.00 | +| For | 10000000 | 4.807 ms | 0.0397 ms | 0.0352 ms | 0.99 | 0.02 | +| For_Unsafe | 10000000 | 4.818 ms | 0.0396 ms | 0.0351 ms | 0.99 | 0.02 | +| ForAdamczewski | 10000000 | 4.587 ms | 0.0227 ms | 0.0189 ms | 0.95 | 0.02 | +| ForAdamczewskiUnsafe | 10000000 | 4.121 ms | 0.0432 ms | 0.0383 ms | 0.85 | 0.02 | +| Span | 10000000 | 4.771 ms | 0.0216 ms | 0.0191 ms | 0.98 | 0.02 | +| Memory | 10000000 | 4.804 ms | 0.0539 ms | 0.0504 ms | 0.99 | 0.02 | +| ArraySegment_Foreach | 10000000 | 28.829 ms | 0.2076 ms | 0.1942 ms | 5.93 | 0.10 | +| ArraySegment_For | 10000000 | 8.417 ms | 0.0617 ms | 0.0578 ms | 1.73 | 0.03 | +| ArraySegment_Wrapper_Foreach | 10000000 | 15.080 ms | 0.0738 ms | 0.0690 ms | 3.10 | 0.05 | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs index b0bbc8c95..43e93bff0 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs @@ -1,16 +1,15 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Jobs; using System; -using System.Collections.Generic; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks { - [SimpleJob(RuntimeMoniker.NetCoreApp50)] + [SimpleJob(RuntimeMoniker.Net60)] public class ArrayIterationBenchmarks { const int seed = 2982; - int[] array; + int[]? array; ReadOnlyMemory memory; ArraySegment segment; @@ -29,7 +28,7 @@ public void GlobalSetup() public int Foreach() { var sum = 0; - foreach (var item in array) + foreach (var item in array!) sum += item; return sum; } @@ -37,11 +36,11 @@ public int Foreach() [Benchmark] public int For() { - var source = array; + var source = array!; var sum = 0; for (var index = 0; index < source.Length; index++) { - var item = array[index]; + var item = source[index]; sum += item; } return sum; @@ -50,7 +49,7 @@ public int For() [Benchmark] public unsafe int For_Unsafe() { - var end = array.Length; + var end = array!.Length; var sum = 0; fixed (int* source = array) { @@ -66,8 +65,8 @@ public unsafe int For_Unsafe() [Benchmark] public int ForAdamczewski() { - var source = array; - var len = array.Length; + var source = array!; + var len = source.Length; var sum1 = 0; var sum2 = 0; for (var index = 0; index < len; index += 2) @@ -88,7 +87,7 @@ public unsafe int ForAdamczewskiUnsafe() { fixed (int* source = array) { - var len = array.Length; + var len = array!.Length; var sum1 = 0; var sum2 = 0; for (var index = 0; index < len; index += 2) @@ -108,7 +107,7 @@ public unsafe int ForAdamczewskiUnsafe() [Benchmark] public int Span() { - var source = array.AsSpan(); + var source = array!.AsSpan(); var sum = 0; for (var index = 0; index < source.Length; index++) { diff --git a/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs b/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs index 0d9e039b9..b1ffcee5a 100644 --- a/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs +++ b/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs @@ -9,7 +9,7 @@ namespace NetFabric.Hyperlinq.Benchmarks //[SimpleJob(RuntimeMoniker.Net48, baseline: true)] //[SimpleJob(RuntimeMoniker.NetCoreApp21)] //[SimpleJob(RuntimeMoniker.NetCoreApp31)] - [SimpleJob(RuntimeMoniker.NetCoreApp50)] + [SimpleJob(RuntimeMoniker.Net60)] [MemoryDiagnoser] public abstract class BenchmarksBase { diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index e6020590c..d468ec23f 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -17,7 +17,7 @@ - + diff --git a/NuGet.config b/NuGet.config index c10b6783c..f3c7e1ed8 100755 --- a/NuGet.config +++ b/NuGet.config @@ -1,4 +1,4 @@ - + @@ -8,9 +8,9 @@ - - - - + + + + - \ No newline at end of file + From 0fc76de9ef96a027c3eef02553625103b7e9391e Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sun, 14 Mar 2021 11:40:29 +0000 Subject: [PATCH 22/61] Fix Where for ValueEnumerable --- .../Where/Where/Where.ValueEnumerable.cs | 73 ++++++++++++++++++- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index 104a5a310..7a371fa27 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -25,7 +25,7 @@ public static WhereEnumerable Whe where TPredicate : struct, IFunction => new(in source, predicate); - // [GeneratorBindings(source: "source", implementedTypes: "IValueEnumerable`2", extraTypeParameters: "TPredicate", extraParameters: "predicate")] + //[GeneratorBindings(source: "source", sourceImplements: "IValueEnumerable`2", extraTypeParameters: "TPredicate", extraParameters: "predicate")] [StructLayout(LayoutKind.Auto)] public readonly partial struct WhereEnumerable : IValueEnumerable.Enumerator> @@ -95,6 +95,10 @@ public void Dispose() #region Aggregation + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count() + => source.Count(predicate); + #endregion #region Conversion @@ -104,9 +108,48 @@ WhereEnumerable AsValueEnumerable WhereEnumerable AsEnumerable() => this; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TSource[] ToArray() + => source.ToArray(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IMemoryOwner ToArray(MemoryPool memoryPool) + => source.ToArray(memoryPool, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => source.ToList(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) + where TKey : notnull + => ToDictionary(new FunctionWrapper(keySelector), comparer); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) + where TKey : notnull + where TKeySelector : struct, IFunction + => source.ToDictionary(keySelector, comparer, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) + where TKey : notnull + => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) + where TKey : notnull + where TKeySelector : struct, IFunction + where TElementSelector : struct, IFunction + => source.ToDictionary(keySelector, elementSelector, comparer, predicate); + #endregion #region Quantifier + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool All() + => source.All(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) => All(new FunctionWrapper(predicate)); @@ -167,14 +210,36 @@ public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.WhereAt>(new PredicatePredicateAtCombination(this.predicate, predicate)); - + #endregion #region Projection - + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public WhereSelectEnumerable> Select(Func selector) + => Select>(new FunctionWrapper(selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public WhereSelectEnumerable Select(TSelector selector = default) + where TSelector : struct, IFunction + => source.WhereSelect(predicate, selector); + #endregion #region Element - + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Option ElementAt(int index) + => source.ElementAt(index, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Option First() + => source.First(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Option Single() +#pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() + => source.Single(predicate); +#pragma warning restore HLQ005 // Avoid Single() and SingleOrDefault() + #endregion } From f4146ed10c7b07b151ed1c4eb1627c3cd2574ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Mon, 15 Mar 2021 09:46:28 +0000 Subject: [PATCH 23/61] Test NetFabric.Hyperlinq.Immutable (#350) --- .../NetFabric.Hyperlinq.UnitTests.csproj | 5 +---- NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj index 78f63b5ea..3c4481d54 100644 --- a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj +++ b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj @@ -4,10 +4,6 @@ net461;netcoreapp2.1;netcoreapp3.1;net6.0 false - - - - @@ -29,6 +25,7 @@ + diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index a645e3c48..67c9f44fd 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -21,13 +21,13 @@ - - - + - + + + From 6199b1aeb4252762b635f72028c5deba75b23edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Mon, 15 Mar 2021 18:41:03 +0000 Subject: [PATCH 24/61] Refactor handling of IReadOnlyList (#351) * Refactor handling of IReadOnlyList * Fixes --- Benchmarks/SingleBenchmarks.md | 47 +-- .../Benchmarks/AllBenchmarks.cs | 1 - .../Benchmarks/AnyBenchmarks.cs | 1 - .../Benchmarks/AnyPredicateBenchmarks.cs | 1 - .../Benchmarks/ContainsBenchmarks.cs | 1 - .../Benchmarks/ContainsComparerBenchmarks.cs | 1 - .../Benchmarks/CountBenchmarks.cs | 1 - .../Benchmarks/ElementAtBenchmarks.cs | 1 - .../Benchmarks/EmptyBenchmarks.cs | 4 - .../Benchmarks/FirstBenchmarks.cs | 1 - .../Benchmarks/RangeBenchmarks.cs | 3 - .../Benchmarks/RepeatBenchmarks.cs | 3 - .../Benchmarks/ReturnBenchmarks.cs | 4 - .../Benchmarks/SelectCountBenchmarks.cs | 1 - .../Benchmarks/SelectSumBenchmarks.cs | 1 - .../Benchmarks/SelectToArrayBenchmarks.cs | 1 - .../Benchmarks/SelectToListBenchmarks.cs | 13 +- .../Benchmarks/SingleBenchmarks.cs | 3 - .../Benchmarks/SumBenchmarks.cs | 1 - .../Benchmarks/ToArrayBenchmarks.cs | 1 - .../Benchmarks/ToListBenchmarks.cs | 1 - .../Benchmarks/WhereFirstBenchmarks.cs | 2 - .../Benchmarks/WhereSelectCountBenchmarks.cs | 1 - .../Benchmarks/WhereSingleBenchmarks.cs | 2 - .../Benchmarks/WhereToArrayBenchmarks.cs | 1 - .../Benchmarks/WhereToListBenchmarks.cs | 1 - .../BenchmarksBase.cs | 1 - NetFabric.Hyperlinq.Benchmarks/Program.cs | 2 +- .../SequentialBenchmarksBase.cs | 4 +- .../Utils/TestAsyncEnumerable.cs | 3 +- .../GenerateSourceTests.cs | 6 +- .../Results/Select.ArraySegment.Any.cs | 4 +- ...adOnlyList.cs => Any.ValueReadOnlyList.cs} | 8 +- ...NetFabric.Hyperlinq.SourceGenerator.csproj | 1 - .../OverloadsGenerator.cs | 18 +- .../Utils/MethodSymbolExtensions.cs | 6 +- .../Utils/StringExtensions.cs | 28 +- .../Utils/SymbolExtensions.cs | 4 +- .../CountAsync.AsyncValueEnumerable.Tests.cs | 12 +- .../SumAsync.AsyncValueEnumerable.Tests.cs | 8 +- ...ncEnumerable.AsyncValueEnumerable.Tests.cs | 5 +- ...ValueEnumerable.ValueReadOnlyList.Tests.cs | 128 +++++++- ...ToArrayAsync.AsyncValueEnumerable.Tests.cs | 48 +-- .../ToListAsync.AsyncValueEnumerable.Tests.cs | 24 +- ...ementAtAsync.AsyncValueEnumerable.Tests.cs | 96 +++--- .../FirstAsync.AsyncValueEnumerable.Tests.cs | 72 ++--- .../SingleAsync.AsyncValueEnumerable.Tests.cs | 88 +++--- .../Where/Where.AsyncValueEnumerable.Tests.cs | 8 +- .../WhereAt.AsyncValueEnumerable.Tests.cs | 8 +- .../WhereSelect.AsyncValueEnumerable.Tests.cs | 8 +- .../Generation/ValueEnumerable/Range.Tests.cs | 16 - .../Skip/Skip.AsyncValueEnumerable.Tests.cs | 12 +- .../Take/Take.AsyncValueEnumerable.Tests.cs | 8 +- .../All/All.AsyncValueEnumerable.Tests.cs | 8 +- .../Any/Any.AsyncValueEnumerable.Tests.cs | 12 +- .../Contains.AsyncValueEnumerable.Tests.cs | 32 +- .../Distinct.AsyncValueEnumerable.Tests.cs | 20 +- .../Utils/Wrappers/Wrap.AsValueList.cs | 4 +- .../Wrappers/Wrap.AsValueReadOnlyList.cs | 4 +- ...OnlyList.cs => Count.ValueReadOnlyList.cs} | 8 +- ...adOnlyList.cs => Sum.ValueReadOnlyList.cs} | 16 +- ...sAsyncValueEnumerable'1.AsyncEnumerable.cs | 8 +- .../AsValueEnumerable.ReadOnlyList.cs | 47 ++- .../AsValueEnumerable.ValueReadOnlyList.cs | 257 +++++++++++++++++ .../AsValueEnumerable.ValuesReadOnlyList.cs | 21 -- ...lyList.cs => ToArray.ValueReadOnlyList.cs} | 13 +- ...t.cs => ToDictionary.ValueReadOnlyList.cs} | 14 +- ...nlyList.cs => ToList.ValueReadOnlyList.cs} | 8 +- ...List.cs => ElementAt.ValueReadOnlyList.cs} | 7 +- ...OnlyList.cs => First.ValueReadOnlyList.cs} | 5 +- ...nlyList.cs => Single.ValueReadOnlyList.cs} | 5 +- ...OnlyList.cs => Where.ValueReadOnlyList.cs} | 9 +- ...lyList.cs => WhereAt.ValueReadOnlyList.cs} | 10 +- ...st.cs => WhereSelect.ValueReadOnlyList.cs} | 12 +- .../Generation/ValueEnumerable/Range.cs | 6 +- .../Select/Select/Select.ArraySegment.cs | 8 +- .../Select/Select/Select.ReadOnlyMemory.cs | 8 +- ...nlyList.cs => Select.ValueReadOnlyList.cs} | 10 +- .../Select/SelectAt/SelectAt.ArraySegment.cs | 8 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 8 +- ...yList.cs => SelectAt.ValueReadOnlyList.cs} | 10 +- .../Select/SelectVector/SelectVector.Range.cs | 273 ++---------------- ...ist.cs => SelectMany.ValueReadOnlyList.cs} | 24 +- ...adOnlyList.cs => All.ValueReadOnlyList.cs} | 29 +- ...adOnlyList.cs => Any.ValueReadOnlyList.cs} | 17 +- ...yList.cs => Contains.ValueReadOnlyList.cs} | 32 +- ...yList.cs => Distinct.ValueReadOnlyList.cs} | 5 +- ...cs => ToArrayBuilder.ValueReadOnlyList.cs} | 2 +- ...dOnlyList.cs => Copy.ValueReadOnlyList.cs} | 14 +- .../Utils/IndexOf/IndexOf.ReadOnlyList.cs | 88 ------ .../IndexOf/IndexOf.ValueReadOnlyList.cs | 131 +++++++++ 91 files changed, 1056 insertions(+), 861 deletions(-) rename NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/{Any.ReadOnlyList.cs => Any.ValueReadOnlyList.cs} (78%) rename NetFabric.Hyperlinq/Aggregation/Count/{Count.ReadOnlyList.cs => Count.ValueReadOnlyList.cs} (83%) rename NetFabric.Hyperlinq/Aggregation/Sum/{Sum.ReadOnlyList.cs => Sum.ValueReadOnlyList.cs} (88%) create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs rename NetFabric.Hyperlinq/Conversion/ToArray/{ToArray.ReadOnlyList.cs => ToArray.ValueReadOnlyList.cs} (97%) rename NetFabric.Hyperlinq/Conversion/ToDictionary/{ToDictionary.ReadOnlyList.cs => ToDictionary.ValueReadOnlyList.cs} (91%) rename NetFabric.Hyperlinq/Conversion/ToList/{ToList.ReadOnlyList.cs => ToList.ValueReadOnlyList.cs} (90%) rename NetFabric.Hyperlinq/Element/ElementAt/{ElementAt.ReadOnlyList.cs => ElementAt.ValueReadOnlyList.cs} (93%) rename NetFabric.Hyperlinq/Element/First/{First.ReadOnlyList.cs => First.ValueReadOnlyList.cs} (95%) rename NetFabric.Hyperlinq/Element/Single/{Single.ReadOnlyList.cs => Single.ValueReadOnlyList.cs} (96%) rename NetFabric.Hyperlinq/Filtering/Where/Where/{Where.ReadOnlyList.cs => Where.ValueReadOnlyList.cs} (97%) rename NetFabric.Hyperlinq/Filtering/Where/WhereAt/{WhereAt.ReadOnlyList.cs => WhereAt.ValueReadOnlyList.cs} (97%) rename NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/{WhereSelect.ReadOnlyList.cs => WhereSelect.ValueReadOnlyList.cs} (97%) rename NetFabric.Hyperlinq/Projection/Select/Select/{Select.ReadOnlyList.cs => Select.ValueReadOnlyList.cs} (97%) rename NetFabric.Hyperlinq/Projection/Select/SelectAt/{SelectAt.ReadOnlyList.cs => SelectAt.ValueReadOnlyList.cs} (97%) rename NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/{SelectMany.ReadOnlyList.cs => SelectMany.ValueReadOnlyList.cs} (93%) rename NetFabric.Hyperlinq/Quantifier/All/{All.ReadOnlyList.cs => All.ValueReadOnlyList.cs} (59%) rename NetFabric.Hyperlinq/Quantifier/Any/{Any.ReadOnlyList.cs => Any.ValueReadOnlyList.cs} (84%) rename NetFabric.Hyperlinq/Quantifier/Contains/{Contains.ReadOnlyList.cs => Contains.ValueReadOnlyList.cs} (87%) rename NetFabric.Hyperlinq/Set/Distinct/{Distinct.ReadOnlyList.cs => Distinct.ValueReadOnlyList.cs} (97%) rename NetFabric.Hyperlinq/Utils/ArrayBuilder/{ToArrayBuilder.ReadOnlyList.cs => ToArrayBuilder.ValueReadOnlyList.cs} (97%) rename NetFabric.Hyperlinq/Utils/Copy/{Copy.ReadOnlyList.cs => Copy.ValueReadOnlyList.cs} (79%) create mode 100644 NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs diff --git a/Benchmarks/SingleBenchmarks.md b/Benchmarks/SingleBenchmarks.md index 81d4ab90d..63592b5ee 100644 --- a/Benchmarks/SingleBenchmarks.md +++ b/Benchmarks/SingleBenchmarks.md @@ -4,7 +4,7 @@ [SingleBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,44 +14,15 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + .NET 6.0 : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Job=.NET 6.0 Runtime=.NET 6.0 Categories=AsyncEnumerable_Value ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 1 | 11.808 ns | 0.2634 ns | 0.5011 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 1 | 13.928 ns | 0.0230 ns | 0.0192 ns | 1.20 | 0.05 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 1 | 23.083 ns | 0.1199 ns | 0.1062 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 1 | 16.547 ns | 0.0383 ns | 0.0359 ns | 0.72 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 1 | 23.476 ns | 0.4181 ns | 0.6986 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 1 | 18.673 ns | 0.0344 ns | 0.0322 ns | 0.79 | 0.03 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 1 | 7.425 ns | 0.0417 ns | 0.0348 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 1 | 22.084 ns | 0.0572 ns | 0.0507 ns | 2.97 | 0.02 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 1 | 89.296 ns | 0.1602 ns | 0.1420 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 1 | NA | NA | NA | ? | ? | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 1 | 17.964 ns | 0.0869 ns | 0.0813 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 1 | 15.953 ns | 0.0711 ns | 0.0630 ns | 0.89 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 1 | 18.071 ns | 0.1005 ns | 0.0891 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 1 | 16.254 ns | 0.0875 ns | 0.1864 ns | 0.91 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 1 | 7.401 ns | 0.1724 ns | 0.1693 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 1 | 22.010 ns | 0.0530 ns | 0.0496 ns | 2.97 | 0.07 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 1 | 84.754 ns | 0.2935 ns | 0.2602 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 1 | NA | NA | NA | ? | ? | - | - | - | - | - -Benchmarks with issues: - SingleBenchmarks.Hyperlinq_AsyncEnumerable_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=1] - SingleBenchmarks.Hyperlinq_AsyncEnumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=1] +| Method | Count | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | +|-------------------------------- |------ |---------:|---------:|---------:|------:|------:|------:|----------:| +| Hyperlinq_AsyncEnumerable_Value | 1 | 84.27 ns | 0.499 ns | 0.443 ns | - | - | - | - | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs index e15e21d4c..0658622f3 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs @@ -1,6 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs index af76c757e..ac880e5ea 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs @@ -1,6 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs index 107c5e4b6..9fa4e28de 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs @@ -1,6 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs index 58146ff60..504b607f9 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs @@ -1,6 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs index fd1563d9a..61e6bfd9e 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs @@ -1,6 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs index e515aa10c..6ea55184e 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs @@ -1,7 +1,6 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs index d015f0d01..42bf8369c 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs @@ -1,6 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/EmptyBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/EmptyBenchmarks.cs index 786482170..cba2268f2 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/EmptyBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/EmptyBenchmarks.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using StructLinq; namespace NetFabric.Hyperlinq.Benchmarks { diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs index 936de168d..c7d91dfe4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs @@ -1,6 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs index 067b5c9cc..a7f454b18 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatBenchmarks.cs index f37b280ca..c54915bf0 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatBenchmarks.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReturnBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReturnBenchmarks.cs index 1cafda77e..9c4c7d272 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReturnBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReturnBenchmarks.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using StructLinq; namespace NetFabric.Hyperlinq.Benchmarks { diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs index b8d3002db..0608b495c 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs @@ -1,7 +1,6 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs index b7a39998a..0d46e2429 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs @@ -1,7 +1,6 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs index 9c8e1dd8e..d1050b589 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs @@ -2,7 +2,6 @@ using BenchmarkDotNet.Configs; using JM.LinqFaster.SIMD; using StructLinq; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs index 287e4bf63..5fd9f1031 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs @@ -1,7 +1,6 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -32,6 +31,12 @@ public List Linq_Collection_Value() public List Linq_List_Value() => listValue.Select(item => item).ToList(); + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public ValueTask> Linq_AsyncEnumerable_Value() + => asyncEnumerableValue.Select(item => item) + .ToListAsync(); + [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public List Linq_Enumerable_Reference() @@ -47,6 +52,12 @@ public List Linq_Collection_Reference() public List Linq_List_Reference() => listReference.Select(item => item).ToList(); + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public ValueTask> Linq_AsyncEnumerable_Reference() + => asyncEnumerableReference.Select(item => item) + .ToListAsync(); + // --------------------------------------------------------------------- [BenchmarkCategory("Array")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs index b4c595ac2..cb388733a 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs @@ -2,10 +2,7 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using System; -using System.Collections.Generic; using System.Linq; -using System.Threading; using System.Threading.Tasks; namespace NetFabric.Hyperlinq.Benchmarks diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs index 58e1a9059..9c4cbefb4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs @@ -2,7 +2,6 @@ using BenchmarkDotNet.Configs; using JM.LinqFaster.SIMD; using StructLinq; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs index f2b1f32f1..e7301dc04 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs @@ -1,7 +1,6 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs index 24c98d6b8..4d990fe0e 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs @@ -1,7 +1,6 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs index 5781c72a4..89053f3dd 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs @@ -1,7 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using StructLinq; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs index c7b67d07e..4a47d792c 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs @@ -1,6 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs index 5dc9ea654..55c11b1df 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs @@ -1,7 +1,5 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; -using StructLinq; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs index c30a8a399..1136ef872 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs @@ -1,7 +1,6 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs index 5bbc48b9c..497091b29 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs @@ -1,7 +1,6 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs b/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs index b1ffcee5a..95c3da63f 100644 --- a/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs +++ b/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs @@ -2,7 +2,6 @@ using BenchmarkDotNet.Jobs; using System; using System.Collections.Generic; -using System.Collections.Specialized; namespace NetFabric.Hyperlinq.Benchmarks { diff --git a/NetFabric.Hyperlinq.Benchmarks/Program.cs b/NetFabric.Hyperlinq.Benchmarks/Program.cs index 1a9c412c4..4fb00032b 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Program.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Program.cs @@ -90,7 +90,7 @@ static string GetInformationalVersion(Assembly assembly) { var dir = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); - while (!string.IsNullOrEmpty(dir)) + while (dir is not null and { Length: not 0 }) { if (Directory.EnumerateFiles(dir, "*.sln", SearchOption.TopDirectoryOnly).Any()) return dir; diff --git a/NetFabric.Hyperlinq.Benchmarks/SequentialBenchmarksBase.cs b/NetFabric.Hyperlinq.Benchmarks/SequentialBenchmarksBase.cs index ede6ba87b..f9787162d 100644 --- a/NetFabric.Hyperlinq.Benchmarks/SequentialBenchmarksBase.cs +++ b/NetFabric.Hyperlinq.Benchmarks/SequentialBenchmarksBase.cs @@ -1,6 +1,4 @@ -using BenchmarkDotNet.Attributes; - -namespace NetFabric.Hyperlinq.Benchmarks +namespace NetFabric.Hyperlinq.Benchmarks { public abstract class SequentialBenchmarksBase : CountBenchmarksBase { diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs index 6d5fef241..701e9ba88 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Threading; @@ -59,7 +58,7 @@ public Enumerator(int[] array, CancellationToken cancellationToken) public ValueTask MoveNextAsync() { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(++index < array.Length); + return new ValueTask(++index <= array.Length); } public ValueTask DisposeAsync() diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs index c90719d02..44078968f 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs @@ -115,7 +115,7 @@ public static TheoryData GeneratorSources { new[] { "TestData/Source/Any.ArraySegment.cs", - "TestData/Source/Any.ReadOnlyList.cs", + "TestData/Source/Any.ValueReadOnlyList.cs", "TestData/Source/Any.ValueEnumerable.cs", "TestData/Source/Any.ValueReadOnlyCollection.cs", "TestData/Source/Where.ValueEnumerable.cs", @@ -126,7 +126,7 @@ public static TheoryData GeneratorSources { new[] { "TestData/Source/Any.ArraySegment.cs", - "TestData/Source/Any.ReadOnlyList.cs", + "TestData/Source/Any.ValueReadOnlyList.cs", "TestData/Source/Any.ValueEnumerable.cs", "TestData/Source/Any.ValueReadOnlyCollection.cs", "TestData/Source/Select.ArraySegment.cs", @@ -138,7 +138,7 @@ public static TheoryData GeneratorSources { new[] { "TestData/Source/Any.ArraySegment.cs", - "TestData/Source/Any.ReadOnlyList.cs", + "TestData/Source/Any.ValueReadOnlyList.cs", "TestData/Source/Any.ValueEnumerable.cs", "TestData/Source/Any.ValueReadOnlyCollection.cs", "TestData/Source/Select.ValueEnumerable.cs", diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs index d0fc592f7..f44a33abe 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs @@ -15,14 +15,14 @@ public partial struct ArraySegmentSelectEnumerable [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Any(System.Func predicate) - => NetFabric.Hyperlinq.ReadOnlyListExtensions.Any, TResult>(this, predicate); + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Any, TResult>(this, predicate); [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] [DebuggerNonUserCode] [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Any(TPredicate predicate = default) where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ReadOnlyListExtensions.Any, TResult, TPredicate>(this, predicate); + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Any, TResult, TPredicate>(this, predicate); } diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ReadOnlyList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs similarity index 78% rename from NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ReadOnlyList.cs rename to NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs index 10383b01b..085c79a11 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs @@ -4,23 +4,23 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool Any(this TList source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.Count is not 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool Any(this TList source, Func predicate) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.Any>(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool Any(this TList source, TPredicate predicate = default) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList where TPredicate : struct, IFunction => default; } diff --git a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj index 89eecd2a8..991562703 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj @@ -2,7 +2,6 @@ netstandard2.0 - preview true diff --git a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs index b3b674711..d3b2ddc0f 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs @@ -362,11 +362,7 @@ void GenerateMethodSource(CodeBuilder builder, CompilationContext context, IName foreach (var (name, constraints, _) in typeParameters.Where(typeParameter => typeParameter.Constraints.Any())) _ = builder.AppendLine($"where {name} : {constraints}"); - - callParameters = StringExtensions.CommaSeparateIfNotNullOrEmpty(firstCallParameter, callParameters); - - if (!string.IsNullOrEmpty(bindingsAttribute?.ExtraParameters)) - callParameters = StringExtensions.CommaSeparateIfNotNullOrEmpty(callParameters, bindingsAttribute!.ExtraParameters); + callParameters = StringExtensions.CommaSeparateIfNotNullOrEmpty(firstCallParameter, callParameters, bindingsAttribute?.ExtraParameters); _ = builder .AppendLine($"=> {callContainingType}.{methodName}{callTypeParameters}({callParameters});") @@ -384,7 +380,11 @@ string MapTypeProperties(IEnumerable typePropertyNames, ITypeSymbol enum }) .ToCommaSeparated(); - return string.IsNullOrEmpty(str) ? string.Empty : $"<{str}>"; + return str switch + { + { Length: 0 } => string.Empty, + _ => $"<{str}>" + }; } string MapTypeProperties(IEnumerable typePropertyNames, GeneratorBindingsAttribute? bindingsAttribute) @@ -400,7 +400,11 @@ string MapTypeProperties(IEnumerable typePropertyNames, GeneratorBinding str = StringExtensions.CommaSeparateIfNotNullOrEmpty(str, bindingsAttribute?.ExtraTypeParameters); - return string.IsNullOrEmpty(str) ? string.Empty : $"<{str}>"; + return str switch + { + { Length: 0 } => string.Empty, + _ => $"<{str}>" + }; } } } diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs index 3ec912676..8dec54151 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs @@ -102,9 +102,9 @@ public static bool IsOverload(this MethodInfo method0, MethodInfo method1) // check if parameter type is defined by contraints var constraints0 = method0.TypeParameters.FirstOrDefault(typeParameter => type0 == typeParameter.Name).Constraints; var constraints1 = method1.TypeParameters.FirstOrDefault(typeParameter => type1 == typeParameter.Name).Constraints; - if (string.IsNullOrEmpty(constraints0)) + if (constraints0 is null or { Length: 0 }) { - if (!string.IsNullOrEmpty(constraints1)) + if (constraints1 is not null and { Length: not 0 }) return false; if (type0 != type1) @@ -112,7 +112,7 @@ public static bool IsOverload(this MethodInfo method0, MethodInfo method1) } else { - if (string.IsNullOrEmpty(constraints1)) + if (constraints1 is null or { Length: 0 }) return false; return constraints0 == constraints1; diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs index c6f648b86..a9f23efd7 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs @@ -43,18 +43,32 @@ static StringBuilder PerformAppendCommaSeparated(StringBuilder builder, IReadOnl public static string CommaSeparateIfNotNullOrEmpty(params string?[] args) { - var builder = new StringBuilder(); - foreach(var arg in args) + return args.Length switch { - if (!string.IsNullOrEmpty(arg)) + 0 => string.Empty, + 1 => args[0] switch + { + null or { Length: 0 } => string.Empty, + _ => args[0]! + }, + _ => Append(args) + }; + + static string Append(params string?[] args) + { + var builder = new StringBuilder(); + foreach (var arg in args) { - if (builder.Length is not 0) - _ = builder.Append(", "); + if (arg is not null and { Length: not 0 }) + { + if (builder.Length is not 0) + _ = builder.Append(", "); - _ = builder.Append(arg); + _ = builder.Append(arg); + } } + return builder.ToString(); } - return builder.ToString(); } public static string ApplyMappings(this string value, ImmutableArray genericsMapping, out bool isConcreteType) diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs index dd8f1d59a..d06260964 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs @@ -1,7 +1,6 @@ using Microsoft.CodeAnalysis; using System.Collections.Immutable; using System.Linq; -using System.Reflection; namespace NetFabric.Hyperlinq.SourceGenerator { @@ -36,7 +35,8 @@ public static ImmutableArray GetGenericsMappings(this (string?)attribute.ConstructorArguments[2].Value, (string?)attribute.ConstructorArguments[3].Value, (string?)attribute.ConstructorArguments[4].Value, - (string?)attribute.ConstructorArguments[5].Value) + (string?)attribute.ConstructorArguments[5].Value, + (string?)attribute.ConstructorArguments[6].Value) }; } diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs index 18ca41074..28ae22077 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs @@ -21,8 +21,8 @@ public async ValueTask CountAsync_With_ValidData_Must_Succeed(int[] source) .Count(); // Act - var result = await wrapped - .CountAsync, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .CountAsync() .ConfigureAwait(false); // Assert @@ -43,8 +43,8 @@ public async ValueTask CountAsync_Predicate_With_ValidData_Must_Succeed(int[] so .Count(predicate); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .CountAsync() .ConfigureAwait(false); @@ -67,8 +67,8 @@ public async ValueTask CountAsync_PredicateAt_With_ValidData_Must_Succeed(int[] .Count(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .CountAsync() .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs index 42c63580b..c595838a1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs @@ -18,8 +18,8 @@ public async ValueTask SumAsync_With_ValidData_Must_Succeed(double[] source) .Sum(); // Act - var result = await wrapped - .SumAsync, Wrap.AsyncEnumerator, double, double>() + var result = await wrapped.AsAsyncValueEnumerable() + .SumAsync() .ConfigureAwait(false); // Assert @@ -37,8 +37,8 @@ public async ValueTask SumAsync_With_Nullable_ValidData_Must_Succeed(double?[] s .Sum(); // Act - var result = await wrapped - .SumAsync, Wrap.AsyncEnumerator, double?, double>() + var result = await wrapped.AsAsyncValueEnumerable() + .SumAsync() .ConfigureAwait(false); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.Tests.cs index 97bd55296..5e4f493ea 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.Tests.cs @@ -1,4 +1,5 @@ using NetFabric.Assertive; +using System; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsAsyncEnumerable @@ -9,7 +10,7 @@ public class AsyncValueEnumerableTests public void AsAsyncEnumerable_With_ValueType_Must_ReturnCopy() { // Arrange - var source = new int[0]; + var source = Array.Empty(); var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act @@ -25,7 +26,7 @@ public void AsAsyncEnumerable_With_ValueType_Must_ReturnCopy() public void AsAsyncEnumerable_With_ReferenceType_Must_ReturnSame() { // Arrange - var source = new int[0]; + var source = Array.Empty(); var wrapped = Wrap .AsAsyncValueEnumerable(source) as IAsyncValueEnumerable>; diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs index a0ce037d6..4fc411329 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs @@ -1,5 +1,6 @@ using NetFabric.Assertive; using Xunit; +using System.Linq; namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable { @@ -21,9 +22,134 @@ public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) // Assert _ = result.Must() - .BeOfType, int>>() + .BeOfType, int>>() .BeEnumerableOf() .BeEqualTo(wrapped); } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source, int skipCount, int takeCount) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .ToArray(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .ToArray(); + + // Assert + _ = result.Must() + .BeArrayOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] + public void AsValueEnumerable_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(count0) + .Skip(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(count0) + .Skip(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Take(count0) + .Take(count1); + + // Act + var result = wrapped + .AsValueEnumerable() + .Take(count0) + .Take(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .Count(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Skip(skipCount) + .Take(takeCount) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs index 6931d4850..6013be4ce 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs @@ -22,8 +22,8 @@ public async ValueTask ToArrayAsync_With_ValidData_Must_Succeed(int[] source) .ToArray(); // Act - var result = await wrapped - .ToArrayAsync, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .ToArrayAsync() .ConfigureAwait(false); // Assert @@ -46,8 +46,8 @@ public async ValueTask ToArrayAsync_MemoryPool_Must_Succeed(int[] source) .ToArray(); // Act - var result = await wrapped - .ToArrayAsync, Wrap.AsyncEnumerator, int>(pool) + var result = await wrapped.AsAsyncValueEnumerable() + .ToArrayAsync(pool) .ConfigureAwait(false); // Assert @@ -71,8 +71,8 @@ public async ValueTask ToArrayAsync_Predicate_With_ValidData_Must_Succeed(int[] .ToArray(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ToArrayAsync() .ConfigureAwait(false); @@ -97,8 +97,8 @@ public async ValueTask ToArrayAsync_Predicate_MemoryPool_Must_Succeed(int[] sour .ToArray(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ToArrayAsync(pool) .ConfigureAwait(false); @@ -123,8 +123,8 @@ public async ValueTask ToArrayAsync_PredicateAt_With_ValidData_Must_Succeed(int[ .ToArray(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ToArrayAsync() .ConfigureAwait(false); @@ -149,8 +149,8 @@ public async ValueTask ToArrayAsync_PredicateAt_MemoryPool_Must_Succeed(int[] so .ToArray(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ToArrayAsync(pool) .ConfigureAwait(false); @@ -175,8 +175,8 @@ public async ValueTask ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] s .ToArray(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ToArrayAsync() .ConfigureAwait(false); @@ -201,8 +201,8 @@ public async ValueTask ToArrayAsync_Selector_MemoryPool_Must_Succeed(int[] sourc .ToArray(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ToArrayAsync(pool) .ConfigureAwait(false); @@ -227,8 +227,8 @@ public async ValueTask ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[] .ToArray(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ToArrayAsync() .ConfigureAwait(false); @@ -253,8 +253,8 @@ public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] sou .ToArray(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ToArrayAsync(pool) .ConfigureAwait(false); @@ -281,8 +281,8 @@ public async ValueTask ToArrayAsync_Predicate_Selector_With_ValidData_Must_Succe .ToArray(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .ToArrayAsync() .ConfigureAwait(false); @@ -309,8 +309,8 @@ public async ValueTask ToArrayAsync_Predicate_Selector_MemoryPool_Must_Succeed(i .ToArray(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .ToArrayAsync(pool) .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs index 7e705771b..9a73611ed 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs @@ -22,8 +22,8 @@ public async ValueTask ToListAsync_With_ValidData_Must_Succeed(int[] source) .ToList(); // Act - var result = await wrapped - .ToListAsync, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .ToListAsync() .ConfigureAwait(false); // Assert @@ -47,8 +47,8 @@ public async ValueTask ToListAsync_Predicate_With_ValidData_Must_Succeed(int[] s .ToList(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ToListAsync() .ConfigureAwait(false); @@ -73,8 +73,8 @@ public async ValueTask ToListAsync_PredicateAt_With_ValidData_Must_Succeed(int[] .ToList(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ToListAsync() .ConfigureAwait(false); @@ -99,8 +99,8 @@ public async ValueTask ToListAsync_Selector_With_ValidData_Must_Succeed(int[] so .ToList(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ToListAsync() .ConfigureAwait(false); @@ -125,8 +125,8 @@ public async ValueTask ToListAsync_SelectorAt_With_ValidData_Must_Succeed(int[] .ToList(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ToListAsync() .ConfigureAwait(false); @@ -153,8 +153,8 @@ public async ValueTask ToListAsync_Predicate_Selector_With_ValidData_Must_Succee .ToList(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .ToListAsync() .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs index b98cbdf0f..4b32ac9b8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs @@ -19,11 +19,11 @@ public async void ElementAtAsync_With_OutOfRange_Must_Return_None(int[] source) .AsAsyncValueEnumerable(source); // Act - var optionNegative = await wrapped - .ElementAtAsync, Wrap.AsyncEnumerator, int>(-1) + var optionNegative = await wrapped.AsAsyncValueEnumerable() + .ElementAtAsync(-1) .ConfigureAwait(false); - var optionTooLarge = await wrapped - .ElementAtAsync, Wrap.AsyncEnumerator, int>(source.Length) + var optionTooLarge = await wrapped.AsAsyncValueEnumerable() + .ElementAtAsync(source.Length) .ConfigureAwait(false); // Assert @@ -45,12 +45,12 @@ public async ValueTask ElementAtAsync_With_ValidData_Must_Return_Some(int[] sour for (var index = 0; index < source.Length; index++) { // Arrange - var expected = Enumerable - .ElementAt(source, index); + var expected = source + .ElementAt(index); // Act - var result = await wrapped - .ElementAtAsync, Wrap.AsyncEnumerator, int>(index) + var result = await wrapped.AsAsyncValueEnumerable() + .ElementAtAsync(index) .ConfigureAwait(false); // Assert @@ -71,12 +71,12 @@ public async void ElementAtAsync_Predicate_With_OutOfRange_Must_Return_None(int[ .AsAsyncValueEnumerable(source); // Act - var optionNegative = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var optionNegative = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ElementAtAsync(-1) .ConfigureAwait(false); - var optionTooLarge = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var optionTooLarge = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ElementAtAsync(source.Length) .ConfigureAwait(false); @@ -97,15 +97,15 @@ public async ValueTask ElementAtAsync_Predicate_With_ValidData_Must_Return_Some( // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ElementAtAsync(index) .ConfigureAwait(false); @@ -127,12 +127,12 @@ public async void ElementAtAsync_PredicateAt_With_OutOfRange_Must_Return_None(in .AsAsyncValueEnumerable(source); // Act - var optionNegative = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var optionNegative = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ElementAtAsync(-1) .ConfigureAwait(false); - var optionTooLarge = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var optionTooLarge = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ElementAtAsync(source.Length) .ConfigureAwait(false); @@ -152,15 +152,15 @@ public async ValueTask ElementAtAsync_PredicateAt_With_ValidData_Must_Return_Som { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .ElementAtAsync(index) .ConfigureAwait(false); @@ -182,12 +182,12 @@ public async void ElementAtAsync_Selector_With_OutOfRange_Must_Return_None(int[] .AsAsyncValueEnumerable(source); // Act - var optionNegative = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var optionNegative = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ElementAtAsync(-1) .ConfigureAwait(false); - var optionTooLarge = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var optionTooLarge = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ElementAtAsync(source.Length) .ConfigureAwait(false); @@ -207,15 +207,15 @@ public async ValueTask ElementAtAsync_Selector_With_ValidData_Must_Return_Some(i { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ElementAtAsync(index) .ConfigureAwait(false); @@ -237,12 +237,12 @@ public async void ElementAtAsync_SelectorAt_With_OutOfRange_Must_Return_None(int .AsAsyncValueEnumerable(source); // Act - var optionNegative = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var optionNegative = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ElementAtAsync(-1) .ConfigureAwait(false); - var optionTooLarge = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var optionTooLarge = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ElementAtAsync(source.Length) .ConfigureAwait(false); @@ -263,15 +263,15 @@ public async ValueTask ElementAtAsync_SelectorAt_With_ValidData_Must_Return_Some // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .ElementAtAsync(index) .ConfigureAwait(false); @@ -293,13 +293,13 @@ public async void ElementAtAsync_Predicate_Selector_With_OutOfRange_Must_Return_ .AsAsyncValueEnumerable(source); // Act - var optionNegative = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var optionNegative = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .ElementAtAsync(-1) .ConfigureAwait(false); - var optionTooLarge = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var optionTooLarge = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .ElementAtAsync(source.Length) .ConfigureAwait(false); @@ -321,16 +321,16 @@ public async ValueTask ElementAtAsync_Predicate_Selector_With_ValidData_Must_Ret // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .ToList(); for (var index = 0; index < expected.Count; index++) { // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .ElementAtAsync(index) .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs index c5e2358bf..e2fa58c69 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs @@ -17,8 +17,8 @@ public async void FirstAsync_With_Empty_Must_Return_None(int[] source) .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .FirstAsync, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .FirstAsync() .ConfigureAwait(false); // Assert @@ -35,12 +35,12 @@ public async ValueTask FirstAsync_With_ValidData_Must_Return_Some(int[] source) // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .First(source); + var expected = source + .First(); // Act - var result = await wrapped - .FirstAsync, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .FirstAsync() .ConfigureAwait(false); // Assert @@ -58,8 +58,8 @@ public async void FirstAsync_Predicate_With_Empty_Must_Return_None(int[] source, .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .FirstAsync() .ConfigureAwait(false); @@ -77,12 +77,12 @@ public async ValueTask FirstAsync_Predicate_With_ValidData_Must_Return_Some(int[ // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .First(source, predicate); + var expected = source + .First(predicate); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .FirstAsync() .ConfigureAwait(false); @@ -101,8 +101,8 @@ public async void FirstAsync_PredicateAt_With_Empty_Must_Return_None(int[] sourc .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .FirstAsync() .ConfigureAwait(false); @@ -120,13 +120,13 @@ public async ValueTask FirstAsync_PredicateAt_With_ValidData_Must_Return_Some(in // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .First(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .FirstAsync() .ConfigureAwait(false); @@ -145,8 +145,8 @@ public async void FirstAsync_Selector_With_Empty_Must_Return_None(int[] source, .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .FirstAsync() .ConfigureAwait(false); @@ -164,13 +164,13 @@ public async ValueTask FirstAsync_Selector_With_ValidData_Must_Return_Some(int[] // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .First(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .FirstAsync() .ConfigureAwait(false); @@ -189,8 +189,8 @@ public async void FirstAsync_SelectorAt_With_Empty_Must_Return_None(int[] source .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .FirstAsync() .ConfigureAwait(false); @@ -208,13 +208,13 @@ public async ValueTask FirstAsync_SelectorAt_With_ValidData_Must_Return_Some(int // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .First(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .FirstAsync() .ConfigureAwait(false); @@ -233,8 +233,8 @@ public async void FirstAsync_Predicate_Selector_With_Empty_Must_Return_None(int[ .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .FirstAsync() .ConfigureAwait(false); @@ -253,14 +253,14 @@ public async ValueTask FirstAsync_Predicate_Selector_With_ValidData_Must_Return_ // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .First(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .FirstAsync() .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs index 733300ab1..62ecc075b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs @@ -17,8 +17,8 @@ public async void SingleAsync_With_Empty_Must_Return_None(int[] source) .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .SingleAsync, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .SingleAsync() .ConfigureAwait(false); // Assert @@ -34,12 +34,12 @@ public async ValueTask SingleAsync_With_SingleAsync_Must_Return_Some(int[] sourc // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Single(source); + var expected = source + .Single(); // Act - var result = await wrapped - .SingleAsync, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .SingleAsync() .ConfigureAwait(false); // Assert @@ -57,8 +57,8 @@ public async void SingleAsync_With_Multiple_Must_Return_None(int[] source) .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .SingleAsync, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .SingleAsync() .ConfigureAwait(false); // Assert @@ -76,8 +76,8 @@ public async void SingleAsync_Predicate_With_Empty_Must_Return_None(int[] source .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -94,12 +94,12 @@ public async ValueTask SingleAsync_Predicate_With_SingleAsync_Must_Return_Some(i // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Single(source, predicate); + var expected = source + .Single(predicate); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -118,8 +118,8 @@ public async void SingleAsync_Predicate_With_Multiple_Must_Return_None(int[] sou .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -138,8 +138,8 @@ public async void SingleAsync_PredicateAt_With_Empty_Must_Return_None(int[] sour .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -161,8 +161,8 @@ public async ValueTask SingleAsync_PredicateAt_With_SingleAsync_Must_Return_Some .Single(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -181,8 +181,8 @@ public async void SingleAsync_PredicateAt_With_Multiple_Must_Return_None(int[] s .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -201,8 +201,8 @@ public async void SingleAsync_Selector_With_Empty_Must_Return_None(int[] source, .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -224,8 +224,8 @@ public async ValueTask SingleAsync_Selector_With_SingleAsync_Must_Return_Some(in .Single(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -244,8 +244,8 @@ public async void SingleAsync_Selector_With_Multiple_Must_Return_None(int[] sour .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -264,8 +264,8 @@ public async void SingleAsync_SelectorAt_With_Empty_Must_Return_None(int[] sourc .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -282,13 +282,13 @@ public async ValueTask SingleAsync_SelectorAt_With_SingleAsync_Must_Return_Some( // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Select(source, selector) + var expected = source + .Select(selector) .Single(); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -307,8 +307,8 @@ public async void SingleAsync_SelectorAt_With_Multiple_Must_Return_None(int[] so .AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .Select, Wrap.AsyncEnumerator, int, string>(selector.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Select(selector.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -327,8 +327,8 @@ public async void SingleAsync_Predicate_Selector_With_Empty_Must_Return_None(int .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -346,14 +346,14 @@ public async ValueTask SingleAsync_Predicate_Selector_With_SingleAsync_Must_Retu // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); - var expected = Enumerable - .Where(source, predicate) + var expected = source + .Where(predicate) .Select(selector) .Single(); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .SingleAsync() .ConfigureAwait(false); @@ -373,8 +373,8 @@ public async void SingleAsync_Predicate_Selector_With_Multiple_Must_Return_None( .AsAsyncValueEnumerable(source); // Act - var result = await AsyncValueEnumerableExtensions - .Where, Wrap.AsyncEnumerator, int>(wrapped, predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()) .SingleAsync() .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs index 34ae9626b..49ea28526 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs @@ -21,8 +21,8 @@ public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); + var result = wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()); // Assert _ = result.Must() @@ -44,8 +44,8 @@ public async ValueTask Where_Sum_Predicate_With_ValidData_Must_Succeed(int[] sou .Sum(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .SumAsync() .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs index db2d5ba4d..294eeeacf 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs @@ -21,8 +21,8 @@ public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func, Wrap.AsyncEnumerator, int>(predicate.AsAsync()); + var result = wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()); // Assert _ = result.Must() @@ -44,8 +44,8 @@ public async ValueTask Where_Sum_Predicate_With_ValidData_Must_Succeed(int[] sou .Sum(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .SumAsync() .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs index a308e525f..6c86e1f31 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs @@ -21,8 +21,8 @@ public void WhereSelect_Predicate_With_ValidData_Must_Succeed(int[] source, Func .Select(selector); // Act - var result = wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select(selector.AsAsync()); // Assert @@ -45,8 +45,8 @@ public async ValueTask WhereSelect_Sum_Predicate_With_ValidData_Must_Succeed(int .Sum(); // Act - var result = await wrapped - .Where, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .Where(predicate.AsAsync()) .Select((item, _) => new ValueTask(item)) .SumAsync() .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs index 657412273..b8961b596 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs @@ -134,22 +134,6 @@ public void Range_With_ToList_Must_Succeed(int start, int count) .BeEqualTo(expected); } - [Theory] - [MemberData(nameof(TestData.Range), MemberType = typeof(TestData))] - public void Range_SelectVector_Must_Succeed(int start, int count) - { - // Arrange - var expected = Enumerable.Range(start, count).Select(item => item * 2); - - // Act - var result = ValueEnumerable.Range(start, count).SelectVector(item => item * 2, item => item * 2); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - [Theory] [MemberData(nameof(TestData.Range), MemberType = typeof(TestData))] diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs index 8a8d402c6..794992bee 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs @@ -19,8 +19,8 @@ public void Skip_With_ValidData_Must_Succeed(int[] source, int count) .Skip(count); // Act - var result = wrapped - .Skip, Wrap.AsyncEnumerator, int>(count); + var result = wrapped.AsAsyncValueEnumerable() + .Skip(count); // Assert _ = result.Must() @@ -40,8 +40,8 @@ public void Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int .Skip(count1); // Act - var result = wrapped - .Skip, Wrap.AsyncEnumerator, int>(count0) + var result = wrapped.AsAsyncValueEnumerable() + .Skip(count0) .Skip(count1); // Assert @@ -64,8 +64,8 @@ public void Skip_Take_With_ValidData_Must_Succeed(int[] source, int skip, int ta .Take(take); // Act - var result = wrapped - .Skip, Wrap.AsyncEnumerator, int>(skip) + var result = wrapped.AsAsyncValueEnumerable() + .Skip(skip) .Take(take); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs index cf8160b94..cb28579cb 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs @@ -19,8 +19,8 @@ public void Take_With_ValidData_Must_Succeed(int[] source, int count) .Take(count); // Act - var result = wrapped - .Take, Wrap.AsyncEnumerator, int>(count); + var result = wrapped.AsAsyncValueEnumerable() + .Take(count); // Assert _ = result.Must() @@ -40,8 +40,8 @@ public void Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int .Take(count1); // Act - var result = wrapped - .Take, Wrap.AsyncEnumerator, int>(count0) + var result = wrapped.AsAsyncValueEnumerable() + .Take(count0) .Take(count1); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs index af58e47d7..1a8b775ab 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs @@ -20,8 +20,8 @@ public async ValueTask AllAsync_With_ValidData_Must_Succeed(int[] source, Func, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .AllAsync(predicate.AsAsync()) .ConfigureAwait(false); // Assert @@ -42,8 +42,8 @@ public async ValueTask AllAsync_PredicateAt_With_ValidData_Must_Succeed(int[] so .Count() == source.Length; // Act - var result = await wrapped - .AllAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .AllAsync(predicate.AsAsync()) .ConfigureAwait(false); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs index 87f2c297c..99ce22f97 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs @@ -20,8 +20,8 @@ public async ValueTask AnyAsync_With_ValidData_Must_Succeed(int[] source) .Any(); // Act - var result = await wrapped - .AnyAsync, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .AnyAsync() .ConfigureAwait(false); // Assert @@ -41,8 +41,8 @@ public async ValueTask AnyAsync_Predicate_With_ValidData_Must_Succeed(int[] sour .Any(predicate); // Act - var result = await wrapped - .AnyAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .AnyAsync(predicate.AsAsync()) .ConfigureAwait(false); // Assert @@ -63,8 +63,8 @@ public async ValueTask AnyAsync_PredicateAt_With_ValidData_Must_Succeed(int[] so .Count() != 0; // Act - var result = await wrapped - .AnyAsync, Wrap.AsyncEnumerator, int>(predicate.AsAsync()) + var result = await wrapped.AsAsyncValueEnumerable() + .AnyAsync(predicate.AsAsync()) .ConfigureAwait(false); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs index 6ca97f10f..b5ba9b1ea 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs @@ -19,8 +19,8 @@ public async ValueTask ContainsAsync_ValueType_With_Null_And_NotContains_Must_Re var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value) + var result = await wrapped.AsAsyncValueEnumerable() + .ContainsAsync(value) .ConfigureAwait(false); // Assert @@ -39,8 +39,8 @@ public async ValueTask ContainsAsync_ReferenceType_With_Null_And_NotContains_Mus var wrapped = Wrap.AsAsyncValueEnumerable(source.Select(item => item.ToString()).ToArray()); // Act - var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, string>(value) + var result = await wrapped.AsAsyncValueEnumerable() + .ContainsAsync(value) .ConfigureAwait(false); // Assert @@ -59,8 +59,8 @@ public async ValueTask ContainsAsync_ValueType_With_Null_And_Contains_Must_Retur var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value) + var result = await wrapped.AsAsyncValueEnumerable() + .ContainsAsync(value) .ConfigureAwait(false); // Assert @@ -80,8 +80,8 @@ public async ValueTask ContainsAsync_ReferenceType_With_Null_And_Contains_Must_R var wrapped = Wrap.AsAsyncValueEnumerable(source.Select(item => item.ToString()).ToArray()); // Act - var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, string>(value) + var result = await wrapped.AsAsyncValueEnumerable() + .ContainsAsync(value) .ConfigureAwait(false); // Assert @@ -100,8 +100,8 @@ public async ValueTask ContainsAsync_With_DefaultComparer_And_NotContains_Must_R var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value, EqualityComparer.Default) + var result = await wrapped.AsAsyncValueEnumerable() + .ContainsAsync(value, EqualityComparer.Default) .ConfigureAwait(false); // Assert @@ -120,8 +120,8 @@ public async ValueTask ContainsAsync_With_DefaultComparer_And_Contains_Must_Retu var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value, EqualityComparer.Default) + var result = await wrapped.AsAsyncValueEnumerable() + .ContainsAsync(value, EqualityComparer.Default) .ConfigureAwait(false); // Assert @@ -141,8 +141,8 @@ public async ValueTask ContainsAsync_With_Comparer_And_NotContains_Must_ReturnFa var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value, TestComparer.Instance) + var result = await wrapped.AsAsyncValueEnumerable() + .ContainsAsync(value, TestComparer.Instance) .ConfigureAwait(false); // Assert @@ -161,8 +161,8 @@ public async ValueTask ContainsAsync_With_Comparer_And_Contains_Must_ReturnTrue( var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act - var result = await wrapped - .ContainsAsync, Wrap.AsyncEnumerator, int>(value, TestComparer.Instance) + var result = await wrapped.AsAsyncValueEnumerable() + .ContainsAsync(value, TestComparer.Instance) .ConfigureAwait(false); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs index 51835524a..fa566b562 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs @@ -20,8 +20,8 @@ public void Distinct_With_ValidData_Must_Succeed(int[] source) .Distinct(); // Act - var result = wrapped - .Distinct, Wrap.AsyncEnumerator, int>(); + var result = wrapped.AsAsyncValueEnumerable() + .Distinct(); // Assert _ = result.Must() @@ -42,8 +42,8 @@ public async ValueTask Distinct_ToArrayAsync_With_ValidData_Must_Succeed(int[] s .ToArray(); // Act - var result = await wrapped - .Distinct, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .Distinct() .ToArrayAsync() .ConfigureAwait(false); @@ -67,8 +67,8 @@ public async ValueTask Distinct_ToArrayAsync_MemoryPool_With_ValidData_Must_Succ .ToArray(); // Act - var result = await wrapped - .Distinct, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .Distinct() .ToArrayAsync(pool) .ConfigureAwait(false); @@ -90,8 +90,8 @@ public async ValueTask Distinct_ToListAsync_With_ValidData_Must_Succeed(int[] so .ToList(); // Act - var result = await wrapped - .Distinct, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .Distinct() .ToListAsync() .ConfigureAwait(false); @@ -114,8 +114,8 @@ public async ValueTask Distinct_SumAsync_With_ValidData_Must_Succeed(int[] sourc .Sum(); // Act - var result = await wrapped - .Distinct, Wrap.AsyncEnumerator, int>() + var result = await wrapped.AsAsyncValueEnumerable() + .Distinct() .SumAsync() .ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs index c93a9fcc4..945035dca 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs @@ -68,8 +68,8 @@ void IList.RemoveAt(int index) => throw new NotSupportedException(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() - => this.AsValueEnumerable, Enumerator, T>(); + public ValueReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() + => ValueReadOnlyListExtensions.AsValueEnumerable, T>(this); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs index 8a315e62f..5cc5061d2 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs @@ -38,8 +38,8 @@ readonly IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() - => this.AsValueEnumerable, Enumerator, T>(); + public ValueReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() + => ValueReadOnlyListExtensions.AsValueEnumerable, T>(this); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyList.cs similarity index 83% rename from NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyList.cs index 56e043d52..9f99339b2 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyList.cs @@ -3,8 +3,14 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static int Count(this TList source) + where TList : struct, IReadOnlyList + => source.Count(0, source.Count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] static int Count(this TList source, int offset, int count) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyList.cs similarity index 88% rename from NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyList.cs index ab487511e..8baa08230 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyList.cs @@ -2,15 +2,15 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { public static TSum Sum(this TList source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList where TSum : struct => source.Sum(0, source.Count); internal static TSum Sum(this TList source, int offset, int count) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList where TSum : struct { var sum = default(TSum); @@ -24,7 +24,7 @@ internal static TSum Sum(this TList source, int offset, in } static TSum Sum(this TList source, TPredicate predicate, int offset, int count) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList where TPredicate : struct, IFunction where TSum : struct { @@ -40,7 +40,7 @@ static TSum Sum(this TList source, TPredicate } static TSum SumAt(this TList source, TPredicate predicate, int offset, int count) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList where TPredicate : struct, IFunction where TSum : struct { @@ -56,7 +56,7 @@ static TSum SumAt(this TList source, TPredicat } static TSum Sum(this TList source, TSelector selector, int offset, int count) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList where TSelector : struct, IFunction where TSum : struct { @@ -71,7 +71,7 @@ static TSum Sum(this TList source, TSe } static TSum SumAt(this TList source, TSelector selector, int offset, int count) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList where TSelector : struct, IFunction where TSum : struct { @@ -86,7 +86,7 @@ static TSum SumAt(this TList source, T } static TSum Sum(this TList source, TPredicate predicate, TSelector selector, int offset, int count) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList where TPredicate : struct, IFunction where TSelector : struct, IFunction where TSum : struct diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs index c2467b810..8660e55b3 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs @@ -29,10 +29,10 @@ readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator( // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source, cancellationToken); - public readonly struct AsyncEnumerator + public struct AsyncEnumerator : IAsyncEnumerator { - readonly IAsyncEnumerator enumerator; + IAsyncEnumerator enumerator; internal AsyncEnumerator(IAsyncEnumerable enumerable, CancellationToken cancellationToken) => enumerator = enumerable.GetAsyncEnumerator(cancellationToken); @@ -43,12 +43,12 @@ readonly TSource IAsyncEnumerator.Current => enumerator.Current; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueTask MoveNextAsync() + public ValueTask MoveNextAsync() => enumerator.MoveNextAsync(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueTask DisposeAsync() + public ValueTask DisposeAsync() => enumerator.DisposeAsync(); } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs index 57e8f2a34..59b7c9fc8 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs @@ -81,7 +81,19 @@ public void CopyTo(Span span) if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - Copy(this, 0, span, Count); + if (Count is 0) + return; + + if (offset is 0) + { + for (var index = 0; index < Count && index < span.Length; index++) + span[index] = source[index]; + } + else + { + for (var index = 0; index < Count && index < span.Length; index++) + span[index] = source[index + offset]; + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -89,8 +101,17 @@ public void CopyTo(TSource[] array, int arrayIndex) => CopyTo(array.AsSpan().Slice(arrayIndex)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => Count is not 0 && source.Contains(item); + public bool Contains(TSource value) + { + var end = offset + Count; + for (var index = offset; index < end; index++) + { + var item = source[index]; + if (EqualityComparer.Default.Equals(item, value)) + return true; + } + return false; + } public int IndexOf(TSource item) => ReadOnlyListExtensions.IndexOf(source, item, offset, Count); @@ -209,52 +230,52 @@ public static int Count(this in ValueEnumerable [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) - where TList : IReadOnlyList + where TList : struct, IReadOnlyList => source.source.Sum(source.offset, source.Count); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs new file mode 100644 index 000000000..1da50adbf --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TList source) + where TList : struct, IReadOnlyList + => new(source, 0, source.Count); + + [GeneratorBindings(source: "source", sourceImplements: "IReadOnlyList`1", extraParameters: "offset, Count")] + [StructLayout(LayoutKind.Auto)] + public readonly partial struct ValueEnumerable + : IValueReadOnlyList.DisposableEnumerator> + , IList + where TList : struct, IReadOnlyList + { + internal readonly TList source; + internal readonly int offset; + + internal ValueEnumerable(TList source, int offset, int count) + => (this.source, this.offset, Count) = (source, offset, count); + + public readonly int Count { get; } + + public readonly TSource this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + if (index < 0 || index >= Count) + Throw.IndexOutOfRangeException(); + + return source[index + offset]; + } + } + + TSource IReadOnlyList.this[int index] + => this[index]; + + TSource IList.this[int index] + { + get => this[index]; + + [ExcludeFromCodeCoverage] + // ReSharper disable once ValueParameterNotUsed + set => Throw.NotSupportedException(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() + => new(in this); + + DisposableEnumerator IValueEnumerable.GetEnumerator() + => new(in this); + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => new DisposableEnumerator(in this); + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => new DisposableEnumerator(in this); + + + bool ICollection.IsReadOnly + => true; + + public void CopyTo(Span span) + { + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + + Copy(this, 0, span, Count); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TSource[] array, int arrayIndex) + => CopyTo(array.AsSpan().Slice(arrayIndex)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TSource item) + => Count is not 0 && source.DefaultContains(item, offset, Count); + + public int IndexOf(TSource item) + => ValueReadOnlyListExtensions.IndexOf(source, item, offset, Count); + + [ExcludeFromCodeCoverage] + void ICollection.Add(TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + bool ICollection.Remove(TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void ICollection.Clear() + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void IList.Insert(int index, TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void IList.RemoveAt(int index) + => Throw.NotSupportedException(); + + [StructLayout(LayoutKind.Auto)] + public struct Enumerator + { + readonly TList source; + readonly int end; + int index; + + internal Enumerator(in ValueEnumerable enumerable) + { + source = enumerable.source; + index = enumerable.offset - 1; + end = index + enumerable.Count; + } + + public TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index <= end; + } + + [StructLayout(LayoutKind.Auto)] + public struct DisposableEnumerator + : IEnumerator + { + readonly TList source; + readonly int end; + int index; + + internal DisposableEnumerator(in ValueEnumerable enumerable) + { + source = enumerable.source; + index = enumerable.offset - 1; + end = index + enumerable.Count; + } + + public TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + TSource IEnumerator.Current + => source[index]; + object? IEnumerator.Current + // ReSharper disable once HeapView.PossibleBoxingAllocation + => source[index]; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index <= end; + + [ExcludeFromCodeCoverage] + public readonly void Reset() + => Throw.NotSupportedException(); + + public readonly void Dispose() { } + } + + #region Conversion + + ValueEnumerable AsValueEnumerable() + => this; + + TList AsEnumerable() + => source; + + #endregion + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerable Skip(int count) + { + var (skipCount, takeCount) = Utils.Skip(Count, count); + return new ValueEnumerable(source, offset + skipCount, takeCount); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerable Take(int count) + => new(source, offset, Utils.Take(Count, count)); + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this in ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TList : struct, IReadOnlyList + => source.source.Sum(source.offset, source.Count); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs deleted file mode 100644 index 62c8a5a6e..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValuesReadOnlyList.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyListExtensions.ValueEnumerable, TSource> AsValueEnumerable(this IValueReadOnlyList source) - where TEnumerator : struct, IEnumerator - => ReadOnlyListExtensions.AsValueEnumerable(source); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyListExtensions.ValueEnumerable AsValueEnumerable(this TList source) - where TList : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => ReadOnlyListExtensions.AsValueEnumerable(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs similarity index 97% rename from NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs index 5d0618caa..91a344b74 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs @@ -5,8 +5,14 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static TSource[] ToArray(this TList source) + where TList : struct, IReadOnlyList + => source.ToArray(0, source.Count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] static TSource[] ToArray(this TList source, int offset, int count) where TList : struct, IReadOnlyList @@ -25,11 +31,6 @@ static TSource[] BuildArray(TList source, int offset, int count) } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IMemoryOwner ToArray(this TList source, MemoryPool pool) - where TList : struct, IReadOnlyList - => source.ToArray(pool, 0, source.Count); - [MethodImpl(MethodImplOptions.AggressiveInlining)] static IMemoryOwner ToArray(this TList source, MemoryPool pool, int offset, int count) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs similarity index 91% rename from NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs index 2a61574d5..527c011fe 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs @@ -4,10 +4,11 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this TList source, Func keySelector, IEqualityComparer? comparer = default) + internal static Dictionary ToDictionary(this TList source, Func keySelector, IEqualityComparer? comparer = default) where TList : struct, IReadOnlyList where TKey : notnull => source.ToDictionary(keySelector, comparer, 0, source.Count); @@ -18,8 +19,9 @@ static Dictionary ToDictionary(this TList s where TKey : notnull => source.ToDictionary>(new FunctionWrapper(keySelector), comparer, offset, count); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this TList source, TKeySelector keySelector = default, IEqualityComparer? comparer = default) + internal static Dictionary ToDictionary(this TList source, TKeySelector keySelector = default, IEqualityComparer? comparer = default) where TList : struct, IReadOnlyList where TKey : notnull where TKeySelector : struct, IFunction @@ -104,8 +106,9 @@ static Dictionary ToDictionary ToDictionary(this TList source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) + internal static Dictionary ToDictionary(this TList source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) where TList : struct, IReadOnlyList where TKey : notnull => source.ToDictionary(keySelector, elementSelector, comparer, 0, source.Count); @@ -116,8 +119,9 @@ static Dictionary ToDictionary(t where TKey : notnull => source.ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer, offset, count); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this TList source, TKeySelector keySelector = default, TElementSelector elementSelector = default, IEqualityComparer? comparer = default) + internal static Dictionary ToDictionary(this TList source, TKeySelector keySelector = default, TElementSelector elementSelector = default, IEqualityComparer? comparer = default) where TList : struct, IReadOnlyList where TKey : notnull where TKeySelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs similarity index 90% rename from NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs index 501bdaf6c..a0a9d6de6 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs @@ -4,9 +4,15 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static List ToList(this TList source) + where TList : struct, IReadOnlyList + => source.ToList(0, source.Count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TList source, int offset, int count) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyList.cs similarity index 93% rename from NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyList.cs index a308fae61..c775623c5 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyList.cs @@ -2,12 +2,13 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { - static Option ElementAt(this TList source, int index) + [GeneratorIgnore(false)] + internal static Option ElementAt(this TList source, int index) where TList : struct, IReadOnlyList - => source.ElementAt(index,0, source.Count); + => source.ElementAt(index, 0, source.Count); static Option ElementAt(this TList source, int index, int offset, int count) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyList.cs similarity index 95% rename from NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyList.cs index 0e0792986..9ce96d7ee 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyList.cs @@ -3,10 +3,11 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { - static Option First(this TList source) + [GeneratorIgnore(false)] + internal static Option First(this TList source) where TList : struct, IReadOnlyList => source.First(0, source.Count); diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyList.cs similarity index 96% rename from NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyList.cs index 255f31e50..6a495a374 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyList.cs @@ -2,10 +2,11 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { - static Option Single(this TList source) + [GeneratorIgnore(false)] + internal static Option Single(this TList source) where TList : struct, IReadOnlyList => source.Single(0, source.Count); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs similarity index 97% rename from NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs index 4cad17a7f..de634d7df 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs @@ -8,22 +8,25 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereEnumerable> Where(this TList source, Func predicate) + internal static WhereEnumerable> Where(this TList source, Func predicate) where TList : struct, IReadOnlyList => source.Where(predicate, 0, source.Count); + [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereEnumerable> Where(this TList source, Func predicate, int offset, int count) where TList : struct, IReadOnlyList => source.Where>(new FunctionWrapper(predicate), offset, count); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereEnumerable Where(this TList source, TPredicate predicate = default) + internal static WhereEnumerable Where(this TList source, TPredicate predicate = default) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction => source.Where(predicate, 0, source.Count); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs similarity index 97% rename from NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs index 08e1fe93a..fe68887d4 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs @@ -8,12 +8,13 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] + [GeneratorIgnore(false)] + [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereAtEnumerable> Where(this TList source, Func predicate) + internal static WhereAtEnumerable> Where(this TList source, Func predicate) where TList : struct, IReadOnlyList => source.Where(predicate, 0, source.Count); @@ -23,8 +24,9 @@ static WhereAtEnumerable> Wh where TList : struct, IReadOnlyList => source.WhereAt>(new FunctionWrapper(predicate), offset, count); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereAtEnumerable WhereAt(this TList source, TPredicate predicate = default) + internal static WhereAtEnumerable WhereAt(this TList source, TPredicate predicate = default) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction => source.WhereAt(predicate, 0, source.Count); diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs similarity index 97% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs index 32dffa8b9..d5f342431 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs @@ -8,19 +8,9 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static WhereSelectEnumerable WhereSelect( - this TList source, - TPredicate predicate, - TSelector selector) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.WhereSelect(predicate, selector, 0, source.Count); - [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TList source, diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs index 8d62cea06..856d01c51 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs @@ -195,18 +195,18 @@ public bool Contains(int value, IEqualityComparer? comparer) #region Projection [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RangeSelectVectorEnumerable, Vector>, FunctionWrapper> SelectVector(Func, Vector> vectorSelector, Func selector) + public RangeSelectVectorContext, Vector>, FunctionWrapper> SelectVector(Func, Vector> vectorSelector, Func selector) where TResult : struct => ValueEnumerable.SelectVector(start, Count, vectorSelector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RangeSelectVectorEnumerable SelectVector(TSelector selector = default) + public RangeSelectVectorContext SelectVector(TSelector selector = default) where TSelector : struct, IFunction, Vector>, IFunction where TResult : struct => ValueEnumerable.SelectVector(start, Count, selector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RangeSelectVectorEnumerable SelectVector(TVectorSelector vectorSelector = default, TSelector selector = default) + public RangeSelectVectorContext SelectVector(TVectorSelector vectorSelector = default, TSelector selector = default) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TResult : struct diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 86f2b3613..90818e728 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -174,17 +174,17 @@ public ArraySegmentSelectAtEnumerable source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector, 0, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector, 0, Count); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index f08446e21..08721d353 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -170,17 +170,17 @@ public MemorySelectAtEnumerable source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => ReadOnlyListExtensions.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(this, selector); + => ValueReadOnlyListExtensions.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(this, selector, 0, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => ReadOnlyListExtensions.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(this, selector); + => ValueReadOnlyListExtensions.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(this, selector, 0, Count); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs similarity index 97% rename from NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs index 1c7a68eca..22f744baf 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -8,12 +8,13 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectEnumerable> Select(this TList source, Func selector) + internal static SelectEnumerable> Select(this TList source, Func selector) where TList : struct, IReadOnlyList => source.Select(selector, 0, source.Count); @@ -23,8 +24,9 @@ static SelectEnumerable => source.Select>(new FunctionWrapper(selector), offset, count); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectEnumerable Select(this TList source, TSelector selector = default) + internal static SelectEnumerable Select(this TList source, TSelector selector = default) where TList : struct, IReadOnlyList where TSelector : struct, IFunction => source.Select(selector, 0, source.Count); @@ -105,7 +107,7 @@ public bool Contains(TResult item) => source.Contains(item, default, selector, offset, Count); public int IndexOf(TResult item) - => ReadOnlyListExtensions.IndexOf(source, item, selector, offset, Count); + => IndexOf(source, item, selector, offset, Count); [ExcludeFromCodeCoverage] void ICollection.Add(TResult item) diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 375a7a65a..fdf73b7ee 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -169,17 +169,17 @@ public ArraySegmentSelectAtEnumerable source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector, 0, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector, 0, Count); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 97e1bf9fc..9bc93b1e3 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -164,17 +164,17 @@ public MemorySelectAtEnumerable source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector, 0, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector, 0, Count); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs similarity index 97% rename from NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs index 6a2db9ad6..60e82d14b 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -8,12 +8,13 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] + [GeneratorIgnore(false)] + [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectAtEnumerable> Select(this TList source, Func selector) + internal static SelectAtEnumerable> Select(this TList source, Func selector) where TList : struct, IReadOnlyList => source.Select(selector, 0, source.Count); @@ -23,8 +24,9 @@ static SelectAtEnumerable => source.SelectAt>(new FunctionWrapper(selector), offset, count); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectAtEnumerable SelectAt(this TList source, TSelector selector = default) + internal static SelectAtEnumerable SelectAt(this TList source, TSelector selector = default) where TList : struct, IReadOnlyList where TSelector : struct, IFunction => source.SelectAt(selector, 0, source.Count); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs index a897b04b0..d00c70a84 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs @@ -13,244 +13,58 @@ public static partial class ValueEnumerable { [MethodImpl(MethodImplOptions.AggressiveInlining)] - static RangeSelectVectorEnumerable, Vector>, FunctionWrapper> SelectVector(int start, int count, Func, Vector> vectorSelector, Func selector) + static RangeSelectVectorContext, Vector>, FunctionWrapper> SelectVector(int start, int count, Func, Vector> vectorSelector, Func selector) where TResult : struct => SelectVector, Vector>, FunctionWrapper>(start, count, new FunctionWrapper, Vector>(vectorSelector), new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static RangeSelectVectorEnumerable SelectVector(int start, int count, TSelector selector = default) + static RangeSelectVectorContext SelectVector(int start, int count, TSelector selector = default) where TSelector : struct, IFunction, Vector>, IFunction where TResult : struct => SelectVector(start, count, selector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static RangeSelectVectorEnumerable SelectVector(int start, int count, TVectorSelector vectorSelector = default, TSelector selector = default) + static RangeSelectVectorContext SelectVector(int start, int count, TVectorSelector vectorSelector = default, TSelector selector = default) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TResult : struct => new(start, count, vectorSelector, selector); [GeneratorIgnore] - // [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] - public partial struct RangeSelectVectorEnumerable - : IValueReadOnlyList.DisposableEnumerator> - , IList + public partial struct RangeSelectVectorContext where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TResult : struct { internal readonly int start; + internal readonly int count; internal TVectorSelector vectorSelector; internal TSelector selector; - internal RangeSelectVectorEnumerable(int start, int count, TVectorSelector vectorSelector, TSelector selector) + internal RangeSelectVectorContext(int start, int count, TVectorSelector vectorSelector, TSelector selector) { if (Vector.Count != Vector.Count) Throw.NotSupportedException(); this.start = start; - Count = count; + this.count = count; this.vectorSelector = vectorSelector; this.selector = selector; } - public readonly int Count { get; } + #region Aggregation - public TResult this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); - - return selector.Invoke(start + index); - } - } - TResult IReadOnlyList.this[int index] - => this[index]; - TResult IList.this[int index] - { - get => this[index]; - - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - public readonly Enumerator GetEnumerator() - => new (in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - ArrayExtensions.CopyRange(start, Count, span, vectorSelector, selector); - } - - void ICollection.CopyTo(TResult[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); - - void ICollection.Add(TResult item) - => Throw.NotSupportedException(); - void ICollection.Clear() - => Throw.NotSupportedException(); - - public unsafe bool Contains(TResult item) - { - if (Count is 0) - return false; - - var index = 0; - - if (Vector.IsHardwareAccelerated && Count > Vector.Count * 2) - { - var seed = stackalloc int[Vector.Count]; - if (start is 0) - { - for (var seedIndex = 0; seedIndex < Vector.Count; seedIndex++) - seed[seedIndex] = seedIndex; - } - else - { - for (var seedIndex = 0; seedIndex < Vector.Count; seedIndex++) - seed[seedIndex] = seedIndex + start; - } - - var vector = Unsafe.AsRef>(seed); - var vectorItem = new Vector(item); - if (Vector.EqualsAny(vectorSelector.Invoke(vector), vectorItem)) - return true; - - var vectorIncrement = new Vector(Vector.Count); - vector += vectorIncrement; - for (index = 0; index < Count - Vector.Count; index += Vector.Count) - { - if (Vector.EqualsAny(vectorSelector.Invoke(vector), vectorItem)) - return true; - - vector += vectorIncrement; - } - } - - var end = start + Count; - for (var value = index + start; value < end; value++) - { - if (GenericsOperator.Equals(selector.Invoke(value), item)) - return true; - } - - return false; - } - - bool ICollection.Remove(TResult item) - => Throw.NotSupportedException(); - int IList.IndexOf(TResult item) - { - var end = start + Count; - for (var value = start; value < end; value++) - { - if (EqualityComparer.Default.Equals(selector.Invoke(value), item)) - return value - start; - } - return -1; - } - - void IList.Insert(int index, TResult item) - => Throw.NotSupportedException(); - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - { - TSelector selector; - readonly int end; - int value; - - internal Enumerator(in RangeSelectVectorEnumerable enumerable) - { - selector = enumerable.selector; - value = enumerable.start - 1; - end = value + enumerable.Count; - } - - public TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(value); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++value <= end; - } - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - TSelector selector; - readonly int end; - int value; - - internal DisposableEnumerator(in RangeSelectVectorEnumerable enumerable) - { - selector = enumerable.selector; - value = enumerable.start - 1; - end = value + enumerable.Count; - } - - public TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(value); - } - TResult IEnumerator.Current - => selector.Invoke(value); - object IEnumerator.Current - // ReSharper disable once HeapView.BoxingAllocation - => selector.Invoke(value); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++value <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public void Dispose() { } - } - - #region Aggregation + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count() + => count; - #endregion - #region Quantifier + #endregion + #region Quantifier [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() - => Count is not 0; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TResult value, IEqualityComparer? comparer) - => comparer switch - { - null => Contains(value), - _ => ReadOnlyListExtensions.Contains(this, value, comparer) - }; + => count is not 0; #endregion #region Filtering @@ -266,21 +80,21 @@ public bool Contains(TResult value, IEqualityComparer? comparer) public TResult[] ToArray() { - var result = Utils.AllocateUninitializedArray(Count); - ArrayExtensions.CopyRange(start, Count, result.AsSpan(), vectorSelector, selector); + var result = Utils.AllocateUninitializedArray(count); + ArrayExtensions.CopyRange(start, count, result.AsSpan(), vectorSelector, selector); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(MemoryPool pool) { - var result = pool.RentSliced(Count); - ArrayExtensions.CopyRange(start, Count, result.Memory.Span, vectorSelector, selector); + var result = pool.RentSliced(count); + ArrayExtensions.CopyRange(start, count, result.Memory.Span, vectorSelector, selector); return result; } public List ToList() - => Count switch + => count switch { // ReSharper disable once HeapView.ObjectAllocation.Evident 0 => new List(), @@ -288,66 +102,37 @@ public List ToList() }; #endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this RangeSelectVectorEnumerable source) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TResult : struct - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this RangeSelectVectorEnumerable source) + public static int Sum(this RangeSelectVectorContext source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.Count, source.vectorSelector, source.selector); + => SumRange(source.start, source.count, source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this RangeSelectVectorEnumerable source) + public static long Sum(this RangeSelectVectorContext source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.Count, source.vectorSelector, source.selector); + => SumRange(source.start, source.count, source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this RangeSelectVectorEnumerable source) + public static float Sum(this RangeSelectVectorContext source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.Count, source.vectorSelector, source.selector); + => SumRange(source.start, source.count, source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this RangeSelectVectorEnumerable source) + public static double Sum(this RangeSelectVectorContext source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.Count, source.vectorSelector, source.selector); + => SumRange(source.start, source.count, source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this RangeSelectVectorEnumerable source) + public static decimal Sum(this RangeSelectVectorContext source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction - => SumRange(source.start, source.Count, source.vectorSelector, source.selector); + => SumRange(source.start, source.count, source.vectorSelector, source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs similarity index 93% rename from NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs index 8405360eb..fd3ae3f6f 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs @@ -7,35 +7,21 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(true)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SelectManyEnumerable> SelectMany(this TList source, Func selector) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => source.SelectMany(selector, 0, source.Count); - - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SelectManyEnumerable> SelectMany(this TList source, Func selector, int offset, int count) + internal static SelectManyEnumerable> SelectMany(this TList source, Func selector, int offset, int count) where TList : struct, IReadOnlyList where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => source.SelectMany>(new FunctionWrapper(selector), offset, count); + [GeneratorIgnore(true)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SelectManyEnumerable SelectMany(this TList source, TSelector selector) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.SelectMany(selector, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SelectManyEnumerable SelectMany(this TList source, TSelector selector, int offset, int count) + internal static SelectManyEnumerable SelectMany(this TList source, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyList.cs similarity index 59% rename from NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyList.cs index a564e8749..381062ee4 100644 --- a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyList.cs @@ -4,14 +4,28 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static bool All(this TList source, Func predicate) + where TList : struct, IReadOnlyList + => source.All(predicate, 0, source.Count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool All(this TList source, Func predicate, int offset, int count) where TList : struct, IReadOnlyList => source.All>(new FunctionWrapper(predicate), offset, count); + + [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static bool All(this TList source, TPredicate predicate) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.All(predicate, 0, source.Count); + static bool All(this TList source, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction @@ -26,11 +40,24 @@ static bool All(this TList source, TPredicate predic return true; } + [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static bool All(this TList source, Func predicate) + where TList : struct, IReadOnlyList + => source.All(predicate, 0, source.Count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool All(this TList source, Func predicate, int offset, int count) where TList : struct, IReadOnlyList => source.AllAt>(new FunctionWrapper(predicate), offset, count); + [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static bool AllAt(this TList source, TPredicate predicate) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.AllAt(predicate, 0, source.Count); + static bool AllAt(this TList source, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyList.cs similarity index 84% rename from NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyList.cs index a4cab4ec1..c1c3aa690 100644 --- a/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyList.cs @@ -4,11 +4,12 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source) + internal static bool Any(this TList source) where TList : struct, IReadOnlyList => source.Any(0, source.Count); @@ -18,8 +19,9 @@ static bool Any(this TList source, int offset, int count) => count is not 0; + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source, Func predicate) + internal static bool Any(this TList source, Func predicate) where TList : struct, IReadOnlyList => source.Any(predicate, 0, source.Count); @@ -28,8 +30,9 @@ static bool Any(this TList source, Func predicate where TList : struct, IReadOnlyList => source.Any>(new FunctionWrapper(predicate), offset, count); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source, TPredicate predicate) + internal static bool Any(this TList source, TPredicate predicate) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction => source.Any(predicate, 0, source.Count); @@ -49,8 +52,9 @@ static bool Any(this TList source, TPredicate predic } + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source, Func predicate) + internal static bool Any(this TList source, Func predicate) where TList : struct, IReadOnlyList => source.Any(predicate, 0, source.Count); @@ -59,8 +63,9 @@ static bool Any(this TList source, Func pred where TList : struct, IReadOnlyList => source.AnyAt>(new FunctionWrapper(predicate), offset, count); + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AnyAt(this TList source, TPredicate predicate) + internal static bool AnyAt(this TList source, TPredicate predicate) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction => source.AnyAt(predicate, 0, source.Count); diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs similarity index 87% rename from NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs index df47f3c35..9f7ccb9ab 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs @@ -1,11 +1,14 @@ using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { - public static bool Contains(this TList source, TSource value, IEqualityComparer? comparer = default) + [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static bool Contains(this TList source, TSource value, IEqualityComparer? comparer = default) where TList : struct, IReadOnlyList => source.Contains(value, comparer, 0, source.Count); @@ -27,18 +30,6 @@ static bool Contains(this TList source, TSource value, IEquality return ComparerContains(source, value, comparer, offset, count); - static bool DefaultContains(TList source, TSource value, int offset, int count) - { - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (EqualityComparer.Default.Equals(item, value)) - return true; - } - return false; - } - static bool ComparerContains(TList source, TSource value, IEqualityComparer? comparer, int offset, int count) { comparer ??= EqualityComparer.Default; @@ -53,6 +44,19 @@ static bool ComparerContains(TList source, TSource value, IEqualityComparer(this TList source, TSource value, int offset, int count) + where TList : struct, IReadOnlyList + { + var end = offset + count; + for (var index = offset; index < end; index++) + { + var item = source[index]; + if (EqualityComparer.Default.Equals(item, value)) + return true; + } + return false; + } + static bool Contains(this TList source, TResult value, IEqualityComparer? comparer, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyList.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs similarity index 97% rename from NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs index 14c4efd39..512667e7d 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs @@ -8,11 +8,12 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { + [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static DistinctEnumerable Distinct(this TList source, IEqualityComparer? comparer = default) + internal static DistinctEnumerable Distinct(this TList source, IEqualityComparer? comparer = default) where TList : struct, IReadOnlyList => source.Distinct(comparer, 0, source.Count); diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs similarity index 97% rename from NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs index da3a548fa..0e2d7863f 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs @@ -3,7 +3,7 @@ namespace NetFabric.Hyperlinq { - public static partial class ReadOnlyListExtensions + public static partial class ValueReadOnlyListExtensions { static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, TPredicate predicate, int offset, int count) diff --git a/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyList.cs similarity index 79% rename from NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlyList.cs rename to NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyList.cs index e1e25c18f..e3c33210f 100644 --- a/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyList.cs @@ -4,7 +4,7 @@ namespace NetFabric.Hyperlinq { - static partial class ReadOnlyListExtensions + static partial class ValueReadOnlyListExtensions { public static void Copy(TList source, int sourceOffset, Span destination, int count) where TList : struct, IReadOnlyList @@ -17,12 +17,12 @@ public static void Copy(TList source, int sourceOffset, Span(TList source, int so if (sourceOffset is 0) { - for (var index = 0; index < count; index++) + for (var index = 0; index < count && index < destination.Length; index++) destination[index] = selector.Invoke(source[index]); } else { - for (var index = 0; index < count; index++) + for (var index = 0; index < count && index < destination.Length; index++) destination[index] = selector.Invoke(source[index + sourceOffset]); } } @@ -61,12 +61,12 @@ public static void CopyAt(TList source, int if (sourceOffset is 0) { - for (var index = 0; index < count; index++) + for (var index = 0; index < count && index < destination.Length; index++) destination[index] = selector.Invoke(source[index], index); } else { - for (var index = 0; index < count; index++) + for (var index = 0; index < count && index < destination.Length; index++) destination[index] = selector.Invoke(source[index + sourceOffset], index); } } diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs index f3004b831..419cde6e2 100644 --- a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs @@ -39,93 +39,5 @@ public static int IndexOf(TList source, TSource item, int offset return -1; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOf(TList source, TResult item, TSelector selector, int offset, int count) - where TList : IReadOnlyList - where TSelector : struct, IFunction - { - if (count is 0) - return -1; - - var end = offset + count; - if (Utils.IsValueType()) - { - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(arrayItem), item)) - return index - offset; - } - } - else - { - var defaultComparer = EqualityComparer.Default; - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (defaultComparer.Equals(selector.Invoke(arrayItem), item)) - return index - offset; - } - } - - return -1; - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int IndexOfAt(TList source, TResult item, TSelector selector, int offset, int count) - where TList : IReadOnlyList - where TSelector : struct, IFunction - { - if (count is 0) - return -1; - - if (Utils.IsValueType()) - { - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var listItem = source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(listItem, index), item)) - return index; - } - } - else - { - for (var index = 0; index < count; index++) - { - var listItem = source[index + offset]; - if (EqualityComparer.Default.Equals(selector.Invoke(listItem, index), item)) - return index; - } - } - } - else - { - var defaultComparer = EqualityComparer.Default; - - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var listItem = source[index]; - if (defaultComparer.Equals(selector.Invoke(listItem, index), item)) - return index; - } - } - else - { - for (var index = 0; index < count; index++) - { - var listItem = source[index + offset]; - if (defaultComparer.Equals(selector.Invoke(listItem, index), item)) - return index; - } - } - } - return -1; - } } } diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs new file mode 100644 index 000000000..6f9dbc554 --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs @@ -0,0 +1,131 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class ValueReadOnlyListExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int IndexOf(TList source, TSource item, int offset, int count) + where TList : struct, IReadOnlyList + { + if (count is 0) + return -1; + + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (offset is 0 && count == source.Count && source is IList list) + return list.IndexOf(item); + + var end = offset + count; + if (Utils.IsValueType()) + { + for (var index = offset; index < end; index++) + { + var arrayItem = source[index]; + if (EqualityComparer.Default.Equals(arrayItem, item)) + return index - offset; + } + } + else + { + var defaultComparer = EqualityComparer.Default; + for (var index = offset; index < end; index++) + { + var arrayItem = source[index]; + if (defaultComparer.Equals(arrayItem, item)) + return index - offset; + } + } + + return -1; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int IndexOf(TList source, TResult item, TSelector selector, int offset, int count) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + { + if (count is 0) + return -1; + + var end = offset + count; + if (Utils.IsValueType()) + { + for (var index = offset; index < end; index++) + { + var arrayItem = source[index]; + if (EqualityComparer.Default.Equals(selector.Invoke(arrayItem), item)) + return index - offset; + } + } + else + { + var defaultComparer = EqualityComparer.Default; + for (var index = offset; index < end; index++) + { + var arrayItem = source[index]; + if (defaultComparer.Equals(selector.Invoke(arrayItem), item)) + return index - offset; + } + } + + return -1; + } + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int IndexOfAt(TList source, TResult item, TSelector selector, int offset, int count) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + { + if (count is 0) + return -1; + + if (Utils.IsValueType()) + { + if (offset is 0) + { + for (var index = 0; index < count; index++) + { + var listItem = source[index]; + if (EqualityComparer.Default.Equals(selector.Invoke(listItem, index), item)) + return index; + } + } + else + { + for (var index = 0; index < count; index++) + { + var listItem = source[index + offset]; + if (EqualityComparer.Default.Equals(selector.Invoke(listItem, index), item)) + return index; + } + } + } + else + { + var defaultComparer = EqualityComparer.Default; + + if (offset is 0) + { + for (var index = 0; index < count; index++) + { + var listItem = source[index]; + if (defaultComparer.Equals(selector.Invoke(listItem, index), item)) + return index; + } + } + else + { + for (var index = 0; index < count; index++) + { + var listItem = source[index + offset]; + if (defaultComparer.Equals(selector.Invoke(listItem, index), item)) + return index; + } + } + } + return -1; + } + } +} From 4e904754b8964cce5e0682a55ef5c0b2f8880909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Wed, 17 Mar 2021 21:41:41 +0000 Subject: [PATCH 25/61] Benchmark fixes (#352) --- Benchmarks/AllBenchmarks.md | 62 +++---- Benchmarks/AnyBenchmarks.md | 48 +++--- Benchmarks/AnyPredicateBenchmarks.md | 68 ++++---- Benchmarks/ArrayIterationBenchmarks.md | 30 ++-- Benchmarks/ContainsBenchmarks.md | 70 ++++---- Benchmarks/ContainsComparerBenchmarks.md | 48 +++--- Benchmarks/CountBenchmarks.md | 82 +++++----- Benchmarks/DistinctBenchmarks.md | 66 ++++---- Benchmarks/ElementAtBenchmarks.md | 68 ++++---- Benchmarks/EmptyBenchmarks.md | 20 +-- Benchmarks/FirstBenchmarks.md | 68 ++++---- Benchmarks/RangeBenchmarks.md | 22 +-- Benchmarks/RangeToArrayBenchmarks.md | 24 +-- Benchmarks/RepeatBenchmarks.md | 22 +-- Benchmarks/RepeatToArrayBenchmarks.md | 26 +-- Benchmarks/ReturnBenchmarks.md | 20 +-- Benchmarks/SelectBenchmarks.md | 96 +++++------ Benchmarks/SingleBenchmarks.md | 35 +++- Benchmarks/WhereFirstBenchmarks.md | 79 ++++----- .../Benchmarks/ArrayIterationBenchmarks.cs | 1 - .../Benchmarks/FirstBenchmarks.cs | 2 +- .../Benchmarks/SingleBenchmarks.cs | 20 +-- .../Benchmarks/WhereFirstBenchmarks.cs | 2 +- .../BenchmarksBase.cs | 33 +--- .../NetFabric.Hyperlinq.Benchmarks.csproj | 1 + NetFabric.Hyperlinq.Benchmarks/Program.cs | 13 +- .../RandomBenchmarksBase.cs | 1 + .../SingleBenchmarksBase.cs | 3 - .../Utils/TestAsyncEnumerable.cs | 106 ------------ .../Utils/TestCollection.cs | 143 ---------------- .../Utils/TestEnumerable.cs | 105 ------------ .../Utils/TestList.cs | 154 ------------------ .../Aggregation/Sum.TestData.cs | 50 +++--- .../ToArray/ToArray.ReadOnlyList.Tests.cs | 9 +- .../ToArray/ToArray.ReadOnlySpan.Tests.cs | 6 +- .../Element/ElementAt.TestData.cs | 12 +- .../Generation/Range.TestData.cs | 6 +- .../Generation/Repeat.TestData.cs | 4 +- .../Generation/Return.TestData.cs | 2 +- .../Option/TestData.Option.cs | 16 +- .../Partitioning/Skip.TestData.cs | 18 +- .../Partitioning/SkipTake.TestData.cs | 12 +- .../Partitioning/Take.TestData.cs | 20 ++- .../Projection/SelectVector.TestData.cs | 8 +- .../TestData/TestData.Empty.cs | 104 ++++++------ .../TestData/TestData.Multiple.cs | 34 ++-- .../TestData/TestData.Single.cs | 34 ++-- .../Utils/TestComparer.cs | 8 +- .../Utils/Wrappers/Wrap.AsList.cs | 2 +- ...sAsyncValueEnumerable'1.AsyncEnumerable.cs | 5 +- ...cValueEnumerable'1.AsyncValueEnumerable.cs | 4 + ...sAsyncValueEnumerable'6.AsyncEnumerable.cs | 3 + ...cValueEnumerable'6.AsyncValueEnumerable.cs | 56 ++++--- .../AsValueEnumerable.ArraySegment.cs | 6 +- .../AsValueEnumerable.ReadOnlyList.cs | 13 +- .../AsValueEnumerable.ValueReadOnlyList.cs | 2 +- .../Collections/Generic/ListExtensions.cs | 28 +++- .../Conversion/ToList/ToList.ReadOnlySpan.cs | 42 +---- .../ToList/ToList.ValueReadOnlyCollection.cs | 30 +--- .../ToList/ToList.ValueReadOnlyList.cs | 36 +--- .../Contains/Contains.ValueReadOnlyList.cs | 27 ++- 61 files changed, 801 insertions(+), 1334 deletions(-) delete mode 100644 NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs delete mode 100644 NetFabric.Hyperlinq.Benchmarks/Utils/TestEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs diff --git a/Benchmarks/AllBenchmarks.md b/Benchmarks/AllBenchmarks.md index 9ca9c4cad..98d8f5946 100644 --- a/Benchmarks/AllBenchmarks.md +++ b/Benchmarks/AllBenchmarks.md @@ -17,37 +17,37 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - .NET 6.0 : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET 6.0 Runtime=.NET 6.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 608.4 ns | 8.10 ns | 7.96 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 221.1 ns | 0.87 ns | 0.77 ns | 0.36 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 781.2 ns | 9.45 ns | 7.38 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 208.2 ns | 1.49 ns | 1.17 ns | 0.27 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 770.5 ns | 4.33 ns | 3.84 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 212.3 ns | 1.64 ns | 1.28 ns | 0.28 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 752.9 ns | 10.18 ns | 9.52 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 920.3 ns | 13.31 ns | 11.79 ns | 1.22 | 0.02 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,920.2 ns | 8.37 ns | 6.99 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 279.0 ns | 1.49 ns | 1.40 ns | 0.15 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 537.2 ns | 10.22 ns | 11.77 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 608.8 ns | 5.31 ns | 4.70 ns | 1.13 | 0.03 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 528.5 ns | 3.67 ns | 3.26 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 556.2 ns | 3.01 ns | 2.67 ns | 1.05 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 581.1 ns | 11.64 ns | 10.32 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 930.1 ns | 15.48 ns | 15.20 ns | 1.60 | 0.03 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,856.0 ns | 36.36 ns | 34.01 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 302.0 ns | 1.03 ns | 0.86 ns | 0.16 | 0.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 595.0 ns | 4.34 ns | 4.06 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 192.7 ns | 0.61 ns | 0.51 ns | 0.32 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 749.5 ns | 2.53 ns | 2.37 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 228.9 ns | 2.89 ns | 2.42 ns | 0.31 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 754.4 ns | 7.67 ns | 7.17 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 206.9 ns | 1.72 ns | 1.34 ns | 0.27 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 748.2 ns | 3.10 ns | 2.90 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 611.6 ns | 2.82 ns | 2.50 ns | 0.82 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,871.6 ns | 3.28 ns | 3.07 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 274.0 ns | 0.63 ns | 0.59 ns | 0.15 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 731.6 ns | 9.35 ns | 8.75 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 777.0 ns | 3.04 ns | 2.54 ns | 1.06 | 0.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 723.4 ns | 2.88 ns | 2.55 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 757.4 ns | 4.79 ns | 4.48 ns | 1.05 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 726.2 ns | 4.17 ns | 3.69 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 610.9 ns | 1.23 ns | 1.15 ns | 0.84 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,866.5 ns | 4.85 ns | 3.79 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 302.5 ns | 1.93 ns | 1.80 ns | 0.16 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyBenchmarks.md b/Benchmarks/AnyBenchmarks.md index fbe4e7b45..49998d4bf 100644 --- a/Benchmarks/AnyBenchmarks.md +++ b/Benchmarks/AnyBenchmarks.md @@ -4,7 +4,7 @@ [AnyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 9.399 ns | 0.0537 ns | 0.0419 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 7.945 ns | 0.0236 ns | 0.0209 ns | 0.85 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 8.852 ns | 0.0332 ns | 0.0310 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.780 ns | 0.0216 ns | 0.0181 ns | 0.88 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 20.241 ns | 0.0537 ns | 0.0502 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 10.652 ns | 0.0210 ns | 0.0164 ns | 0.53 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 22.005 ns | 0.1641 ns | 0.1371 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 12.334 ns | 0.0213 ns | 0.0189 ns | 0.56 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.684 ns | 0.0171 ns | 0.0160 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.330 ns | 0.0272 ns | 0.0255 ns | 1.78 | 0.01 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 5.165 ns | 0.0671 ns | 0.0628 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.206 ns | 0.0258 ns | 0.0229 ns | 1.59 | 0.02 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.399 ns | 0.0244 ns | 0.0229 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.548 ns | 0.0258 ns | 0.0452 ns | 0.29 | 0.01 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 5.672 ns | 0.0396 ns | 0.0331 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.553 ns | 0.0118 ns | 0.0111 ns | 0.27 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 67.638 ns | 0.2277 ns | 0.2130 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 64.182 ns | 0.1641 ns | 0.1281 ns | 0.95 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 62.236 ns | 0.3114 ns | 0.2760 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 52.144 ns | 0.1382 ns | 0.1293 ns | 0.84 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 17.738 ns | 0.0473 ns | 0.0369 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 9.871 ns | 0.0625 ns | 0.0554 ns | 0.56 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 21.951 ns | 0.1458 ns | 0.1364 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 13.268 ns | 0.0782 ns | 0.0653 ns | 0.60 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.702 ns | 0.0219 ns | 0.0194 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.799 ns | 0.0076 ns | 0.0067 ns | 0.38 | 0.00 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 5.295 ns | 0.0266 ns | 0.0249 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.553 ns | 0.0143 ns | 0.0126 ns | 0.29 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.409 ns | 0.0167 ns | 0.0139 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.807 ns | 0.0114 ns | 0.0107 ns | 0.33 | 0.00 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 5.814 ns | 0.0171 ns | 0.0152 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.561 ns | 0.0118 ns | 0.0111 ns | 0.27 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 65.851 ns | 1.3129 ns | 2.4007 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 63.001 ns | 0.1889 ns | 0.1767 ns | 0.94 | 0.05 | 0.0191 | - | - | 40 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 62.757 ns | 0.1622 ns | 0.1438 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 58.159 ns | 0.1437 ns | 0.1274 ns | 0.93 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyPredicateBenchmarks.md b/Benchmarks/AnyPredicateBenchmarks.md index 31ce239d6..fcf2606bf 100644 --- a/Benchmarks/AnyPredicateBenchmarks.md +++ b/Benchmarks/AnyPredicateBenchmarks.md @@ -4,7 +4,7 @@ [AnyPredicateBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 540.87 ns | 1.515 ns | 1.182 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 191.82 ns | 0.300 ns | 0.251 ns | 0.35 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 775.48 ns | 1.497 ns | 1.250 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 198.03 ns | 0.750 ns | 0.585 ns | 0.26 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 745.08 ns | 1.510 ns | 1.413 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 204.31 ns | 4.074 ns | 4.184 ns | 0.27 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 745.18 ns | 2.165 ns | 1.808 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 605.35 ns | 1.579 ns | 1.477 ns | 0.81 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,179.82 ns | 5.170 ns | 4.836 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 89.24 ns | 0.240 ns | 0.224 ns | 0.04 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 587.15 ns | 1.060 ns | 0.992 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 539.20 ns | 3.402 ns | 2.656 ns | 0.92 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 536.71 ns | 1.205 ns | 1.068 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 550.71 ns | 11.016 ns | 12.686 ns | 1.03 | 0.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 538.66 ns | 4.845 ns | 4.046 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 605.80 ns | 2.073 ns | 1.618 ns | 1.12 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,073.97 ns | 4.513 ns | 4.001 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 86.68 ns | 1.010 ns | 0.789 ns | 0.04 | 0.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 592.95 ns | 5.427 ns | 4.237 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 192.42 ns | 0.470 ns | 0.393 ns | 0.32 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 749.49 ns | 2.649 ns | 2.348 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 227.31 ns | 1.033 ns | 0.967 ns | 0.30 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 747.52 ns | 2.473 ns | 2.313 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 208.27 ns | 1.093 ns | 1.022 ns | 0.28 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 748.40 ns | 3.902 ns | 3.258 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 611.28 ns | 2.587 ns | 2.293 ns | 0.82 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,865.51 ns | 3.796 ns | 3.365 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 78.57 ns | 0.165 ns | 0.147 ns | 0.04 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 724.87 ns | 3.528 ns | 3.300 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 769.92 ns | 4.524 ns | 3.532 ns | 1.06 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 723.28 ns | 2.886 ns | 2.410 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 729.40 ns | 7.278 ns | 5.682 ns | 1.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 747.92 ns | 2.545 ns | 2.380 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 618.86 ns | 2.077 ns | 1.943 ns | 0.83 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,849.37 ns | 20.568 ns | 17.175 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 79.77 ns | 0.256 ns | 0.227 ns | 0.04 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 6eae55d50..12254b820 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -17,21 +17,21 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - .NET 6.0 : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-PWBPZS : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET 6.0 Runtime=.NET 6.0 +Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | -|----------------------------- |--------- |----------:|----------:|----------:|------:|--------:| -| Foreach | 10000000 | 4.859 ms | 0.0885 ms | 0.0828 ms | 1.00 | 0.00 | -| For | 10000000 | 4.807 ms | 0.0397 ms | 0.0352 ms | 0.99 | 0.02 | -| For_Unsafe | 10000000 | 4.818 ms | 0.0396 ms | 0.0351 ms | 0.99 | 0.02 | -| ForAdamczewski | 10000000 | 4.587 ms | 0.0227 ms | 0.0189 ms | 0.95 | 0.02 | -| ForAdamczewskiUnsafe | 10000000 | 4.121 ms | 0.0432 ms | 0.0383 ms | 0.85 | 0.02 | -| Span | 10000000 | 4.771 ms | 0.0216 ms | 0.0191 ms | 0.98 | 0.02 | -| Memory | 10000000 | 4.804 ms | 0.0539 ms | 0.0504 ms | 0.99 | 0.02 | -| ArraySegment_Foreach | 10000000 | 28.829 ms | 0.2076 ms | 0.1942 ms | 5.93 | 0.10 | -| ArraySegment_For | 10000000 | 8.417 ms | 0.0617 ms | 0.0578 ms | 1.73 | 0.03 | -| ArraySegment_Wrapper_Foreach | 10000000 | 15.080 ms | 0.0738 ms | 0.0690 ms | 3.10 | 0.05 | +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|----------------------------- |--------- |----------:|----------:|----------:|------:|--------:|------:|------:|------:|----------:| +| Foreach | 10000000 | 4.957 ms | 0.0964 ms | 0.0947 ms | 1.00 | 0.00 | - | - | - | 18 B | +| For | 10000000 | 5.003 ms | 0.0330 ms | 0.0258 ms | 1.01 | 0.02 | - | - | - | 17 B | +| For_Unsafe | 10000000 | 4.963 ms | 0.0788 ms | 0.0844 ms | 1.00 | 0.02 | - | - | - | 17 B | +| ForAdamczewski | 10000000 | 4.724 ms | 0.0932 ms | 0.0779 ms | 0.96 | 0.03 | - | - | - | 17 B | +| ForAdamczewskiUnsafe | 10000000 | 4.225 ms | 0.0555 ms | 0.0492 ms | 0.85 | 0.01 | - | - | - | 17 B | +| Span | 10000000 | 4.892 ms | 0.0367 ms | 0.0325 ms | 0.99 | 0.02 | - | - | - | 17 B | +| Memory | 10000000 | 4.910 ms | 0.0249 ms | 0.0221 ms | 0.99 | 0.02 | - | - | - | 17 B | +| ArraySegment_Foreach | 10000000 | 29.163 ms | 0.0954 ms | 0.0892 ms | 5.89 | 0.11 | - | - | - | 68 B | +| ArraySegment_For | 10000000 | 8.499 ms | 0.0435 ms | 0.0364 ms | 1.72 | 0.03 | - | - | - | 34 B | +| ArraySegment_Wrapper_Foreach | 10000000 | 15.324 ms | 0.0627 ms | 0.0587 ms | 3.10 | 0.06 | - | - | - | 34 B | diff --git a/Benchmarks/ContainsBenchmarks.md b/Benchmarks/ContainsBenchmarks.md index b4d98a14b..75499114d 100644 --- a/Benchmarks/ContainsBenchmarks.md +++ b/Benchmarks/ContainsBenchmarks.md @@ -4,7 +4,7 @@ [ContainsBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,41 +14,41 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 40.31 ns | 0.211 ns | 0.176 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 30.98 ns | 0.124 ns | 0.103 ns | 0.77 | 0.00 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 24.17 ns | 0.108 ns | 0.096 ns | 0.60 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 654.06 ns | 1.947 ns | 1.520 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 342.42 ns | 0.897 ns | 0.795 ns | 0.52 | 0.00 | 0.0191 | - | - | 40 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 34.21 ns | 0.205 ns | 0.171 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 38.02 ns | 0.124 ns | 0.110 ns | 1.11 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 35.23 ns | 0.169 ns | 0.150 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 37.38 ns | 0.183 ns | 0.153 ns | 1.06 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,083.85 ns | 5.835 ns | 5.172 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,436.75 ns | 3.264 ns | 2.726 ns | 0.69 | 0.00 | 0.0191 | - | - | 40 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 416.22 ns | 1.444 ns | 1.280 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 530.67 ns | 7.926 ns | 7.414 ns | 1.27 | 0.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 33.91 ns | 0.148 ns | 0.131 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 34.34 ns | 0.523 ns | 0.489 ns | 1.01 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 32.59 ns | 0.119 ns | 0.112 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 35.85 ns | 0.358 ns | 0.317 ns | 1.10 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,931.08 ns | 5.581 ns | 4.947 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,092.36 ns | 22.838 ns | 21.363 ns | 1.08 | 0.01 | 0.0305 | - | - | 64 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 40.78 ns | 0.166 ns | 0.139 ns | 1.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 30.19 ns | 0.114 ns | 0.095 ns | 0.74 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 26.73 ns | 0.065 ns | 0.058 ns | 0.66 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 656.05 ns | 1.734 ns | 1.448 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 293.93 ns | 1.028 ns | 0.802 ns | 0.45 | 0.0191 | - | - | 40 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 36.22 ns | 0.124 ns | 0.103 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 39.83 ns | 0.251 ns | 0.234 ns | 1.10 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 37.12 ns | 0.166 ns | 0.147 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 39.95 ns | 0.189 ns | 0.168 ns | 1.08 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,793.21 ns | 3.049 ns | 2.852 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,143.36 ns | 1.975 ns | 1.649 ns | 0.64 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 658.41 ns | 3.378 ns | 2.994 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 656.36 ns | 1.728 ns | 1.443 ns | 1.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 36.17 ns | 0.155 ns | 0.137 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 39.18 ns | 0.135 ns | 0.112 ns | 1.08 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 37.15 ns | 0.166 ns | 0.147 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 40.14 ns | 0.224 ns | 0.199 ns | 1.08 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,820.96 ns | 7.193 ns | 6.006 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,885.59 ns | 4.615 ns | 4.317 ns | 1.04 | 0.0267 | - | - | 56 B | diff --git a/Benchmarks/ContainsComparerBenchmarks.md b/Benchmarks/ContainsComparerBenchmarks.md index dabeee64c..0cacb4984 100644 --- a/Benchmarks/ContainsComparerBenchmarks.md +++ b/Benchmarks/ContainsComparerBenchmarks.md @@ -4,7 +4,7 @@ [ContainsComparerBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 571.7 ns | 2.71 ns | 2.41 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 220.4 ns | 0.81 ns | 0.71 ns | 0.39 | - | - | - | - | +| Linq_Array | Array | 100 | 575.9 ns | 2.52 ns | 2.10 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 199.6 ns | 0.87 ns | 0.77 ns | 0.35 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 763.3 ns | 6.91 ns | 6.12 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 327.9 ns | 0.96 ns | 0.85 ns | 0.43 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 792.1 ns | 3.07 ns | 2.72 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 332.2 ns | 1.20 ns | 1.13 ns | 0.42 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 757.2 ns | 3.71 ns | 3.47 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 331.4 ns | 0.65 ns | 0.54 ns | 0.44 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 789.7 ns | 2.80 ns | 2.62 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 333.3 ns | 0.77 ns | 0.68 ns | 0.42 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 756.8 ns | 2.23 ns | 1.97 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 684.0 ns | 3.06 ns | 2.87 ns | 0.90 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 759.8 ns | 1.27 ns | 1.06 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 649.4 ns | 3.74 ns | 3.32 ns | 0.85 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,183.8 ns | 7.23 ns | 6.41 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,415.5 ns | 3.39 ns | 3.01 ns | 0.65 | 0.0191 | - | - | 40 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,895.1 ns | 4.91 ns | 4.10 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,105.4 ns | 3.08 ns | 2.58 ns | 0.58 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 569.8 ns | 2.71 ns | 2.40 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 571.1 ns | 2.82 ns | 2.64 ns | 1.00 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 790.5 ns | 2.44 ns | 2.04 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 766.6 ns | 4.24 ns | 3.76 ns | 0.97 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 572.3 ns | 3.82 ns | 3.38 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 570.8 ns | 2.84 ns | 2.65 ns | 1.00 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 761.0 ns | 3.49 ns | 2.91 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 818.4 ns | 3.95 ns | 3.09 ns | 1.08 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 572.3 ns | 3.40 ns | 3.18 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 698.5 ns | 2.32 ns | 2.05 ns | 1.22 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 792.3 ns | 2.21 ns | 1.96 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 678.2 ns | 2.09 ns | 1.86 ns | 0.86 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,013.6 ns | 6.11 ns | 5.42 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,038.9 ns | 5.39 ns | 4.50 ns | 1.01 | 0.0305 | - | - | 64 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,891.4 ns | 2.30 ns | 2.04 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,870.7 ns | 4.38 ns | 3.89 ns | 0.99 | 0.0267 | - | - | 56 B | diff --git a/Benchmarks/CountBenchmarks.md b/Benchmarks/CountBenchmarks.md index d7b4d7151..5bd360155 100644 --- a/Benchmarks/CountBenchmarks.md +++ b/Benchmarks/CountBenchmarks.md @@ -4,7 +4,7 @@ [CountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |--------------:|----------:|----------:|-------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 9.3451 ns | 0.0531 ns | 0.0471 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Array | Array | 100 | 0.5892 ns | 0.0115 ns | 0.0102 ns | 0.06 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 7.4762 ns | 0.0154 ns | 0.0136 ns | 0.80 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 371.9204 ns | 1.3762 ns | 1.2873 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 598.6976 ns | 3.1483 ns | 2.9449 ns | 1.61 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 141.0301 ns | 0.3586 ns | 0.3179 ns | 0.38 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.5363 ns | 0.0178 ns | 0.0157 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Value | Collection_Value | 100 | 598.3502 ns | 2.1699 ns | 1.9236 ns | 131.90 | 0.65 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.6839 ns | 0.0158 ns | 0.0140 ns | 1.69 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.2798 ns | 0.0244 ns | 0.0228 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Value | List_Value | 100 | 2.7498 ns | 0.0396 ns | 0.0331 ns | 0.52 | 0.01 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.5510 ns | 0.0117 ns | 0.0104 ns | 0.29 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,063.9368 ns | 6.4213 ns | 5.0133 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,202.7993 ns | 3.1090 ns | 2.7560 ns | 0.58 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 265.1278 ns | 0.7708 ns | 0.7210 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 389.1150 ns | 1.3920 ns | 1.2339 ns | 1.47 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 257.5446 ns | 1.0796 ns | 0.9570 ns | 0.97 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.5106 ns | 0.0228 ns | 0.0202 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 390.2365 ns | 1.4122 ns | 1.1793 ns | 86.50 | 0.47 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.5762 ns | 0.0077 ns | 0.0065 ns | 0.35 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.2694 ns | 0.0240 ns | 0.0212 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Reference | List_Reference | 100 | 389.6645 ns | 2.3961 ns | 2.1241 ns | 73.95 | 0.54 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.6639 ns | 0.0215 ns | 0.0168 ns | 0.32 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,970.4167 ns | 6.2231 ns | 5.8211 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,811.8537 ns | 2.0555 ns | 1.8222 ns | 0.92 | 0.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |--------------:|-----------:|----------:|-------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 11.2255 ns | 0.0273 ns | 0.0228 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Array | Array | 100 | 0.9603 ns | 0.0093 ns | 0.0087 ns | 0.09 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.9730 ns | 0.0152 ns | 0.0127 ns | 0.71 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 355.4883 ns | 1.6482 ns | 1.4611 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 603.7159 ns | 2.1824 ns | 1.9346 ns | 1.70 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 158.3521 ns | 0.2623 ns | 0.2454 ns | 0.45 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 4.6527 ns | 0.0269 ns | 0.0251 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Value | Collection_Value | 100 | 605.6038 ns | 3.7534 ns | 3.5109 ns | 130.17 | 1.10 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.7639 ns | 0.0187 ns | 0.0175 ns | 1.67 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 5.4788 ns | 0.0126 ns | 0.0098 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Value | List_Value | 100 | 2.0882 ns | 0.0132 ns | 0.0110 ns | 0.38 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.6687 ns | 0.0630 ns | 0.0647 ns | 0.30 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,821.3896 ns | 3.9189 ns | 3.4740 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 939.0860 ns | 3.5278 ns | 3.2999 ns | 0.52 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 348.7667 ns | 1.4129 ns | 1.2525 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 603.3495 ns | 2.1976 ns | 1.9481 ns | 1.73 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 365.2241 ns | 1.1188 ns | 0.9918 ns | 1.05 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.6612 ns | 0.0173 ns | 0.0153 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 606.8740 ns | 2.6887 ns | 2.3835 ns | 130.20 | 0.71 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.5391 ns | 0.0104 ns | 0.0087 ns | 0.33 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 5.5106 ns | 0.0544 ns | 0.0482 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Reference | List_Reference | 100 | 610.2956 ns | 12.0029 ns | 9.3710 ns | 110.85 | 2.17 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.6216 ns | 0.0127 ns | 0.0119 ns | 0.29 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,819.4181 ns | 4.6820 ns | 4.1505 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,589.0589 ns | 4.1811 ns | 3.4914 ns | 0.87 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/DistinctBenchmarks.md b/Benchmarks/DistinctBenchmarks.md index 977c1269d..be5d4fd87 100644 --- a/Benchmarks/DistinctBenchmarks.md +++ b/Benchmarks/DistinctBenchmarks.md @@ -4,7 +4,7 @@ [DistinctBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |---------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 2.946 μs | 0.0232 μs | 0.0217 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Array | Array | 100 | 1.271 μs | 0.0033 μs | 0.0026 μs | 0.43 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 1.520 μs | 0.0063 μs | 0.0052 μs | 0.52 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 1.463 μs | 0.0050 μs | 0.0047 μs | 0.50 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.545 μs | 0.0047 μs | 0.0044 μs | 0.52 | - | - | - | - | +| Linq_Array | Array | 100 | 2.917 μs | 0.0135 μs | 0.0119 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Array | Array | 100 | 1.325 μs | 0.0056 μs | 0.0049 μs | 0.45 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 1.494 μs | 0.0095 μs | 0.0084 μs | 0.51 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 1.520 μs | 0.0054 μs | 0.0048 μs | 0.52 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.602 μs | 0.0040 μs | 0.0031 μs | 0.55 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.273 μs | 0.0077 μs | 0.0068 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.138 μs | 0.0127 μs | 0.0119 μs | 0.65 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.492 μs | 0.0042 μs | 0.0037 μs | 0.46 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.196 μs | 0.0194 μs | 0.0172 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.227 μs | 0.0177 μs | 0.0148 μs | 0.70 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.513 μs | 0.0045 μs | 0.0040 μs | 0.47 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 3.267 μs | 0.0078 μs | 0.0073 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 2.157 μs | 0.0122 μs | 0.0114 μs | 0.66 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.484 μs | 0.0032 μs | 0.0028 μs | 0.45 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 3.208 μs | 0.0151 μs | 0.0134 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 2.222 μs | 0.0092 μs | 0.0077 μs | 0.69 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.591 μs | 0.0111 μs | 0.0103 μs | 0.50 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 3.273 μs | 0.0100 μs | 0.0078 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_List_Value | List_Value | 100 | 1.463 μs | 0.0052 μs | 0.0049 μs | 0.45 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.869 μs | 0.0025 μs | 0.0019 μs | 0.57 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 3.196 μs | 0.0131 μs | 0.0109 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_List_Value | List_Value | 100 | 1.486 μs | 0.0061 μs | 0.0051 μs | 0.47 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.939 μs | 0.0130 μs | 0.0115 μs | 0.61 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.863 μs | 0.0375 μs | 0.0332 μs | 1.00 | 2.0599 | - | - | 4328 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.634 μs | 0.0108 μs | 0.0090 μs | 0.59 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.568 μs | 0.0196 μs | 0.0164 μs | 1.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.515 μs | 0.0255 μs | 0.0239 μs | 0.60 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.911 μs | 0.0097 μs | 0.0086 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1.726 μs | 0.0113 μs | 0.0105 μs | 0.59 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1.901 μs | 0.0121 μs | 0.0101 μs | 0.65 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 3.206 μs | 0.0117 μs | 0.0109 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.211 μs | 0.0129 μs | 0.0114 μs | 0.69 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.678 μs | 0.0103 μs | 0.0091 μs | 0.84 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 2.897 μs | 0.0096 μs | 0.0085 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1.724 μs | 0.0111 μs | 0.0104 μs | 0.60 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.940 μs | 0.0053 μs | 0.0047 μs | 0.67 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 3.206 μs | 0.0098 μs | 0.0087 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 2.264 μs | 0.0071 μs | 0.0063 μs | 0.71 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.747 μs | 0.0141 μs | 0.0125 μs | 0.86 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 2.913 μs | 0.0181 μs | 0.0151 μs | 1.00 | 2.0599 | - | - | 4312 B | -| StructLinq_List_Reference | List_Reference | 100 | 1.776 μs | 0.0073 μs | 0.0069 μs | 0.61 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.847 μs | 0.0075 μs | 0.0070 μs | 0.63 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 3.197 μs | 0.0147 μs | 0.0131 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_List_Reference | List_Reference | 100 | 2.259 μs | 0.0107 μs | 0.0100 μs | 0.71 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.946 μs | 0.0174 μs | 0.0154 μs | 0.61 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.864 μs | 0.0220 μs | 0.0206 μs | 1.00 | 2.0599 | - | - | 4328 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4.945 μs | 0.0087 μs | 0.0077 μs | 0.63 | 0.0153 | - | - | 40 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.581 μs | 0.0228 μs | 0.0202 μs | 1.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5.285 μs | 0.0824 μs | 0.0731 μs | 0.70 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ElementAtBenchmarks.md b/Benchmarks/ElementAtBenchmarks.md index 7e9c3d193..7471d3f4f 100644 --- a/Benchmarks/ElementAtBenchmarks.md +++ b/Benchmarks/ElementAtBenchmarks.md @@ -4,7 +4,7 @@ [ElementAtBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 19.74 ns | 0.048 ns | 0.043 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 12.87 ns | 0.032 ns | 0.027 ns | 0.65 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 339.30 ns | 6.647 ns | 6.528 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 132.51 ns | 0.342 ns | 0.320 ns | 0.39 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 344.81 ns | 4.847 ns | 4.296 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 137.91 ns | 0.423 ns | 0.375 ns | 0.40 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 10.51 ns | 0.048 ns | 0.040 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 442.80 ns | 0.648 ns | 0.574 ns | 42.12 | 0.18 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,057.40 ns | 5.870 ns | 5.203 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,245.70 ns | 3.073 ns | 2.874 ns | 0.61 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 233.42 ns | 1.091 ns | 0.967 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 254.48 ns | 0.651 ns | 0.577 ns | 1.09 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 236.25 ns | 1.363 ns | 1.275 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 242.72 ns | 3.945 ns | 3.690 ns | 1.03 | 0.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 10.55 ns | 0.056 ns | 0.052 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 316.26 ns | 1.433 ns | 1.340 ns | 29.98 | 0.18 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,934.77 ns | 6.463 ns | 6.046 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,813.34 ns | 3.933 ns | 3.679 ns | 0.94 | 0.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 16.827 ns | 0.0864 ns | 0.0809 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 13.462 ns | 0.0422 ns | 0.0374 ns | 0.80 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 344.429 ns | 1.3959 ns | 1.2375 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 144.601 ns | 0.3814 ns | 0.3381 ns | 0.42 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 344.272 ns | 0.8262 ns | 0.7324 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 149.374 ns | 0.2419 ns | 0.2144 ns | 0.43 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 10.101 ns | 0.1818 ns | 0.1611 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 14.733 ns | 0.1009 ns | 0.0843 ns | 1.46 | 0.02 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,794.986 ns | 5.2256 ns | 4.8880 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 966.367 ns | 3.3670 ns | 2.8116 ns | 0.54 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 342.764 ns | 1.0983 ns | 0.8575 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 366.209 ns | 2.0936 ns | 1.8559 ns | 1.07 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 345.252 ns | 0.9672 ns | 0.8574 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 368.954 ns | 1.2762 ns | 1.0657 ns | 1.07 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 9.997 ns | 0.1035 ns | 0.1151 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 14.667 ns | 0.0498 ns | 0.0416 ns | 1.47 | 0.02 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,791.748 ns | 3.0825 ns | 2.7325 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,609.644 ns | 3.2502 ns | 2.8812 ns | 0.90 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/EmptyBenchmarks.md b/Benchmarks/EmptyBenchmarks.md index d2ed3c2ea..9e7466e56 100644 --- a/Benchmarks/EmptyBenchmarks.md +++ b/Benchmarks/EmptyBenchmarks.md @@ -4,7 +4,7 @@ [EmptyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/EmptyBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,19 +14,19 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------------- |------------ |-----------:|----------:|----------:|------:|------:|------:|------:|----------:| -| Linq_Empty | Empty | 6.3048 ns | 0.0285 ns | 0.0238 ns | 1.000 | - | - | - | - | -| Hyperlinq_Empty | Empty | 0.0330 ns | 0.0057 ns | 0.0051 ns | 0.005 | - | - | - | - | +| Linq_Empty | Empty | 6.4623 ns | 0.0269 ns | 0.0239 ns | 1.000 | - | - | - | - | +| Hyperlinq_Empty | Empty | 0.0000 ns | 0.0000 ns | 0.0000 ns | 0.000 | - | - | - | - | | | | | | | | | | | | -| Linq_Empty_Async | Empty_Async | 40.5115 ns | 0.2056 ns | 0.1924 ns | 1.00 | - | - | - | - | -| Hyperlinq_Empty_Async | Empty_Async | 21.9399 ns | 0.1051 ns | 0.0932 ns | 0.54 | - | - | - | - | +| Linq_Empty_Async | Empty_Async | 40.5485 ns | 0.1036 ns | 0.0865 ns | 1.00 | - | - | - | - | +| Hyperlinq_Empty_Async | Empty_Async | 20.5118 ns | 0.1285 ns | 0.1139 ns | 0.51 | - | - | - | - | diff --git a/Benchmarks/FirstBenchmarks.md b/Benchmarks/FirstBenchmarks.md index e11003dd1..25924bafb 100644 --- a/Benchmarks/FirstBenchmarks.md +++ b/Benchmarks/FirstBenchmarks.md @@ -4,7 +4,7 @@ [FirstBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 21.81 ns | 0.085 ns | 0.071 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 13.40 ns | 0.035 ns | 0.033 ns | 0.61 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 24.64 ns | 0.105 ns | 0.093 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.55 ns | 0.029 ns | 0.025 ns | 0.63 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 25.32 ns | 0.090 ns | 0.075 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 18.55 ns | 0.030 ns | 0.028 ns | 0.73 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 12.96 ns | 0.172 ns | 0.144 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 22.25 ns | 0.075 ns | 0.066 ns | 1.72 | 0.02 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 119.08 ns | 0.366 ns | 0.325 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 75.23 ns | 0.256 ns | 0.226 ns | 0.63 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 20.84 ns | 0.134 ns | 0.118 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 15.79 ns | 0.077 ns | 0.064 ns | 0.76 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 21.51 ns | 0.090 ns | 0.084 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 15.61 ns | 0.084 ns | 0.070 ns | 0.73 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 12.89 ns | 0.022 ns | 0.018 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 21.34 ns | 0.056 ns | 0.044 ns | 1.66 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 112.02 ns | 0.289 ns | 0.256 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 77.45 ns | 0.186 ns | 0.174 ns | 0.69 | 0.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 25.26 ns | 0.111 ns | 0.099 ns | 1.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 13.27 ns | 0.041 ns | 0.039 ns | 0.53 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 25.15 ns | 0.090 ns | 0.070 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.62 ns | 0.043 ns | 0.036 ns | 0.62 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 25.78 ns | 0.090 ns | 0.080 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 19.20 ns | 0.078 ns | 0.073 ns | 0.75 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 13.27 ns | 0.045 ns | 0.035 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 14.94 ns | 0.056 ns | 0.049 ns | 1.13 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 107.07 ns | 0.239 ns | 0.187 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 64.04 ns | 0.376 ns | 0.314 ns | 0.60 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 25.56 ns | 0.119 ns | 0.100 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 40.37 ns | 0.294 ns | 0.261 ns | 1.58 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 25.78 ns | 0.260 ns | 0.203 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 19.42 ns | 0.058 ns | 0.051 ns | 0.75 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 13.51 ns | 0.225 ns | 0.188 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 14.68 ns | 0.035 ns | 0.031 ns | 1.09 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 105.10 ns | 0.225 ns | 0.210 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 71.06 ns | 0.539 ns | 0.504 ns | 0.68 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/RangeBenchmarks.md b/Benchmarks/RangeBenchmarks.md index c62f87ab3..8aa7b271f 100644 --- a/Benchmarks/RangeBenchmarks.md +++ b/Benchmarks/RangeBenchmarks.md @@ -4,7 +4,7 @@ [RangeBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,20 +14,20 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------ |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 427.60 ns | 1.835 ns | 1.532 ns | 1.00 | 0.0191 | - | - | 40 B | -| StructLinq | Range | 100 | 33.82 ns | 0.101 ns | 0.090 ns | 0.08 | - | - | - | - | -| Hyperlinq | Range | 100 | 44.21 ns | 0.177 ns | 0.165 ns | 0.10 | - | - | - | - | +| Linq | Range | 100 | 415.68 ns | 1.053 ns | 0.879 ns | 1.00 | 0.0191 | - | - | 40 B | +| StructLinq | Range | 100 | 34.07 ns | 0.128 ns | 0.107 ns | 0.08 | - | - | - | - | +| Hyperlinq | Range | 100 | 48.49 ns | 0.752 ns | 0.703 ns | 0.12 | - | - | - | - | | | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 4,269.81 ns | 15.076 ns | 14.103 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Range_Async | 100 | 1,285.13 ns | 5.782 ns | 4.514 ns | 0.30 | 0.0153 | - | - | 32 B | +| Linq_Async | Range_Async | 100 | 3,916.42 ns | 14.040 ns | 12.446 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Range_Async | 100 | 1,349.05 ns | 15.800 ns | 13.194 ns | 0.34 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/RangeToArrayBenchmarks.md b/Benchmarks/RangeToArrayBenchmarks.md index 8d49f5026..7fce4e284 100644 --- a/Benchmarks/RangeToArrayBenchmarks.md +++ b/Benchmarks/RangeToArrayBenchmarks.md @@ -4,7 +4,7 @@ [RangeToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeToArrayBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,21 +14,21 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------ |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 87.87 ns | 0.644 ns | 0.570 ns | 1.00 | 0.2218 | - | - | 464 B | -| StructLinq | Range | 100 | 86.41 ns | 0.540 ns | 0.451 ns | 0.98 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Range | 100 | 35.38 ns | 0.474 ns | 0.421 ns | 0.40 | 0.2027 | - | - | 424 B | -| Hyperlinq | Range | 100 | 42.76 ns | 0.530 ns | 0.470 ns | 0.49 | 0.2027 | - | - | 424 B | +| Linq | Range | 100 | 82.53 ns | 0.745 ns | 0.660 ns | 1.00 | 0.2218 | - | - | 464 B | +| StructLinq | Range | 100 | 90.06 ns | 0.547 ns | 0.512 ns | 1.09 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Range | 100 | 36.82 ns | 0.510 ns | 0.477 ns | 0.45 | 0.2027 | - | - | 424 B | +| Hyperlinq | Range | 100 | 45.37 ns | 0.255 ns | 0.226 ns | 0.55 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 103.55 ns | 0.558 ns | 0.494 ns | 1.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Range_Async | 100 | 107.76 ns | 0.840 ns | 0.702 ns | 1.04 | 0.2027 | - | - | 424 B | +| Linq_Async | Range_Async | 100 | 107.46 ns | 1.095 ns | 0.971 ns | 1.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Range_Async | 100 | 145.93 ns | 0.688 ns | 0.610 ns | 1.36 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/RepeatBenchmarks.md b/Benchmarks/RepeatBenchmarks.md index 88c841efc..51a00309f 100644 --- a/Benchmarks/RepeatBenchmarks.md +++ b/Benchmarks/RepeatBenchmarks.md @@ -4,7 +4,7 @@ [RepeatBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,20 +14,20 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 405.32 ns | 1.427 ns | 1.192 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq | Repeat | 100 | 56.87 ns | 0.306 ns | 0.286 ns | 0.14 | - | - | - | - | -| Hyperlinq | Repeat | 100 | 144.72 ns | 0.432 ns | 0.404 ns | 0.36 | - | - | - | - | +| Linq | Repeat | 100 | 392.09 ns | 1.569 ns | 1.225 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq | Repeat | 100 | 34.55 ns | 0.134 ns | 0.119 ns | 0.09 | - | - | - | - | +| Hyperlinq | Repeat | 100 | 167.61 ns | 0.434 ns | 0.406 ns | 0.43 | - | - | - | - | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 5,471.45 ns | 18.660 ns | 16.542 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Repeat_Async | 100 | 925.25 ns | 1.404 ns | 1.244 ns | 0.17 | - | - | - | - | +| Linq_Async | Repeat_Async | 100 | 4,985.76 ns | 17.802 ns | 14.865 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Repeat_Async | 100 | 932.19 ns | 1.904 ns | 1.687 ns | 0.19 | - | - | - | - | diff --git a/Benchmarks/RepeatToArrayBenchmarks.md b/Benchmarks/RepeatToArrayBenchmarks.md index 786ca962d..82fd0c0f4 100644 --- a/Benchmarks/RepeatToArrayBenchmarks.md +++ b/Benchmarks/RepeatToArrayBenchmarks.md @@ -4,7 +4,7 @@ [RepeatToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatToArrayBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,22 +14,22 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------- |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 94.97 ns | 0.552 ns | 0.461 ns | 1.00 | 0.2180 | - | - | 456 B | -| StructLinq | Repeat | 100 | 110.09 ns | 0.441 ns | 0.368 ns | 1.16 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Repeat | 100 | 26.88 ns | 0.414 ns | 0.367 ns | 0.28 | 0.2027 | - | - | 424 B | -| Hyperlinq | Repeat | 100 | 52.58 ns | 0.396 ns | 0.371 ns | 0.55 | 0.2027 | - | - | 424 B | -| Hyperlinq_SIMD | Repeat | 100 | 37.14 ns | 0.165 ns | 0.129 ns | 0.39 | 0.2027 | - | - | 424 B | +| Linq | Repeat | 100 | 91.48 ns | 0.341 ns | 0.285 ns | 1.00 | 0.2180 | - | - | 456 B | +| StructLinq | Repeat | 100 | 110.52 ns | 0.520 ns | 0.461 ns | 1.21 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Repeat | 100 | 28.03 ns | 0.611 ns | 0.654 ns | 0.31 | 0.2027 | - | - | 424 B | +| Hyperlinq | Repeat | 100 | 55.85 ns | 0.942 ns | 1.122 ns | 0.61 | 0.2027 | - | - | 424 B | +| Hyperlinq_SIMD | Repeat | 100 | 40.77 ns | 0.343 ns | 0.304 ns | 0.45 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 98.63 ns | 0.675 ns | 0.598 ns | 1.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Repeat_Async | 100 | 163.81 ns | 0.743 ns | 0.659 ns | 1.66 | 0.2027 | - | - | 424 B | +| Linq_Async | Repeat_Async | 100 | 92.87 ns | 0.784 ns | 0.733 ns | 1.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Repeat_Async | 100 | 118.72 ns | 0.475 ns | 0.422 ns | 1.28 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/ReturnBenchmarks.md b/Benchmarks/ReturnBenchmarks.md index 8aa284d6b..df58a0150 100644 --- a/Benchmarks/ReturnBenchmarks.md +++ b/Benchmarks/ReturnBenchmarks.md @@ -4,7 +4,7 @@ [ReturnBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReturnBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,19 +14,19 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |----------------------- |------------- |----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Return | Return | 24.887 ns | 0.1063 ns | 0.0888 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_Return | Return | 8.713 ns | 0.0220 ns | 0.0206 ns | 0.35 | - | - | - | - | +| Linq_Return | Return | 15.616 ns | 0.0868 ns | 0.0812 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_Return | Return | 8.962 ns | 0.0241 ns | 0.0214 ns | 0.57 | - | - | - | - | | | | | | | | | | | | -| Linq_Return_Async | Return_Async | 54.678 ns | 1.0231 ns | 0.8544 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Return_Async | Return_Async | 42.313 ns | 0.1122 ns | 0.1049 ns | 0.77 | - | - | - | - | +| Linq_Return_Async | Return_Async | 56.312 ns | 0.2665 ns | 0.2080 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Return_Async | Return_Async | 42.660 ns | 0.6350 ns | 0.5940 ns | 0.75 | - | - | - | - | diff --git a/Benchmarks/SelectBenchmarks.md b/Benchmarks/SelectBenchmarks.md index 3f7a0cbfe..c02fe1adb 100644 --- a/Benchmarks/SelectBenchmarks.md +++ b/Benchmarks/SelectBenchmarks.md @@ -4,7 +4,7 @@ [SelectBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,54 +14,54 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 649.3 ns | 3.81 ns | 3.38 ns | 649.3 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 213.9 ns | 0.40 ns | 0.35 ns | 213.8 ns | 0.33 | 0.00 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 224.7 ns | 2.42 ns | 3.54 ns | 223.5 ns | 0.35 | 0.01 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 252.0 ns | 7.48 ns | 22.05 ns | 245.4 ns | 0.41 | 0.03 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 219.1 ns | 0.57 ns | 0.50 ns | 219.1 ns | 0.34 | 0.00 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 207.1 ns | 0.69 ns | 0.61 ns | 207.2 ns | 0.32 | 0.00 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 298.9 ns | 1.97 ns | 1.64 ns | 298.5 ns | 0.46 | 0.00 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 236.4 ns | 0.81 ns | 0.68 ns | 236.3 ns | 0.36 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,244.7 ns | 6.85 ns | 5.72 ns | 1,243.7 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 795.1 ns | 2.18 ns | 1.93 ns | 795.4 ns | 0.64 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 238.8 ns | 0.86 ns | 0.67 ns | 238.9 ns | 0.19 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,247.5 ns | 4.97 ns | 4.41 ns | 1,246.0 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 791.6 ns | 1.71 ns | 1.42 ns | 790.9 ns | 0.63 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 208.1 ns | 0.58 ns | 0.48 ns | 208.2 ns | 0.17 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,191.8 ns | 5.52 ns | 4.89 ns | 1,189.7 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 369.3 ns | 1.11 ns | 0.98 ns | 369.3 ns | 0.31 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value_For | List_Value | 100 | 396.5 ns | 1.39 ns | 1.16 ns | 396.5 ns | 0.33 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value_Foreach | List_Value | 100 | 413.4 ns | 1.93 ns | 1.71 ns | 413.1 ns | 0.35 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,335.0 ns | 33.17 ns | 31.03 ns | 8,338.7 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,470.6 ns | 17.71 ns | 14.79 ns | 6,471.6 ns | 0.78 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 975.0 ns | 3.38 ns | 3.16 ns | 974.2 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 517.4 ns | 2.24 ns | 1.99 ns | 517.5 ns | 0.53 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 529.0 ns | 4.08 ns | 3.61 ns | 528.2 ns | 0.54 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 975.0 ns | 4.34 ns | 3.85 ns | 975.4 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 566.8 ns | 2.68 ns | 2.24 ns | 565.9 ns | 0.58 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 592.6 ns | 1.66 ns | 1.47 ns | 592.2 ns | 0.61 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 958.7 ns | 6.11 ns | 5.10 ns | 957.0 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 567.4 ns | 2.49 ns | 2.08 ns | 566.6 ns | 0.59 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference_For | List_Reference | 100 | 401.4 ns | 1.10 ns | 1.03 ns | 401.4 ns | 0.42 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 434.3 ns | 0.92 ns | 0.77 ns | 434.2 ns | 0.45 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,852.8 ns | 27.00 ns | 22.54 ns | 7,850.5 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,290.5 ns | 9.09 ns | 8.06 ns | 6,292.2 ns | 0.80 | 0.00 | 0.0153 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 662.5 ns | 13.09 ns | 12.85 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 234.5 ns | 0.94 ns | 0.84 ns | 0.35 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 225.5 ns | 0.73 ns | 0.61 ns | 0.34 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 209.5 ns | 0.83 ns | 0.78 ns | 0.32 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 198.5 ns | 0.69 ns | 0.64 ns | 0.30 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 208.6 ns | 0.48 ns | 0.45 ns | 0.31 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 353.6 ns | 1.81 ns | 1.69 ns | 0.53 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 237.4 ns | 1.06 ns | 0.99 ns | 0.36 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,214.8 ns | 5.55 ns | 4.92 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 738.4 ns | 4.03 ns | 3.77 ns | 0.61 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 210.4 ns | 0.54 ns | 0.47 ns | 0.17 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,165.4 ns | 4.55 ns | 3.80 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 736.0 ns | 3.95 ns | 3.30 ns | 0.63 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 210.7 ns | 0.78 ns | 0.69 ns | 0.18 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,169.6 ns | 5.22 ns | 4.63 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 371.5 ns | 1.38 ns | 1.22 ns | 0.32 | - | - | - | - | +| Hyperlinq_List_Value_For | List_Value | 100 | 377.6 ns | 1.43 ns | 1.27 ns | 0.32 | - | - | - | - | +| Hyperlinq_List_Value_Foreach | List_Value | 100 | 391.5 ns | 1.21 ns | 1.07 ns | 0.33 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,242.1 ns | 26.11 ns | 21.80 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,225.4 ns | 15.83 ns | 14.03 ns | 0.72 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,166.3 ns | 8.20 ns | 7.27 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 786.8 ns | 2.88 ns | 2.41 ns | 0.67 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 791.6 ns | 9.23 ns | 8.18 ns | 0.68 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,196.1 ns | 2.06 ns | 1.61 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 737.8 ns | 2.97 ns | 2.78 ns | 0.62 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 814.8 ns | 2.78 ns | 2.46 ns | 0.68 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,201.1 ns | 3.43 ns | 2.86 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 735.1 ns | 2.54 ns | 2.12 ns | 0.61 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference_For | List_Reference | 100 | 405.1 ns | 1.33 ns | 1.18 ns | 0.34 | - | - | - | - | +| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 399.4 ns | 1.41 ns | 1.18 ns | 0.33 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,095.8 ns | 37.36 ns | 29.17 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,536.8 ns | 16.65 ns | 15.58 ns | 0.78 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SingleBenchmarks.md b/Benchmarks/SingleBenchmarks.md index 63592b5ee..ef8be53fa 100644 --- a/Benchmarks/SingleBenchmarks.md +++ b/Benchmarks/SingleBenchmarks.md @@ -17,12 +17,35 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - .NET 6.0 : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-QTIORM : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET 6.0 Runtime=.NET 6.0 Categories=AsyncEnumerable_Value +Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | -|-------------------------------- |------ |---------:|---------:|---------:|------:|------:|------:|----------:| -| Hyperlinq_AsyncEnumerable_Value | 1 | 84.27 ns | 0.499 ns | 0.443 ns | - | - | - | - | +| Method | Categories | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------- |-------------------------- |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 11.111 ns | 0.1723 ns | 0.2783 ns | 11.048 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 14.543 ns | 0.1511 ns | 0.1339 ns | 14.520 ns | 1.31 | 0.03 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 31.916 ns | 1.9593 ns | 5.7769 ns | 29.905 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 17.802 ns | 0.0964 ns | 0.0805 ns | 17.776 ns | 0.58 | 0.08 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 33.340 ns | 1.2638 ns | 3.7263 ns | 33.084 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 21.505 ns | 0.4538 ns | 0.8299 ns | 21.617 ns | 0.67 | 0.06 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 8.142 ns | 0.1845 ns | 0.1895 ns | 8.073 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 17.170 ns | 0.5859 ns | 1.7275 ns | 16.305 ns | 2.11 | 0.25 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 87.198 ns | 0.7828 ns | 0.6940 ns | 87.109 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 27.682 ns | 0.5862 ns | 0.6751 ns | 27.613 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 29.365 ns | 1.7127 ns | 5.0498 ns | 27.674 ns | 1.11 | 0.22 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 29.387 ns | 0.6172 ns | 1.6152 ns | 28.745 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 26.202 ns | 0.7604 ns | 2.1447 ns | 26.031 ns | 0.89 | 0.10 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 7.951 ns | 0.1252 ns | 0.1171 ns | 7.915 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 16.146 ns | 0.3480 ns | 0.6276 ns | 16.051 ns | 2.03 | 0.08 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 89.215 ns | 1.7324 ns | 2.2526 ns | 88.796 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereFirstBenchmarks.md b/Benchmarks/WhereFirstBenchmarks.md index 821bb81a9..4964c5a15 100644 --- a/Benchmarks/WhereFirstBenchmarks.md +++ b/Benchmarks/WhereFirstBenchmarks.md @@ -4,7 +4,7 @@ [WhereFirstBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,51 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-TQOBKL : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 183.2 ns | 0.84 ns | 0.79 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 217.7 ns | 0.92 ns | 0.82 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 223.2 ns | 0.70 ns | 0.62 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 625.9 ns | 2.16 ns | 1.80 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,485.7 ns | 7.43 ns | 6.95 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 560.4 ns | 2.78 ns | 2.46 ns | ? | ? | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 553.1 ns | 3.00 ns | 2.81 ns | ? | ? | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 654.8 ns | 2.75 ns | 2.57 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,637.2 ns | 5.87 ns | 5.20 ns | ? | ? | 0.0496 | - | - | 104 B | - -Benchmarks with issues: - WhereFirstBenchmarks.Linq_Array: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Linq_Enumerable_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Linq_Collection_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Linq_List_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Linq_AsyncEnumerable_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Linq_Enumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Linq_Collection_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Linq_List_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereFirstBenchmarks.Linq_AsyncEnumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|----------:|-----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 650.6 ns | 5.75 ns | 4.49 ns | 651.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Array | Array | 100 | 198.5 ns | 3.99 ns | 6.55 ns | 195.7 ns | 0.31 | 0.01 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 808.7 ns | 12.89 ns | 11.43 ns | 807.9 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 230.4 ns | 3.54 ns | 2.76 ns | 230.0 ns | 0.28 | 0.01 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 833.0 ns | 16.62 ns | 39.18 ns | 819.0 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 265.0 ns | 5.19 ns | 13.85 ns | 258.3 ns | 0.32 | 0.02 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 870.0 ns | 21.85 ns | 63.03 ns | 847.6 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Value | List_Value | 100 | 645.5 ns | 12.66 ns | 17.75 ns | 639.0 ns | 0.71 | 0.06 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,989.3 ns | 36.09 ns | 32.00 ns | 1,973.8 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,029.3 ns | 60.12 ns | 59.04 ns | 3,007.0 ns | 1.52 | 0.04 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 836.0 ns | 23.27 ns | 66.38 ns | 825.5 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 877.0 ns | 17.50 ns | 41.25 ns | 858.1 ns | 1.06 | 0.08 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 858.2 ns | 27.33 ns | 78.85 ns | 829.2 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 891.4 ns | 22.61 ns | 66.67 ns | 877.6 ns | 1.05 | 0.12 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 782.1 ns | 15.12 ns | 13.40 ns | 775.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 782.2 ns | 15.48 ns | 31.26 ns | 780.2 ns | 1.00 | 0.05 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,057.0 ns | 41.10 ns | 103.12 ns | 2,010.2 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,424.3 ns | 53.95 ns | 50.47 ns | 3,427.0 ns | 1.60 | 0.09 | 0.0458 | - | - | 96 B | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs index 43e93bff0..945c58932 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs @@ -5,7 +5,6 @@ namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks { - [SimpleJob(RuntimeMoniker.Net60)] public class ArrayIterationBenchmarks { const int seed = 2982; diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs index c7d91dfe4..a1d579f19 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq.Benchmarks { [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] [CategoriesColumn] - public class FirstBenchmarks: RandomBenchmarksBase + public class FirstBenchmarks: SequentialBenchmarksBase { [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs index cb388733a..93cf2814a 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs @@ -83,11 +83,11 @@ public Option Hyperlinq_List_Value() => .AsValueEnumerable() .Single(); - [BenchmarkCategory("AsyncEnumerable_Value")] - [Benchmark] - public ValueTask> Hyperlinq_AsyncEnumerable_Value() => - asyncEnumerableValue.AsAsyncValueEnumerable() - .SingleAsync(); + // [BenchmarkCategory("AsyncEnumerable_Value")] + // [Benchmark] + // public ValueTask> Hyperlinq_AsyncEnumerable_Value() => + // asyncEnumerableValue.AsAsyncValueEnumerable() + // .SingleAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark] @@ -110,11 +110,11 @@ public Option Hyperlinq_List_Reference() => .AsValueEnumerable() .Single(); - [BenchmarkCategory("AsyncEnumerable_Reference")] - [Benchmark] - public ValueTask> Hyperlinq_AsyncEnumerable_Reference() => - asyncEnumerableReference.AsAsyncValueEnumerable() - .SingleAsync(); + // [BenchmarkCategory("AsyncEnumerable_Reference")] + // [Benchmark] + // public ValueTask> Hyperlinq_AsyncEnumerable_Reference() => + // asyncEnumerableReference.AsAsyncValueEnumerable() + // .SingleAsync(); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs index 89053f3dd..08b9a0383 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq.Benchmarks { [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] [CategoriesColumn] - public class WhereFirstBenchmarks: RandomBenchmarksBase + public class WhereFirstBenchmarks: SequentialBenchmarksBase { [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] diff --git a/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs b/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs index 95c3da63f..d73154b8b 100644 --- a/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs +++ b/NetFabric.Hyperlinq.Benchmarks/BenchmarksBase.cs @@ -5,32 +5,24 @@ namespace NetFabric.Hyperlinq.Benchmarks { - //[SimpleJob(RuntimeMoniker.Net48, baseline: true)] - //[SimpleJob(RuntimeMoniker.NetCoreApp21)] - //[SimpleJob(RuntimeMoniker.NetCoreApp31)] - [SimpleJob(RuntimeMoniker.Net60)] - [MemoryDiagnoser] public abstract class BenchmarksBase { protected const int seed = 42; - + protected int[] array; protected ReadOnlyMemory memory; - protected IEnumerable linqRange; - protected ValueEnumerable.RangeEnumerable hyperlinqRange; - protected IEnumerable enumerableReference; - protected TestEnumerable.Enumerable enumerableValue; + protected Wrap.EnumerableWrapper enumerableValue; protected IReadOnlyCollection collectionReference; - protected TestCollection.Enumerable collectionValue; + protected Wrap.CollectionWrapper collectionValue; protected IReadOnlyList listReference; - protected TestList.Enumerable listValue; + protected Wrap.ListWrapper listValue; protected IAsyncEnumerable asyncEnumerableReference; - protected TestAsyncEnumerable.Enumerable asyncEnumerableValue; + protected Wrap.AsyncEnumerableWrapper asyncEnumerableValue; [GlobalSetup] public abstract void GlobalSetup(); @@ -40,17 +32,10 @@ protected void Initialize(int[] array) this.array = array; memory = array.AsMemory(); - enumerableReference = TestEnumerable.ReferenceType(array); - enumerableValue = TestEnumerable.ValueType(array); - - collectionReference = TestCollection.ReferenceType(array); - collectionValue = TestCollection.ValueType(array); - - listReference = TestList.ReferenceType(array); - listValue = TestList.ValueType(array); - - asyncEnumerableReference = TestAsyncEnumerable.ReferenceType(array); - asyncEnumerableValue = TestAsyncEnumerable.ValueType(array); + enumerableReference = enumerableValue = Wrap.AsEnumerable(array); + collectionReference = collectionValue = Wrap.AsCollection(array); + listReference = listValue = Wrap.AsList(array); + asyncEnumerableReference = asyncEnumerableValue = Wrap.AsAsyncEnumerable(array); } } } diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index d468ec23f..b079575ac 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -14,6 +14,7 @@ + diff --git a/NetFabric.Hyperlinq.Benchmarks/Program.cs b/NetFabric.Hyperlinq.Benchmarks/Program.cs index 4fb00032b..a5e5ca55e 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Program.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Program.cs @@ -1,12 +1,17 @@ -using System; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Diagnosers; +using BenchmarkDotNet.Environments; +using System; using System.IO; using System.Linq; using System.Reflection; using System.Text; using BenchmarkDotNet.Exporters; +using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Loggers; using BenchmarkDotNet.Reports; using BenchmarkDotNet.Running; +using BenchmarkDotNet.Validators; namespace NetFabric.Hyperlinq.Benchmarks { @@ -14,7 +19,11 @@ class Program { static void Main(string[] args) { - foreach (var summary in BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args)) + var config = DefaultConfig.Instance + .AddJob(Job.Default.WithRuntime(CoreRuntime.Core60)) + .AddDiagnoser(MemoryDiagnoser.Default); + + foreach (var summary in BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config)) SaveSummary(summary); } diff --git a/NetFabric.Hyperlinq.Benchmarks/RandomBenchmarksBase.cs b/NetFabric.Hyperlinq.Benchmarks/RandomBenchmarksBase.cs index 47739b1b1..2153ed7cf 100644 --- a/NetFabric.Hyperlinq.Benchmarks/RandomBenchmarksBase.cs +++ b/NetFabric.Hyperlinq.Benchmarks/RandomBenchmarksBase.cs @@ -2,6 +2,7 @@ { public abstract class RandomBenchmarksBase : CountBenchmarksBase { + public override void GlobalSetup() => Initialize(Utils.GetRandomValues(seed, Count)); } diff --git a/NetFabric.Hyperlinq.Benchmarks/SingleBenchmarksBase.cs b/NetFabric.Hyperlinq.Benchmarks/SingleBenchmarksBase.cs index c5edfd688..8ba532dac 100644 --- a/NetFabric.Hyperlinq.Benchmarks/SingleBenchmarksBase.cs +++ b/NetFabric.Hyperlinq.Benchmarks/SingleBenchmarksBase.cs @@ -4,9 +4,6 @@ namespace NetFabric.Hyperlinq.Benchmarks { public abstract class SingleBenchmarksBase : BenchmarksBase { - [Params(1)] - public int Count { get; set; } - public override void GlobalSetup() => Initialize(new[] { 42 }); } diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs deleted file mode 100644 index 701e9ba88..000000000 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestAsyncEnumerable.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; - -namespace NetFabric.Hyperlinq.Benchmarks -{ - public static class TestAsyncEnumerable - { - - public static Enumerable ValueType(int[] array) - => new(array); - - public static IAsyncEnumerable ReferenceType(int[] array) - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new ReferenceEnumerable(array); - - public class Enumerable : IAsyncEnumerable - { - readonly int[] array; - - public Enumerable(int[] array) - => this.array = array; - - public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) - => new(array, cancellationToken); - IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(array, cancellationToken); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AsyncEnumerableExtensions.AsyncValueEnumerable AsAsyncValueEnumerable() - => this.AsAsyncValueEnumerable(); - - public readonly struct GetEnumeratorFunction - : IFunction - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator Invoke(Enumerable source, CancellationToken cancellationToken) - => source.GetAsyncEnumerator(cancellationToken); - } - - public struct Enumerator : IAsyncEnumerator - { - readonly int[] array; - readonly CancellationToken cancellationToken; - int index; - - public Enumerator(int[] array, CancellationToken cancellationToken) - { - this.array = array; - this.cancellationToken = cancellationToken; - index = -1; - } - - public int Current => array[index]; - - public ValueTask MoveNextAsync() - { - cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(++index <= array.Length); - } - - public ValueTask DisposeAsync() - => default; - } - } - - class ReferenceEnumerable : IAsyncEnumerable - { - readonly int[] array; - - public ReferenceEnumerable(int[] array) - => this.array = array; - - public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken) - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new Enumerator(array, cancellationToken); - - class Enumerator : IAsyncEnumerator - { - readonly int[] array; - readonly CancellationToken cancellationToken; - int index; - - public Enumerator(int[] array, CancellationToken cancellationToken) - { - this.array = array; - this.cancellationToken = cancellationToken; - index = -1; - } - - public int Current => array[index]; - - public ValueTask MoveNextAsync() - { - cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(++index < array.Length); - } - - public ValueTask DisposeAsync() - => default; - } - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs deleted file mode 100644 index 795e95dd2..000000000 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestCollection.cs +++ /dev/null @@ -1,143 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq.Benchmarks -{ - public static class TestCollection - { - public static Enumerable ValueType(int[] array) - => new(array); - - public static IReadOnlyCollection ReferenceType(int[] array) - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new EnumerableReferenceType(array); - - public class Enumerable : IReadOnlyCollection, ICollection - { - readonly int[] array; - - public Enumerable(int[] array) - => this.array = array; - - public int Count => array.Length; - - public bool IsReadOnly => true; - - public void Add(int item) => throw new NotSupportedException(); - public bool Remove(int item) => throw new NotSupportedException(); - public void Clear() => throw new NotSupportedException(); - - public bool Contains(int item) - => ((IList)array).Contains(item); - - public void CopyTo(int[] array, int arrayIndex) - => this.array.CopyTo(array, arrayIndex); - - public Enumerator GetEnumerator() - => new(array); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(array); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(array); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyCollectionExtensions.ValueEnumerable AsValueEnumerable() - => ReadOnlyCollectionExtensions.AsValueEnumerable(this); - - public readonly struct GetEnumeratorFunction - : IFunction - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator Invoke(Enumerable source) - => source.GetEnumerator(); - } - - public struct Enumerator : IEnumerator - { - readonly int[] array; - int index; - - public Enumerator(int[] array) - { - this.array = array; - index = -1; - } - - public int Current - => array[index]; - object? IEnumerator.Current - // ReSharper disable once HeapView.BoxingAllocation - => array[index]; - - public bool MoveNext() - => ++index < array.Length; - - public void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - } - -#pragma warning disable HLQ006 // GetEnumerator() or GetAsyncEnumerator() should return a value type. - - class EnumerableReferenceType : IReadOnlyCollection, ICollection - { - readonly int[] array; - - public EnumerableReferenceType(int[] array) - => this.array = array; - - public int Count => array.Length; - - public bool IsReadOnly => true; - - public void Add(int item) - => throw new NotSupportedException(); - public bool Remove(int item) - => throw new NotSupportedException(); - public void Clear() - => throw new NotSupportedException(); - - public bool Contains(int item) - => ((IList)array).Contains(item); - - public void CopyTo(int[] array, int arrayIndex) - => this.array.CopyTo(array, arrayIndex); - - public IEnumerator GetEnumerator() - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new Enumerator(array); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new Enumerator(array); - - class Enumerator : IEnumerator - { - readonly int[] array; - int index = -1; - - public Enumerator(int[] array) => this.array = array; - - public int Current - => array[index]; - object? IEnumerator.Current - // ReSharper disable once HeapView.BoxingAllocation - => array[index]; - - public bool MoveNext() => ++index < array.Length; - - public void Reset() => throw new NotSupportedException(); - - public void Dispose() { } - } - } - -#pragma warning restore HLQ006 // GetEnumerator() or GetAsyncEnumerator() should return a value type. - - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestEnumerable.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestEnumerable.cs deleted file mode 100644 index 397b6e324..000000000 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestEnumerable.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq.Benchmarks -{ - public static class TestEnumerable - { - public static Enumerable ValueType(int[] array) - => new(array); - - public static IEnumerable ReferenceType(int[] array) - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new ReferenceEnumerable(array); - - public class Enumerable : IEnumerable - { - readonly int[] array; - - public Enumerable(int[] array) - => this.array = array; - - public Enumerator GetEnumerator() - => new(array); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(array); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(array); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public EnumerableExtensions.ValueEnumerable AsValueEnumerable() - => this.AsValueEnumerable(); - - public readonly struct GetEnumeratorFunction - : IFunction - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator Invoke(Enumerable source) - => source.GetEnumerator(); - } - - public struct Enumerator : IEnumerator - { - readonly int[] array; - int index; - - public Enumerator(int[] array) - { - this.array = array; - index = -1; - } - - public int Current - => array[index]; - object? IEnumerator.Current - // ReSharper disable once HeapView.BoxingAllocation - => array[index]; - - public bool MoveNext() => ++index < array.Length; - - public void Reset() => throw new NotSupportedException(); - - public void Dispose() { } - } - } - - class ReferenceEnumerable : IEnumerable - { - readonly int[] array; - - public ReferenceEnumerable(int[] array) - => this.array = array; - - public IEnumerator GetEnumerator() - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new Enumerator(array); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new Enumerator(array); - - class Enumerator : IEnumerator - { - readonly int[] array; - int index = -1; - - public Enumerator(int[] array) => this.array = array; - - public int Current - => array[index]; - object? IEnumerator.Current - // ReSharper disable once HeapView.BoxingAllocation - => array[index]; - - public bool MoveNext() => ++index < array.Length; - - public void Reset() => throw new NotSupportedException(); - - public void Dispose() { } - } - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs b/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs deleted file mode 100644 index b14acab8d..000000000 --- a/NetFabric.Hyperlinq.Benchmarks/Utils/TestList.cs +++ /dev/null @@ -1,154 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq.Benchmarks -{ - public static class TestList - { - public static Enumerable ValueType(int[] array) - => new(array); - - public static IReadOnlyList ReferenceType(int[] array) - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new EnumerableReferenceType(array); - - public class Enumerable : IReadOnlyList, IList - { - readonly int[] array; - - public Enumerable(int[] array) - => this.array = array; - - public int Count => array.Length; - - public int this[int index] => array[index]; - - int IList.this[int index] - { - get => array[index]; - set => throw new NotSupportedException(); - } - - public bool IsReadOnly => true; - - public void Add(int item) => throw new NotSupportedException(); - public bool Remove(int item) => throw new NotSupportedException(); - public void Clear() => throw new NotSupportedException(); - public int IndexOf(int item) => throw new NotSupportedException(); - public void Insert(int index, int item) => throw new NotSupportedException(); - public void RemoveAt(int index) => throw new NotSupportedException(); - - public bool Contains(int item) - => ((IList)array).Contains(item); - - public void CopyTo(int[] array, int arrayIndex) - => this.array.CopyTo(array, arrayIndex); - - public Enumerator GetEnumerator() - => new(array); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(array); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(array); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyListExtensions.ValueEnumerable AsValueEnumerable() - => this.AsValueEnumerable(); - - public struct Enumerator : IEnumerator - { - readonly int[] array; - int index; - - public Enumerator(int[] array) - { - this.array = array; - index = -1; - } - - public int Current - => array[index]; - object IEnumerator.Current - // ReSharper disable once HeapView.BoxingAllocation - => array[index]; - - public bool MoveNext() => ++index < array.Length; - - public void Reset() => throw new NotSupportedException(); - - public void Dispose() { } - } - } - -#pragma warning disable HLQ006 // GetEnumerator() or GetAsyncEnumerator() should return a value type. - - class EnumerableReferenceType : IReadOnlyList, IList - { - readonly int[] array; - - public EnumerableReferenceType(int[] array) - => this.array = array; - - public int Count => array.Length; - - public int this[int index] => array[index]; - - int IList.this[int index] - { - get => array[index]; - set => throw new NotSupportedException(); - } - - public bool IsReadOnly => true; - - public void Add(int item) => throw new NotSupportedException(); - public bool Remove(int item) => throw new NotSupportedException(); - public void Clear() => throw new NotSupportedException(); - public int IndexOf(int item) => throw new NotSupportedException(); - public void Insert(int index, int item) => throw new NotSupportedException(); - public void RemoveAt(int index) => throw new NotSupportedException(); - - public bool Contains(int item) - => ((IList)array).Contains(item); - - public void CopyTo(int[] array, int arrayIndex) - => this.array.CopyTo(array, arrayIndex); - - public IEnumerator GetEnumerator() - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new Enumerator(array); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new Enumerator(array); - - class Enumerator : IEnumerator - { - readonly int[] array; - int index = -1; - - public Enumerator(int[] array) => this.array = array; - - public int Current - => array[index]; - object? IEnumerator.Current - // ReSharper disable once HeapView.BoxingAllocation - => array[index]; - - public bool MoveNext() - => ++index < array.Length; - - public void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - } - -#pragma warning restore HLQ006 // GetEnumerator() or GetAsyncEnumerator() should return a value type. - - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs index 56a200f6d..6e2a00ad6 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs @@ -1,6 +1,8 @@ using System; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -8,35 +10,35 @@ public static partial class TestData public static TheoryData Sum => new() { - { new double[] { } }, - { new[] { double.NaN } }, - { new[] { double.PositiveInfinity } }, - { new[] { 1.0 } }, - { new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 } }, - { new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 } }, - { new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 } }, - { new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 } }, - { new[] { double.NaN, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 } }, - { new[] { double.PositiveInfinity, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 } }, - { new[] { double.MaxValue, double.MaxValue } }, - { new[] { double.PositiveInfinity, double.PositiveInfinity } }, + new double[] { }, + new[] { double.NaN }, + new[] { double.PositiveInfinity }, + new[] { 1.0 }, + new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }, + new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }, + new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }, + new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 }, + new[] { double.NaN, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 }, + new[] { double.PositiveInfinity, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 }, + new[] { double.MaxValue, double.MaxValue }, + new[] { double.PositiveInfinity, double.PositiveInfinity } }; public static TheoryData NullableSum => new() { - { new double?[] { } }, - { new double?[] { default } }, - { new double?[] { double.NaN } }, - { new double?[] { double.PositiveInfinity } }, - { new double?[] { 1 } }, - { new double?[] { default, default, default } }, - { new double?[] { default, 2.0, double.NaN, 4.0, default } }, - { new double?[] { default, 2.0, 3.0, 4.0, default } }, - { new double?[] { 1.0, 2.0, default, 4.0, 5.0 } }, - { new double?[] { 1.0, 2.0, 3.0, 4.0, 5.0 } }, - { new double?[] { double.MaxValue, double.MaxValue } }, - { new double?[] { double.PositiveInfinity, double.PositiveInfinity } }, + new double?[] { }, + new double?[] { default }, + new double?[] { double.NaN }, + new double?[] { double.PositiveInfinity }, + new double?[] { 1 }, + new double?[] { default, default, default }, + new double?[] { default, 2.0, double.NaN, 4.0, default }, + new double?[] { default, 2.0, 3.0, 4.0, default }, + new double?[] { 1.0, 2.0, default, 4.0, 5.0 }, + new double?[] { 1.0, 2.0, 3.0, 4.0, 5.0 }, + new double?[] { double.MaxValue, double.MaxValue }, + new double?[] { double.PositiveInfinity, double.PositiveInfinity } }; } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs index 6c2071738..f8db401e1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs @@ -30,9 +30,10 @@ public void ToArray_Must_Succeed(int[] source, int skip, int take) // Assert _ = result.Must() - .BeNotSameAs(source) .BeArrayOf() .BeEqualTo(expected); + if (result.Length is not 0) + _ = result.Must().BeNotSameAs(source); } [Theory] @@ -86,9 +87,10 @@ public void ToArray_Predicate_Must_Succeed(int[] source, int skip, int take, Fun // Assert _ = result.Must() - .BeNotSameAs(source) .BeArrayOf() .BeEqualTo(expected); + if (result.Length is not 0) + _ = result.Must().BeNotSameAs(source); } [Theory] @@ -144,9 +146,10 @@ public void ToArray_PredicateAt_Must_Succeed(int[] source, int skip, int take, F // Assert _ = result.Must() - .BeNotSameAs(source) .BeArrayOf() .BeEqualTo(expected); + if (result.Length is not 0) + _ = result.Must().BeNotSameAs(source); } [Theory] diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs index d3b71673c..4e5928502 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs @@ -52,9 +52,10 @@ public void ToArray_Predicate_Must_Succeed(int[] source, Func predica // Assert _ = result.Must() - .BeNotSameAs(source) .BeArrayOf() .BeEqualTo(expected); + if (result.Length is not 0) + _ = result.Must().BeNotSameAs(source); } [Theory] @@ -102,9 +103,10 @@ public void ToArray_PredicateAt_Must_Succeed(int[] source, Func // Assert _ = result.Must() - .BeNotSameAs(source) .BeArrayOf() .BeEqualTo(expected); + if (result.Length is not 0) + _ = result.Must().BeNotSameAs(source); } [Theory] diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs index 1eaa182f9..4b83f55e0 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -9,13 +11,13 @@ public static partial class TestData public static TheoryData ElementAtOutOfRange => new() { - { new int[] { }, -1 }, - { new int[] { }, 0 }, - { new int[] { }, 1 }, + { Array.Empty(), -1 }, + { Array.Empty(), 0 }, + { Array.Empty(), 1 }, { new[] { 1 }, -1 }, { new[] { 1 }, 1 }, { new[] { 1, 2, 3, 4, 5 }, -1 }, - { new[] { 1, 2, 3, 4, 5 }, 5 }, + { new[] { 1, 2, 3, 4, 5 }, 5 } }; public static TheoryData ElementAt => @@ -24,7 +26,7 @@ public static partial class TestData { new[] { 1 }, 0}, { new[] { 1, 2, 3, 4, 5 }, 0 }, { new[] { 1, 2, 3, 4, 5 }, 2 }, - { new[] { 1, 2, 3, 4, 5 }, 4 }, + { new[] { 1, 2, 3, 4, 5 }, 4 } }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs index e15c5d210..3eac0d4c7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs @@ -14,7 +14,7 @@ public static partial class TestData { -1, 1 }, { -1, 20 }, - { 1, 20 }, + { 1, 20 } }; public static TheoryData Range_SkipTake => @@ -24,7 +24,7 @@ public static partial class TestData { 1, 5, 0 }, { 1, 5, 1 }, { 1, 5, 2 }, - { 1, 5, 20 }, + { 1, 5, 20 } }; public static TheoryData Range_Contains => @@ -36,7 +36,7 @@ public static partial class TestData { 1, 5, 1 }, { 1, 5, 4 }, { 1, 5, 5 }, - { 1, 5, 20 }, + { 1, 5, 20 } }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs index a3db3c380..a625b1626 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs @@ -11,7 +11,7 @@ public static partial class TestData { 0, 0 }, { 0, 1 }, { 0, 5 }, - { 5, 5 }, + { 5, 5 } }; public static TheoryData Repeat_SkipTake => @@ -23,7 +23,7 @@ public static partial class TestData { 1, 5, 1 }, { 1, 5, 4 }, { 1, 5, 5 }, - { 1, 5, 10 }, + { 1, 5, 10 } }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs index e19a56b59..a7afa58f7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs @@ -8,7 +8,7 @@ public static partial class TestData public static TheoryData Return => new() { - int.MinValue, 0, int.MaxValue, + int.MinValue, 0, int.MaxValue }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs b/NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs index 9d87a7a34..ebc5c3512 100644 --- a/NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs +++ b/NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs @@ -1,6 +1,8 @@ using System; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -10,29 +12,29 @@ public static partial class TestData { default, string.Empty, - "string", + "string" }; public static TheoryData OptionNoneSelectMany => new() { - new int[] { }, + Array.Empty(), new[] { 1 }, - new[] { 1, 2, 3, 4, 5 }, + new[] { 1, 2, 3, 4, 5 } }; public static TheoryData OptionSomeSelectMany => new() { - { default, new int[] { } }, + { default, Array.Empty() }, { default, new[] { 1 } }, { default, new[] { 1, 2, 3, 4, 5 } }, - { string.Empty, new int[] { } }, + { string.Empty, Array.Empty() }, { string.Empty, new[] { 1 } }, { string.Empty, new[] { 1, 2, 3, 4, 5 } }, - { "string", new int[] { } }, + { "string", Array.Empty() }, { "string", new[] { 1 } }, - { "string", new[] { 1, 2, 3, 4, 5 } }, + { "string", new[] { 1, 2, 3, 4, 5 } } }; } diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs index ba63c6d75..3d98477e4 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs @@ -1,6 +1,8 @@ -using System.Collections.Generic; +using System; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -8,13 +10,13 @@ public static partial class TestData public static TheoryData Skip_Skip => new() { - { new int[] { }, -1, -1 }, - { new int[] { }, 0, -1 }, - { new int[] { }, 1, -1 }, + { Array.Empty(), -1, -1 }, + { Array.Empty(), 0, -1 }, + { Array.Empty(), 1, -1 }, - { new int[] { }, -1, 0 }, - { new int[] { }, 0, 0 }, - { new int[] { }, 1, 0 }, + { Array.Empty(), -1, 0 }, + { Array.Empty(), 0, 0 }, + { Array.Empty(), 1, 0 }, { new[] { 1 }, -1, -1 }, { new[] { 1 }, 0, 0 }, @@ -26,7 +28,7 @@ public static partial class TestData { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 5, 5 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 10, 10 }, - { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 20, 20 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 20, 20 } }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs index aa2c0ab43..41eb95d4f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs @@ -1,6 +1,8 @@ -using System.Collections.Generic; +using System; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -8,9 +10,9 @@ public static partial class TestData public static TheoryData SkipTake_Take => new() { - { new int[] { }, 0, 0, -1 }, - { new int[] { }, 0, 0, 0 }, - { new int[] { }, 0, 0, 1 }, + { Array.Empty(), 0, 0, -1 }, + { Array.Empty(), 0, 0, 0 }, + { Array.Empty(), 0, 0, 1 }, { new[] { 1 }, 0, 1, -1 }, { new[] { 1 }, 0, 1, 0 }, @@ -19,7 +21,7 @@ public static partial class TestData { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, -1 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, 0 }, - { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, 5 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 2, 5 } }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs index de2add957..4fdd4d97b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs @@ -1,6 +1,8 @@ -using System.Collections.Generic; +using System; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -8,14 +10,14 @@ public static partial class TestData public static TheoryData Take_Take => new() { - { new int[] { }, -1, -1 }, - { new int[] { }, 0, -1 }, - { new int[] { }, 1, -1 }, + { Array.Empty(), -1, -1 }, + { Array.Empty(), 0, -1 }, + { Array.Empty(), 1, -1 }, - { new int[] { }, -1, 0 }, - { new int[] { }, 0, 0 }, - { new int[] { }, 1, 0 }, - { new int[] { }, 0, 1 }, + { Array.Empty(), -1, 0 }, + { Array.Empty(), 0, 0 }, + { Array.Empty(), 1, 0 }, + { Array.Empty(), 0, 1 }, { new[] { 1 }, -1, -1 }, { new[] { 1 }, 0, 0 }, @@ -33,7 +35,7 @@ public static partial class TestData { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 4, 2 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 4 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 10, 10 }, - { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 20, 20 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 20, 20 } }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs index 88d7804b2..9a26a513e 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs @@ -2,6 +2,8 @@ using System.Numerics; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -10,8 +12,8 @@ public static partial class TestData public static TheoryData, Vector>, Func> SelectVector => new() { - { new int[] { }, item => item * 2, item => item * 2 }, - { new[] { 0, }, item => item * 2, item => item * 2 }, + { Array.Empty(), item => item * 2, item => item * 2 }, + { new[] { 0 }, item => item * 2, item => item * 2 }, { new[] { 0, 1}, item => item * 2, item => item * 2 }, { new[] { 0, 1, 2}, item => item * 2, item => item * 2 }, { new[] { 0, 1, 2, 3}, item => item * 2, item => item * 2 }, @@ -22,7 +24,7 @@ public static partial class TestData { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8}, item => item * 2, item => item * 2 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, item => item * 2, item => item * 2 }, { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, item => item * 2, item => item * 2 }, - { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, item => item * 2, item => item * 2 }, + { new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, item => item * 2, item => item * 2 } }; } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs index 95b5c1968..6edd1e225 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs @@ -1,6 +1,8 @@ using System; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -8,47 +10,47 @@ public static partial class TestData public static TheoryData Empty => new() { - new int[] { }, + Array.Empty() }; public static TheoryData SkipEmpty => new() { - { new int[] { }, -1 }, - { new int[] { }, 0 }, - { new int[] { }, 1 }, + { Array.Empty(), -1 }, + { Array.Empty(), 0 }, + { Array.Empty(), 1 }, { new[] { 1 }, 1 }, { new[] { 1 }, 5 }, { new[] { 0, 1, 2 }, 3 }, - { new[] { 0, 1, 2 }, 5 }, + { new[] { 0, 1, 2 }, 5 } }; public static TheoryData TakeEmpty => new() { - { new int[] { }, -1 }, - { new int[] { }, 0 }, - { new int[] { }, 1 }, + { Array.Empty(), -1 }, + { Array.Empty(), 0 }, + { Array.Empty(), 1 }, { new[] { 5 }, -1 }, { new[] { 5 }, 0 }, { new[] { 0, 1, 2, 3, 4, 5 }, -1 }, - { new[] { 0, 1, 2, 3, 4, 5 }, 0 }, + { new[] { 0, 1, 2, 3, 4, 5 }, 0 } }; public static TheoryData SkipTakeEmpty => new() { - { new int[] { }, -1, -1 }, - { new int[] { }, -1, 0 }, - { new int[] { }, 0, -1 }, - { new int[] { }, 0, 0 }, - { new int[] { }, 0, 9 }, - { new int[] { }, 1, 0 }, - { new int[] { }, 1, 9 }, + { Array.Empty(), -1, -1 }, + { Array.Empty(), -1, 0 }, + { Array.Empty(), 0, -1 }, + { Array.Empty(), 0, 0 }, + { Array.Empty(), 0, 9 }, + { Array.Empty(), 1, 0 }, + { Array.Empty(), 1, 9 }, { new[] { 1 }, -1, -1 }, { new[] { 1 }, -1, 0 }, @@ -64,28 +66,28 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 0, 0 }, { new[] { 1, 2, 3, 4, 5 }, 2, 0 }, { new[] { 1, 2, 3, 4, 5 }, 9, 0 }, - { new[] { 1, 2, 3, 4, 5 }, 9, 9 }, + { new[] { 1, 2, 3, 4, 5 }, 9, 9 } }; public static TheoryData> PredicateEmpty => new() { - { new int[] { }, _ => false }, - { new int[] { }, _ => true }, + { Array.Empty(), _ => false }, + { Array.Empty(), _ => true }, { new[] { 1 }, _ => false }, { new[] { 1 }, item => item > 9 }, { new[] { 1, 2, 3, 4, 5 }, _ => false }, - { new[] { 1, 2, 3, 4, 5 }, item => item > 9 }, + { new[] { 1, 2, 3, 4, 5 }, item => item > 9 } }; public static TheoryData> SkipTakePredicateEmpty => new() { - { new int[] { }, 0, 9, _ => false }, - { new int[] { }, 0, 0, _ => true }, - { new int[] { }, 0, 9, item => item > 9 }, + { Array.Empty(), 0, 9, _ => false }, + { Array.Empty(), 0, 0, _ => true }, + { Array.Empty(), 0, 9, item => item > 9 }, { new[] { 1 }, 0, 0, _ => true }, { new[] { 1 }, 9, 9, _ => true }, @@ -95,34 +97,34 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 0, 0, _ => true }, { new[] { 1, 2, 3, 4, 5 }, 9, 9, _ => true }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false }, - { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item > 9 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item > 9 } }; public static TheoryData, Func> PredicatePredicateEmpty => new() { - { new int[] { }, _ => true, _ => true }, + { Array.Empty(), _ => true, _ => true }, { new[] { 1, 2, 3, 4, 5 }, _ => false, _ => false }, { new[] { 1, 2, 3, 4, 5 }, _ => true, _ => false }, - { new[] { 1, 2, 3, 4, 5 }, _ => false, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, _ => false, _ => true } }; public static TheoryData, Func> SkipTakePredicatePredicateEmpty => new() { - { new int[] { }, 0, 9, _ => true, _ => true }, + { Array.Empty(), 0, 9, _ => true, _ => true }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, _ => false }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, _ => false }, - { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, _ => true } }; public static TheoryData> PredicateAtEmpty => new() { - { new int[] { }, (_, __) => false }, - { new int[] { }, (_, __) => true }, + { Array.Empty(), (_, __) => false }, + { Array.Empty(), (_, __) => true }, { new[] { 1 }, (_, __) => false }, { new[] { 1 }, (item, _) => item > 9 }, @@ -130,16 +132,16 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, (_, __) => false }, { new[] { 1, 2, 3, 4, 5 }, (item, _) => item > 9 }, - { new[] { 1, 2, 3, 4, 5 }, (_, index) => index > 9 }, + { new[] { 1, 2, 3, 4, 5 }, (_, index) => index > 9 } }; public static TheoryData> SkipTakePredicateAtEmpty => new() { - { new int[] { }, 0, 9, (_, __) => false }, - { new int[] { }, 0, 0, (_, __) => true }, - { new int[] { }, 0, 9, (item, _) => item > 9 }, - { new int[] { }, 0, 9, (_, index) => index > 9 }, + { Array.Empty(), 0, 9, (_, __) => false }, + { Array.Empty(), 0, 0, (_, __) => true }, + { Array.Empty(), 0, 9, (item, _) => item > 9 }, + { Array.Empty(), 0, 9, (_, index) => index > 9 }, { new[] { 1 }, 0, 0, (_, __) => true }, { new[] { 1 }, 0, 9, (_, __) => false }, @@ -154,66 +156,66 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 2, 0, (_, __) => true }, { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, __) => false }, { new[] { 1, 2, 3, 4, 5 }, 2, 9, (item, _) => item > 9 }, - { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index > 9 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index > 9 } }; public static TheoryData> SelectorEmpty => new() { - { new int[] { }, item => item.ToString() }, + { Array.Empty(), item => item.ToString() } }; public static TheoryData> SkipTakeSelectorEmpty => new() { - { new int[] { }, 0, 0, item => item.ToString() }, - { new int[] { }, 0, 9, item => item.ToString() }, + { Array.Empty(), 0, 0, item => item.ToString() }, + { Array.Empty(), 0, 9, item => item.ToString() }, { new[] { 1 }, 0, 0, item => item.ToString() }, { new[] { 1 }, 9, 9, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, 0, 0, item => item.ToString() }, - { new[] { 1, 2, 3, 4, 5 }, 9, 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 9, 9, item => item.ToString() } }; public static TheoryData> SelectorAtEmpty => new() { - { new int[] { }, (item, index) => $"{item} {index}" }, + { Array.Empty(), (item, index) => $"{item} {index}" } }; public static TheoryData> SkipTakeSelectorAtEmpty => new() { - { new int[] { }, 0, 0, (item, index) => $"{item} {index}" }, - { new int[] { }, 0, 9, (item, index) => $"{item} {index}" }, + { Array.Empty(), 0, 0, (item, index) => $"{item} {index}" }, + { Array.Empty(), 0, 9, (item, index) => $"{item} {index}" }, { new[] { 1 }, 0, 0, (item, index) => $"{item} {index}" }, { new[] { 1 }, 9, 9, (item, index) => $"{item} {index}" }, { new[] { 1, 2, 3, 4, 5 }, 0, 0, (item, index) => $"{item} {index}" }, - { new[] { 1, 2, 3, 4, 5 }, 9, 9, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 9, 9, (item, index) => $"{item} {index}" } }; public static TheoryData, Func> PredicateSelectorEmpty => new() { - { new int[] { }, _ => false, item => item.ToString() }, - { new int[] { }, _ => true, item => item.ToString() }, + { Array.Empty(), _ => false, item => item.ToString() }, + { Array.Empty(), _ => true, item => item.ToString() }, { new[] { 1 }, _ => false, item => item.ToString() }, { new[] { 1 }, item => item > 9, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, _ => false, item => item.ToString() }, - { new[] { 1, 2, 3, 4, 5 }, item => item > 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => item > 9, item => item.ToString() } }; public static TheoryData, Func> SkipTakePredicateSelectorEmpty => new() { - { new int[] { }, 0, 9, _ => false, item => item.ToString() }, - { new int[] { }, 0, 0, _ => true, item => item.ToString() }, - { new int[] { }, 0, 9, item => item > 9, item => item.ToString() }, + { Array.Empty(), 0, 9, _ => false, item => item.ToString() }, + { Array.Empty(), 0, 0, _ => true, item => item.ToString() }, + { Array.Empty(), 0, 9, item => item > 9, item => item.ToString() }, { new[] { 1 }, 0, 0, _ => true, item => item.ToString() }, { new[] { 1 }, 9, 9, _ => true, item => item.ToString() }, @@ -223,7 +225,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 0, 0, _ => true, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, 9, 9, _ => true, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => false, item => item.ToString() }, - { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item > 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item > 9, item => item.ToString() } }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs index 3c7181d1b..84bb7075a 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs @@ -1,6 +1,8 @@ using System; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -8,7 +10,7 @@ public static partial class TestData public static TheoryData Multiple => new() { - { new[] { 1, 2, 3, 4, 5 } }, + new[] { 1, 2, 3, 4, 5 } }; public static TheoryData SkipMultiple => @@ -16,7 +18,7 @@ public static partial class TestData { { new[] { 1, 2, 3, 4, 5 }, -1 }, { new[] { 1, 2, 3, 4, 5 }, 0 }, - { new[] { 1, 2, 3, 4, 5 }, 2 }, + { new[] { 1, 2, 3, 4, 5 }, 2 } }; public static TheoryData TakeMultiple => @@ -24,7 +26,7 @@ public static partial class TestData { { new[] { 1, 2, 3, 4, 5 }, 2 }, { new[] { 1, 2, 3, 4, 5 }, 5 }, - { new[] { 1, 2, 3, 4, 5 }, 9 }, + { new[] { 1, 2, 3, 4, 5 }, 9 } }; public static TheoryData SkipTakeMultiple => @@ -38,7 +40,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 2, 3 }, { new[] { 1, 2, 3, 4, 5 }, -1, 9 }, { new[] { 1, 2, 3, 4, 5 }, 0, 9 }, - { new[] { 1, 2, 3, 4, 5 }, 2, 9 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9 } }; public static TheoryData> PredicateMultiple => @@ -46,7 +48,7 @@ public static partial class TestData { { new[] { 1, 2, 3, 4, 5 }, _ => true }, { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 0 }, - { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1 } }; public static TheoryData> SkipTakePredicateMultiple => @@ -80,7 +82,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, item => (item & 0x01) == 1 }, { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, item => (item & 0x01) == 1 }, { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, item => (item & 0x01) == 1 }, - { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, item => (item & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, item => (item & 0x01) == 1 } }; @@ -90,7 +92,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, _ => true, _ => true }, { new[] { 1, 2, 3, 4, 5 }, _ => true, item => (item & 0x01) == 0 }, - { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1, _ => true } }; public static TheoryData, Func> SkipTakePredicatePredicateMultiple => @@ -99,7 +101,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, _ => true }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, item => (item & 0x01) == 0 }, - { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => (item & 0x01) == 1, _ => true }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => (item & 0x01) == 1, _ => true } }; public static TheoryData> PredicateAtMultiple => @@ -109,7 +111,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, (item, _) => (item & 0x01) == 0 }, { new[] { 1, 2, 3, 4, 5 }, (item, _) => (item & 0x01) == 1 }, { new[] { 1, 2, 3, 4, 5 }, (_, index) => (index & 0x01) == 0 }, - { new[] { 1, 2, 3, 4, 5 }, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5 }, (_, index) => (index & 0x01) == 1 } }; public static TheoryData> SkipTakePredicateAtMultiple => @@ -162,13 +164,13 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, (_, index) => (index & 0x01) == 1 }, { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, -1, 20, (_, index) => (index & 0x01) == 1 }, { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 20, (_, index) => (index & 0x01) == 1 }, - { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (_, index) => (index & 0x01) == 1 }, + { new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 20, (_, index) => (index & 0x01) == 1 } }; public static TheoryData> SelectorMultiple => new() { - { new[] { 1, 2, 3, 4, 5 }, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => item.ToString() } }; public static TheoryData> SkipTakeSelectorMultiple => @@ -182,13 +184,13 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 2, 3, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, -1, 9, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item.ToString() }, - { new[] { 1, 2, 3, 4, 5 }, 2, 9, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, item => item.ToString() } }; public static TheoryData> SelectorAtMultiple => new() { - { new[] { 1, 2, 3, 4, 5 }, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, (item, index) => $"{item} {index}" } }; public static TheoryData> SkipTakeSelectorAtMultiple => @@ -202,7 +204,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 2, 3, (item, index) => $"{item} {index}" }, { new[] { 1, 2, 3, 4, 5 }, -1, 9, (item, index) => $"{item} {index}" }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, (item, index) => $"{item} {index}" }, - { new[] { 1, 2, 3, 4, 5 }, 2, 9, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (item, index) => $"{item} {index}" } }; public static TheoryData, Func> PredicateSelectorMultiple => @@ -210,7 +212,7 @@ public static partial class TestData { { new[] { 1, 2, 3, 4, 5 }, _ => true, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 0, item => item.ToString() }, - { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => (item & 0x01) == 1, item => item.ToString() } }; public static TheoryData, Func> SkipTakePredicateSelectorMultiple => @@ -236,7 +238,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 0, 5, item => (item & 0x01) == 1, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, -1, 9, item => (item & 0x01) == 1, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => (item & 0x01) == 1, item => item.ToString() }, - { new[] { 1, 2, 3, 4, 5 }, 1, 9, item => (item & 0x01) == 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 1, 9, item => (item & 0x01) == 1, item => item.ToString() } }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs index 5a6128766..d316e93cc 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs @@ -1,6 +1,8 @@ using System; using Xunit; +// ReSharper disable HeapView.ObjectAllocation.Evident + namespace NetFabric.Hyperlinq { public static partial class TestData @@ -8,7 +10,7 @@ public static partial class TestData public static TheoryData Single => new() { - { new[] { 1 } }, + new[] { 1 } }; public static TheoryData SkipSingle => @@ -17,7 +19,7 @@ public static partial class TestData { new[] { 1 }, -1 }, { new[] { 1 }, 0 }, - { new[] { 0, 1, 2 }, 2 }, + { new[] { 0, 1, 2 }, 2 } }; public static TheoryData TakeSingle => @@ -25,7 +27,7 @@ public static partial class TestData { { new[] { 1 }, 1 }, - { new[] { 1, 2, 3, 4, 5 }, 1 }, + { new[] { 1, 2, 3, 4, 5 }, 1 } }; public static TheoryData SkipTakeSingle => @@ -37,7 +39,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, -1, 1 }, { new[] { 1, 2, 3, 4, 5 }, 0, 1 }, { new[] { 1, 2, 3, 4, 5 }, 2, 1 }, - { new[] { 1, 2, 3, 4, 5 }, 4, 1 }, + { new[] { 1, 2, 3, 4, 5 }, 4, 1 } }; public static TheoryData> PredicateSingle => @@ -48,7 +50,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, item => item == 1 }, { new[] { 1, 2, 3, 4, 5 }, item => item == 3 }, - { new[] { 1, 2, 3, 4, 5 }, item => item == 5 }, + { new[] { 1, 2, 3, 4, 5 }, item => item == 5 } }; public static TheoryData> SkipTakePredicateSingle => @@ -65,7 +67,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 4, 1, _ => true }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 1 }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 3 }, - { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 5 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 5 } }; public static TheoryData, Func> PredicatePredicateSingle => @@ -74,7 +76,7 @@ public static partial class TestData { new[] { 1 }, _ => true, _ => true }, { new[] { 1, 2, 3, 4, 5 }, item => item == 3, _ => true }, - { new[] { 1, 2, 3, 4, 5 }, _ => true, item => item == 3 }, + { new[] { 1, 2, 3, 4, 5 }, _ => true, item => item == 3 } }; public static TheoryData, Func> SkipTakePredicatePredicateSingle => @@ -83,7 +85,7 @@ public static partial class TestData { new[] { 1 }, 0, 9, _ => true, _ => true }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 3, _ => true }, - { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, item => item == 3 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, _ => true, item => item == 3 } }; public static TheoryData> PredicateAtSingle => @@ -98,7 +100,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, (item, _) => item == 5 }, { new[] { 1, 2, 3, 4, 5 }, (_, index) => index == 0 }, { new[] { 1, 2, 3, 4, 5 }, (_, index) => index == 2 }, - { new[] { 1, 2, 3, 4, 5 }, (_, index) => index == 4 }, + { new[] { 1, 2, 3, 4, 5 }, (_, index) => index == 4 } }; public static TheoryData> SkipTakePredicateAtSingle => @@ -125,13 +127,13 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index == 2 }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, (_, index) => index == 4 }, { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index == 0 }, - { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index == 2 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 9, (_, index) => index == 2 } }; public static TheoryData> SelectorSingle => new() { - { new[] { 1 }, item => item.ToString() }, + { new[] { 1 }, item => item.ToString() } }; public static TheoryData> SkipTakeSelectorSingle => @@ -144,13 +146,13 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 0, 1, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, 2, 1, item => item.ToString() }, - { new[] { 1, 2, 3, 4, 5 }, 4, 1, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 4, 1, item => item.ToString() } }; public static TheoryData> SelectorAtSingle => new() { - { new[] { 1 }, (item, index) => $"{item} {index}" }, + { new[] { 1 }, (item, index) => $"{item} {index}" } }; public static TheoryData> SkipTakeSelectorAtSingle => @@ -164,7 +166,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 0, 1, (item, index) => $"{item} {index}" }, { new[] { 1, 2, 3, 4, 5 }, 2, 1, (item, index) => $"{item} {index}" }, - { new[] { 1, 2, 3, 4, 5 }, 4, 1, (item, index) => $"{item} {index}" }, + { new[] { 1, 2, 3, 4, 5 }, 4, 1, (item, index) => $"{item} {index}" } }; public static TheoryData, Func> PredicateSelectorSingle => @@ -175,7 +177,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, item => item == 1, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, item => item == 3, item => item.ToString() }, - { new[] { 1, 2, 3, 4, 5 }, item => item == 5, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, item => item == 5, item => item.ToString() } }; public static TheoryData, Func> SkipTakePredicateSelectorSingle => @@ -195,7 +197,7 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 4, 1, _ => true, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 1, item => item.ToString() }, { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 3, item => item.ToString() }, - { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 5, item => item.ToString() }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9, item => item == 5, item => item.ToString() } }; } } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs b/NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs index f702d0a0a..4286316a1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace NetFabric.Hyperlinq.UnitTests { @@ -6,12 +7,13 @@ class TestComparer : IEqualityComparer { TestComparer() { } - public static TestComparer Instance { get; } = new TestComparer(); + public static TestComparer Instance { get; } + = new(); - public bool Equals(T x, T y) + public bool Equals(T? x, T? y) => EqualityComparer.Default.Equals(x, y); - public int GetHashCode(T obj) + public int GetHashCode([DisallowNull]T obj) => EqualityComparer.Default.GetHashCode(obj); } } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs index 75fb6bd3a..5ee461a57 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs @@ -34,7 +34,7 @@ public void CopyTo(T[] array, int arrayIndex) => source.CopyTo(array, arrayIndex); public bool Contains(T item) - => ((IList)source).Contains(item); + => ((ICollection)source).Contains(item); public int IndexOf(T item) => ((IList)source).IndexOf(item); diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs index 8660e55b3..73b942c0c 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs @@ -54,9 +54,12 @@ public ValueTask DisposeAsync() #region Conversion - AsyncValueEnumerable AsAsyncEnumerable() + AsyncValueEnumerable AsAsyncValueEnumerable() => this; + IAsyncEnumerable AsAsyncEnumerable() + => source; + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs index 92f272ea1..91c1d5160 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs @@ -14,6 +14,7 @@ public static AsyncValueEnumerable AsAsyncValueEnumerable< where TEnumerator : struct, IAsyncEnumerator => new(source); + [GeneratorBindings(source: "source", sourceImplements: "IAsyncValueEnumerable`2", enumerableType: "IAsyncValueEnumerable")] [StructLayout(LayoutKind.Auto)] public readonly partial struct AsyncValueEnumerable : IAsyncValueEnumerable @@ -37,6 +38,9 @@ IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(Cancellat AsyncValueEnumerable AsAsyncValueEnumerable() => this; + IAsyncEnumerable AsAsyncEnumerable() + => source; + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs index 7439eb4c4..8fd889ac8 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs @@ -74,6 +74,9 @@ IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(Cancellat AsyncValueEnumerable AsAsyncValueEnumerable() => this; + TEnumerable AsAsyncEnumerable() + => source; + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs index 3982190f5..81bbe0e49 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs @@ -42,19 +42,20 @@ public static AsyncValueEnumerable where TGetAsyncEnumerator2 : struct, IFunction => new(source, getAsyncEnumerator, getAsyncEnumerator2); - + + [GeneratorBindings(source: "source", sourceImplements: "IAsyncValueEnumerable`2")] [StructLayout(LayoutKind.Auto)] public partial struct AsyncValueEnumerable - : IAsyncValueEnumerable - where TEnumerable : IAsyncEnumerable + : IAsyncValueEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction { - readonly TEnumerable source; - TGetAsyncEnumerator getAsyncEnumerator; - TGetAsyncEnumerator2 getAsyncEnumerator2; + internal readonly TEnumerable source; + internal TGetAsyncEnumerator getAsyncEnumerator; + internal TGetAsyncEnumerator2 getAsyncEnumerator2; internal AsyncValueEnumerable(TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator, TGetAsyncEnumerator2 getAsyncEnumerator2) => (this.source, this.getAsyncEnumerator, this.getAsyncEnumerator2) = (source, getAsyncEnumerator, getAsyncEnumerator2); @@ -74,97 +75,100 @@ IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(Cancellat AsyncValueEnumerable AsAsyncValueEnumerable() => this; + TEnumerable AsAsyncEnumerable() + => source; + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, int, int>(cancellationToken); + => source.source.SumAsync(cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, int?, int>(cancellationToken); + => source.source.SumAsync(cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, long, long>(cancellationToken); + => source.source.SumAsync(cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, long?, long>(cancellationToken); + => source.source.SumAsync(cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, float, float>(cancellationToken); + => source.source.SumAsync(cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, float?, float>(cancellationToken); + => source.source.SumAsync(cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, double, double>(cancellationToken); + => source.source.SumAsync(cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, double?, double>(cancellationToken); + => source.source.SumAsync(cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, decimal, decimal>(cancellationToken); + => source.source.SumAsync(cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncEnumerable + where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TEnumerator2 : struct where TGetAsyncEnumerator : struct, IFunction where TGetAsyncEnumerator2 : struct, IFunction - => source.SumAsync, TEnumerator, decimal?, decimal>(cancellationToken); + => source.source.SumAsync(cancellationToken); } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index d12f3dd8b..24fd23352 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -151,12 +151,12 @@ public readonly void Dispose() { } #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerable AsEnumerable() + public ArraySegmentValueEnumerable AsValueEnumerable() => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerable AsValueEnumerable() - => this; + public ArraySegment AsEnumerable() + => source; [MethodImpl(MethodImplOptions.AggressiveInlining)] public TSource[] ToArray() diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs index 59b7c9fc8..03040e2fc 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs @@ -101,17 +101,8 @@ public void CopyTo(TSource[] array, int arrayIndex) => CopyTo(array.AsSpan().Slice(arrayIndex)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value) - { - var end = offset + Count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (EqualityComparer.Default.Equals(item, value)) - return true; - } - return false; - } + public bool Contains(TSource item) + => Count is not 0 && source.Contains(item); public int IndexOf(TSource item) => ReadOnlyListExtensions.IndexOf(source, item, offset, Count); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs index 1da50adbf..21529c0a8 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs @@ -87,7 +87,7 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - => Count is not 0 && source.DefaultContains(item, offset, Count); + => Count is not 0 && ValueReadOnlyListExtensions.Contains(source, item); public int IndexOf(TSource item) => ValueReadOnlyListExtensions.IndexOf(source, item, offset, Count); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs index 2343f0ba2..77e919eac 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs @@ -19,15 +19,26 @@ public static ArrayExtensions.ArraySegmentValueEnumerable AsValueEnumer static ArraySegment AsArraySegment(this List source) => new(source.GetItems(), 0, source.Count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static List AsList(this TSource[] source) { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var result = new List(); - var layout = Unsafe.As, ListLayout>(ref result); - layout.items = source; - layout.size = source.Length; - result.Capacity = source.Length; - return result; + return source switch + { + // ReSharper disable once HeapView.ObjectAllocation.Evident + { Length: 0 } => new List(), + _ => WrapArray(source) + }; + + static List WrapArray(TSource[] source) + { + // ReSharper disable once HeapView.ObjectAllocation.Evident + var result = new List(); + var layout = Unsafe.As, ListLayout>(ref result); + layout.items = source; + layout.size = source.Length; + result.Capacity = source.Length; + return result; + } } // ReSharper disable once ClassNeverInstantiated.Local @@ -50,6 +61,7 @@ class ListLayout [MethodImpl(MethodImplOptions.AggressiveInlining)] static TSource[] GetItems(this List source) - => Unsafe.As, ListLayout>(ref source).items ?? Array.Empty(); + => Unsafe.As, ListLayout>(ref source).items + ?? Array.Empty(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs index 797924e6e..2d5c55a15 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs @@ -12,38 +12,22 @@ public static partial class ArrayExtensions [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source) - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArray().AsList() - }; + => source.ToArray().AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArray(predicate).AsList() - }; + => source.ToArray(predicate).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArrayAt(predicate).AsList() - }; + => source.ToArrayAt(predicate).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArray(selector).AsList() - }; + => source.ToArray(selector).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) @@ -51,29 +35,17 @@ static List ToListVector( where TSelector : struct, IFunction where TSource : struct where TResult : struct - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArrayVector(vectorSelector, selector).AsList() - }; + => source.ToArrayVector(vectorSelector, selector).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArrayAt(selector).AsList() - }; + => source.ToArrayAt(selector).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => source switch - { - { Length: 0 } => new List(), - _ => source.ToArray(predicate, selector).AsList() - }; + => source.ToArray(predicate, selector).AsList(); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs index ee436a8be..90f843bc8 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs @@ -28,22 +28,14 @@ static List ToList(this where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction - => source switch - { - {Count: 0} => new List(), - _ => ToArray(source, predicate).AsList() - }; + => ToArray(source, predicate).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction - => source switch - { - {Count: 0} => new List(), - _ => ToArrayAt(source, predicate).AsList() - }; + => ToArrayAt(source, predicate).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, @@ -51,22 +43,14 @@ static List ToList where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => source switch - { - {Count: 0} => new List(), - _ => ToArray(source, selector).AsList() - }; + => ToArray(source, selector).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => source switch - { - {Count: 0} => new List(), - _ => ToArrayAt(source, selector).AsList() - }; + => ToArrayAt(source, selector).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate, TSelector selector) @@ -74,10 +58,6 @@ static List ToList where TPredicate : struct, IFunction where TSelector : struct, IFunction - => source switch - { - {Count: 0} => new List(), - _ => ToArray(source, predicate, selector).AsList() - }; + => ToArray(source, predicate, selector).AsList(); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs index a0a9d6de6..e907e8233 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs @@ -16,55 +16,35 @@ internal static List ToList(this TList source) [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TList source, int offset, int count) where TList : struct, IReadOnlyList - => source switch - { - { Count: 0 } => new List(), - _ => source.ToArray(offset, count).AsList() - }; + => source.ToArray(offset, count).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TList source, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction - => source switch - { - { Count: 0 } => new List(), - _ => source.ToArray(predicate, offset, count).AsList() - }; + => source.ToArray(predicate, offset, count).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TList source, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction - => source switch - { - { Count: 0 } => new List(), - _ => source.ToArrayAt(predicate, offset, count).AsList() - }; + => source.ToArrayAt(predicate, offset, count).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TList source, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction - => source switch - { - { Count: 0 } => new List(), - _ => source.ToArray(selector, offset, count).AsList() - }; + => source.ToArray(selector, offset, count).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TList source, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction - => source switch - { - { Count: 0 } => new List(), - _ => source.ToArrayAt(selector, offset, count).AsList() - }; + => source.ToArrayAt(selector, offset, count).AsList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -72,10 +52,6 @@ static List ToList(this where TList : struct, IReadOnlyList where TPredicate : struct, IFunction where TSelector : struct, IFunction - => source switch - { - { Count: 0 } => new List(), - _ => source.ToArray(predicate, selector, offset, count).AsList() - }; + => source.ToArray(predicate, selector, offset, count).AsList(); } } diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs index 9f7ccb9ab..53c5a247b 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs @@ -29,7 +29,19 @@ static bool Contains(this TList source, TSource value, IEquality } return ComparerContains(source, value, comparer, offset, count); - + + static bool DefaultContains(TList source, TSource value, int offset, int count) + { + var end = offset + count; + for (var index = offset; index < end; index++) + { + var item = source[index]; + if (EqualityComparer.Default.Equals(item, value)) + return true; + } + return false; + } + static bool ComparerContains(TList source, TSource value, IEqualityComparer? comparer, int offset, int count) { comparer ??= EqualityComparer.Default; @@ -44,19 +56,6 @@ static bool ComparerContains(TList source, TSource value, IEqualityComparer(this TList source, TSource value, int offset, int count) - where TList : struct, IReadOnlyList - { - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (EqualityComparer.Default.Equals(item, value)) - return true; - } - return false; - } - static bool Contains(this TList source, TResult value, IEqualityComparer? comparer, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction From 2e637e0bac46502921110b74d624d29c46e84806 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Thu, 18 Mar 2021 22:32:25 +0000 Subject: [PATCH 26/61] Fix conversion and Sum for ReadOnlyList --- .../AsValueEnumerable.ReadOnlyList.cs | 44 +++++++++---------- .../AsValueEnumerable.ValueReadOnlyList.cs | 4 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs index 03040e2fc..0f035d344 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs @@ -194,8 +194,8 @@ public readonly void Dispose() { } ValueEnumerable AsValueEnumerable() => this; - TList AsEnumerable() - => source; + ValueEnumerable AsEnumerable() + => this; #endregion #region Partitioning @@ -221,52 +221,52 @@ public static int Count(this in ValueEnumerable [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, int, int>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, int?, int>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, long, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, long?, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, float, int>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, float?, float>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, double, double>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, double?, double>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, decimal, decimal>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); + where TList : IReadOnlyList + => source.Sum, decimal?, decimal>(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs index 21529c0a8..b866f7e33 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs @@ -179,8 +179,8 @@ public readonly void Dispose() { } ValueEnumerable AsValueEnumerable() => this; - TList AsEnumerable() - => source; + ValueEnumerable AsEnumerable() + => this; #endregion #region Partitioning From 7c971368b925cb9c4e687bf94c8314c4178d4410 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Fri, 19 Mar 2021 08:58:49 +0000 Subject: [PATCH 27/61] Update benchmark results --- Benchmarks/AllBenchmarks.md | 58 ++++++------- Benchmarks/AnyBenchmarks.md | 38 ++++---- Benchmarks/AnyPredicateBenchmarks.md | 58 ++++++------- Benchmarks/ArrayIterationBenchmarks.md | 22 ++--- Benchmarks/ContainsBenchmarks.md | 40 ++++----- Benchmarks/ContainsComparerBenchmarks.md | 58 ++++++------- Benchmarks/CountBenchmarks.md | 72 ++++++++-------- Benchmarks/DistinctBenchmarks.md | 56 ++++++------ Benchmarks/ElementAtBenchmarks.md | 58 ++++++------- Benchmarks/EmptyBenchmarks.md | 8 +- Benchmarks/FirstBenchmarks.md | 38 ++++---- Benchmarks/RangeBenchmarks.md | 12 +-- Benchmarks/RangeToArrayBenchmarks.md | 14 +-- Benchmarks/RepeatBenchmarks.md | 12 +-- Benchmarks/RepeatToArrayBenchmarks.md | 22 ++--- Benchmarks/ReturnBenchmarks.md | 10 +-- Benchmarks/SelectBenchmarks.md | 66 +++++++------- Benchmarks/SelectCountBenchmarks.md | 62 ++++++------- Benchmarks/SelectManyBenchmarks.md | 46 +++++----- Benchmarks/SelectSumBenchmarks.md | 84 +++++++++--------- Benchmarks/SelectToArrayBenchmarks.md | 66 +++++++------- Benchmarks/SelectToListBenchmarks.md | 82 +++++++++--------- Benchmarks/SingleBenchmarks.md | 34 ++++---- Benchmarks/SkipTakeBenchmarks.md | 76 ++++++++-------- Benchmarks/SumBenchmarks.md | 84 +++++++++--------- Benchmarks/ToArrayBenchmarks.md | 78 ++++++++--------- Benchmarks/ToListBenchmarks.md | 82 +++++++++--------- Benchmarks/WhereBenchmarks.md | 66 +++++++------- Benchmarks/WhereCountBenchmarks.md | 66 +++++++------- Benchmarks/WhereFirstBenchmarks.md | 58 ++++++------- Benchmarks/WhereSelectBenchmarks.md | 86 +++++++++---------- Benchmarks/WhereSelectCountBenchmarks.md | 48 +++++------ Benchmarks/WhereSingleBenchmarks.md | 77 +++++++---------- Benchmarks/WhereToArrayBenchmarks.md | 62 ++++++------- Benchmarks/WhereToListBenchmarks.md | 82 +++++++++--------- .../Benchmarks/WhereSingleBenchmarks.cs | 30 +++---- 36 files changed, 950 insertions(+), 961 deletions(-) diff --git a/Benchmarks/AllBenchmarks.md b/Benchmarks/AllBenchmarks.md index 98d8f5946..fc67a27eb 100644 --- a/Benchmarks/AllBenchmarks.md +++ b/Benchmarks/AllBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 595.0 ns | 4.34 ns | 4.06 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 192.7 ns | 0.61 ns | 0.51 ns | 0.32 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 749.5 ns | 2.53 ns | 2.37 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 228.9 ns | 2.89 ns | 2.42 ns | 0.31 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 754.4 ns | 7.67 ns | 7.17 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 206.9 ns | 1.72 ns | 1.34 ns | 0.27 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 748.2 ns | 3.10 ns | 2.90 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 611.6 ns | 2.82 ns | 2.50 ns | 0.82 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,871.6 ns | 3.28 ns | 3.07 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 274.0 ns | 0.63 ns | 0.59 ns | 0.15 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 731.6 ns | 9.35 ns | 8.75 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 777.0 ns | 3.04 ns | 2.54 ns | 1.06 | 0.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 723.4 ns | 2.88 ns | 2.55 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 757.4 ns | 4.79 ns | 4.48 ns | 1.05 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 726.2 ns | 4.17 ns | 3.69 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 610.9 ns | 1.23 ns | 1.15 ns | 0.84 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,866.5 ns | 4.85 ns | 3.79 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 302.5 ns | 1.93 ns | 1.80 ns | 0.16 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 592.0 ns | 2.18 ns | 1.82 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 193.8 ns | 1.53 ns | 1.28 ns | 0.33 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 757.1 ns | 9.53 ns | 8.92 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 228.8 ns | 1.41 ns | 1.25 ns | 0.30 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 750.8 ns | 2.92 ns | 2.74 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 206.9 ns | 1.60 ns | 1.34 ns | 0.28 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 729.5 ns | 6.13 ns | 5.12 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 614.8 ns | 6.33 ns | 5.92 ns | 0.84 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,847.2 ns | 9.89 ns | 8.77 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 273.3 ns | 1.04 ns | 0.92 ns | 0.15 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 726.7 ns | 3.21 ns | 3.00 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 780.2 ns | 6.27 ns | 5.23 ns | 1.07 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 754.7 ns | 7.32 ns | 6.11 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 757.3 ns | 3.90 ns | 3.65 ns | 1.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 724.9 ns | 4.12 ns | 3.85 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 611.9 ns | 2.85 ns | 2.66 ns | 0.84 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,846.2 ns | 6.31 ns | 5.90 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 301.6 ns | 2.90 ns | 2.27 ns | 0.16 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyBenchmarks.md b/Benchmarks/AnyBenchmarks.md index 49998d4bf..dd768d084 100644 --- a/Benchmarks/AnyBenchmarks.md +++ b/Benchmarks/AnyBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 8.852 ns | 0.0332 ns | 0.0310 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 7.780 ns | 0.0216 ns | 0.0181 ns | 0.88 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 8.874 ns | 0.0473 ns | 0.0442 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 8.295 ns | 0.0321 ns | 0.0300 ns | 0.93 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 22.005 ns | 0.1641 ns | 0.1371 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 12.334 ns | 0.0213 ns | 0.0189 ns | 0.56 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 21.884 ns | 0.1573 ns | 0.1314 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 11.296 ns | 0.0425 ns | 0.0332 ns | 0.52 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 5.165 ns | 0.0671 ns | 0.0628 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.206 ns | 0.0258 ns | 0.0229 ns | 1.59 | 0.02 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 5.370 ns | 0.1195 ns | 0.1118 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.238 ns | 0.0508 ns | 0.0476 ns | 1.53 | 0.03 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.672 ns | 0.0396 ns | 0.0331 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.553 ns | 0.0118 ns | 0.0111 ns | 0.27 | 0.00 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 5.860 ns | 0.0582 ns | 0.0544 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.569 ns | 0.0238 ns | 0.0199 ns | 0.27 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 62.236 ns | 0.3114 ns | 0.2760 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 52.144 ns | 0.1382 ns | 0.1293 ns | 0.84 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 62.273 ns | 0.4126 ns | 0.3222 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 52.364 ns | 0.1373 ns | 0.1146 ns | 0.84 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 21.951 ns | 0.1458 ns | 0.1364 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 13.268 ns | 0.0782 ns | 0.0653 ns | 0.60 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 22.123 ns | 0.3594 ns | 0.3361 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 13.315 ns | 0.0734 ns | 0.0650 ns | 0.60 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 5.295 ns | 0.0266 ns | 0.0249 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.553 ns | 0.0143 ns | 0.0126 ns | 0.29 | 0.00 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 5.171 ns | 0.0717 ns | 0.0635 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.568 ns | 0.0145 ns | 0.0135 ns | 0.30 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.814 ns | 0.0171 ns | 0.0152 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.561 ns | 0.0118 ns | 0.0111 ns | 0.27 | 0.00 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 5.851 ns | 0.0434 ns | 0.0406 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.552 ns | 0.0120 ns | 0.0100 ns | 0.26 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 62.757 ns | 0.1622 ns | 0.1438 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 58.159 ns | 0.1437 ns | 0.1274 ns | 0.93 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 61.675 ns | 0.2805 ns | 0.2624 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 58.200 ns | 0.1898 ns | 0.1585 ns | 0.94 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyPredicateBenchmarks.md b/Benchmarks/AnyPredicateBenchmarks.md index fcf2606bf..01afe1f1e 100644 --- a/Benchmarks/AnyPredicateBenchmarks.md +++ b/Benchmarks/AnyPredicateBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 592.95 ns | 5.427 ns | 4.237 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 192.42 ns | 0.470 ns | 0.393 ns | 0.32 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 749.49 ns | 2.649 ns | 2.348 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 227.31 ns | 1.033 ns | 0.967 ns | 0.30 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 747.52 ns | 2.473 ns | 2.313 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 208.27 ns | 1.093 ns | 1.022 ns | 0.28 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 748.40 ns | 3.902 ns | 3.258 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 611.28 ns | 2.587 ns | 2.293 ns | 0.82 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,865.51 ns | 3.796 ns | 3.365 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 78.57 ns | 0.165 ns | 0.147 ns | 0.04 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 724.87 ns | 3.528 ns | 3.300 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 769.92 ns | 4.524 ns | 3.532 ns | 1.06 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 723.28 ns | 2.886 ns | 2.410 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 729.40 ns | 7.278 ns | 5.682 ns | 1.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 747.92 ns | 2.545 ns | 2.380 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 618.86 ns | 2.077 ns | 1.943 ns | 0.83 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,849.37 ns | 20.568 ns | 17.175 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 79.77 ns | 0.256 ns | 0.227 ns | 0.04 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 591.00 ns | 1.814 ns | 1.608 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 192.91 ns | 1.138 ns | 1.065 ns | 0.33 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 751.43 ns | 3.851 ns | 6.844 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 227.78 ns | 1.197 ns | 1.120 ns | 0.30 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 751.53 ns | 3.422 ns | 3.201 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 207.85 ns | 1.383 ns | 1.155 ns | 0.28 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 749.40 ns | 4.345 ns | 3.628 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 612.27 ns | 2.321 ns | 2.057 ns | 0.82 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,869.98 ns | 7.385 ns | 6.908 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 77.90 ns | 0.339 ns | 0.283 ns | 0.04 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 725.02 ns | 2.412 ns | 2.256 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 784.85 ns | 2.119 ns | 1.878 ns | 1.08 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 751.31 ns | 2.980 ns | 2.327 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 739.72 ns | 3.044 ns | 2.542 ns | 0.98 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 750.60 ns | 5.104 ns | 4.775 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 618.04 ns | 1.425 ns | 1.264 ns | 0.82 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,845.41 ns | 8.015 ns | 7.497 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 81.29 ns | 0.305 ns | 0.270 ns | 0.04 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 12254b820..a4488722b 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -18,20 +18,20 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-PWBPZS : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |----------------------------- |--------- |----------:|----------:|----------:|------:|--------:|------:|------:|------:|----------:| -| Foreach | 10000000 | 4.957 ms | 0.0964 ms | 0.0947 ms | 1.00 | 0.00 | - | - | - | 18 B | -| For | 10000000 | 5.003 ms | 0.0330 ms | 0.0258 ms | 1.01 | 0.02 | - | - | - | 17 B | -| For_Unsafe | 10000000 | 4.963 ms | 0.0788 ms | 0.0844 ms | 1.00 | 0.02 | - | - | - | 17 B | -| ForAdamczewski | 10000000 | 4.724 ms | 0.0932 ms | 0.0779 ms | 0.96 | 0.03 | - | - | - | 17 B | -| ForAdamczewskiUnsafe | 10000000 | 4.225 ms | 0.0555 ms | 0.0492 ms | 0.85 | 0.01 | - | - | - | 17 B | -| Span | 10000000 | 4.892 ms | 0.0367 ms | 0.0325 ms | 0.99 | 0.02 | - | - | - | 17 B | -| Memory | 10000000 | 4.910 ms | 0.0249 ms | 0.0221 ms | 0.99 | 0.02 | - | - | - | 17 B | -| ArraySegment_Foreach | 10000000 | 29.163 ms | 0.0954 ms | 0.0892 ms | 5.89 | 0.11 | - | - | - | 68 B | -| ArraySegment_For | 10000000 | 8.499 ms | 0.0435 ms | 0.0364 ms | 1.72 | 0.03 | - | - | - | 34 B | -| ArraySegment_Wrapper_Foreach | 10000000 | 15.324 ms | 0.0627 ms | 0.0587 ms | 3.10 | 0.06 | - | - | - | 34 B | +| Foreach | 10000000 | 5.083 ms | 0.0922 ms | 0.1133 ms | 1.00 | 0.00 | - | - | - | 1 B | +| For | 10000000 | 5.022 ms | 0.0300 ms | 0.0266 ms | 0.98 | 0.02 | - | - | - | 2 B | +| For_Unsafe | 10000000 | 5.226 ms | 0.0301 ms | 0.0267 ms | 1.02 | 0.02 | - | - | - | 2 B | +| ForAdamczewski | 10000000 | 4.805 ms | 0.0371 ms | 0.0310 ms | 0.94 | 0.02 | - | - | - | 2 B | +| ForAdamczewskiUnsafe | 10000000 | 4.343 ms | 0.0677 ms | 0.0633 ms | 0.85 | 0.03 | - | - | - | 1 B | +| Span | 10000000 | 5.173 ms | 0.1025 ms | 0.1220 ms | 1.02 | 0.04 | - | - | - | 1 B | +| Memory | 10000000 | 5.072 ms | 0.0736 ms | 0.0723 ms | 0.99 | 0.02 | - | - | - | 1 B | +| ArraySegment_Foreach | 10000000 | 28.831 ms | 0.1434 ms | 0.1271 ms | 5.63 | 0.14 | - | - | - | 6 B | +| ArraySegment_For | 10000000 | 8.883 ms | 0.0334 ms | 0.0296 ms | 1.73 | 0.04 | - | - | - | 2 B | +| ArraySegment_Wrapper_Foreach | 10000000 | 15.390 ms | 0.0593 ms | 0.0496 ms | 3.00 | 0.08 | - | - | - | 3 B | diff --git a/Benchmarks/ContainsBenchmarks.md b/Benchmarks/ContainsBenchmarks.md index 75499114d..1747f8d66 100644 --- a/Benchmarks/ContainsBenchmarks.md +++ b/Benchmarks/ContainsBenchmarks.md @@ -18,37 +18,37 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 40.78 ns | 0.166 ns | 0.139 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 30.19 ns | 0.114 ns | 0.095 ns | 0.74 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 26.73 ns | 0.065 ns | 0.058 ns | 0.66 | - | - | - | - | +| Linq_Array | Array | 100 | 40.65 ns | 0.211 ns | 0.176 ns | 1.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 30.31 ns | 0.198 ns | 0.176 ns | 0.75 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 25.58 ns | 0.120 ns | 0.106 ns | 0.63 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 656.05 ns | 1.734 ns | 1.448 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 293.93 ns | 1.028 ns | 0.802 ns | 0.45 | 0.0191 | - | - | 40 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 656.14 ns | 1.460 ns | 1.366 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 295.03 ns | 1.379 ns | 1.290 ns | 0.45 | 0.0191 | - | - | 40 B | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 36.22 ns | 0.124 ns | 0.103 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 39.83 ns | 0.251 ns | 0.234 ns | 1.10 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 36.24 ns | 0.165 ns | 0.146 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 39.45 ns | 0.147 ns | 0.131 ns | 1.09 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 37.12 ns | 0.166 ns | 0.147 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 39.95 ns | 0.189 ns | 0.168 ns | 1.08 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 36.89 ns | 0.126 ns | 0.112 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 40.04 ns | 0.165 ns | 0.155 ns | 1.08 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,793.21 ns | 3.049 ns | 2.852 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,143.36 ns | 1.975 ns | 1.649 ns | 0.64 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,818.57 ns | 3.937 ns | 3.288 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,118.84 ns | 2.749 ns | 2.295 ns | 0.62 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 658.41 ns | 3.378 ns | 2.994 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 656.36 ns | 1.728 ns | 1.443 ns | 1.00 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 658.64 ns | 5.196 ns | 4.057 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 660.32 ns | 3.563 ns | 3.158 ns | 1.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 36.17 ns | 0.155 ns | 0.137 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 39.18 ns | 0.135 ns | 0.112 ns | 1.08 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 35.92 ns | 0.107 ns | 0.095 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 39.33 ns | 0.105 ns | 0.088 ns | 1.10 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 37.15 ns | 0.166 ns | 0.147 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 40.14 ns | 0.224 ns | 0.199 ns | 1.08 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 37.08 ns | 0.130 ns | 0.122 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 39.94 ns | 0.186 ns | 0.165 ns | 1.08 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,820.96 ns | 7.193 ns | 6.006 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,885.59 ns | 4.615 ns | 4.317 ns | 1.04 | 0.0267 | - | - | 56 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,821.71 ns | 4.026 ns | 3.569 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,889.72 ns | 6.468 ns | 6.050 ns | 1.04 | 0.0267 | - | - | 56 B | diff --git a/Benchmarks/ContainsComparerBenchmarks.md b/Benchmarks/ContainsComparerBenchmarks.md index 0cacb4984..30db67ce5 100644 --- a/Benchmarks/ContainsComparerBenchmarks.md +++ b/Benchmarks/ContainsComparerBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 575.9 ns | 2.52 ns | 2.10 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 199.6 ns | 0.87 ns | 0.77 ns | 0.35 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 792.1 ns | 3.07 ns | 2.72 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 332.2 ns | 1.20 ns | 1.13 ns | 0.42 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 789.7 ns | 2.80 ns | 2.62 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 333.3 ns | 0.77 ns | 0.68 ns | 0.42 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 759.8 ns | 1.27 ns | 1.06 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 649.4 ns | 3.74 ns | 3.32 ns | 0.85 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,895.1 ns | 4.91 ns | 4.10 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,105.4 ns | 3.08 ns | 2.58 ns | 0.58 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 790.5 ns | 2.44 ns | 2.04 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 766.6 ns | 4.24 ns | 3.76 ns | 0.97 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 761.0 ns | 3.49 ns | 2.91 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 818.4 ns | 3.95 ns | 3.09 ns | 1.08 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 792.3 ns | 2.21 ns | 1.96 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 678.2 ns | 2.09 ns | 1.86 ns | 0.86 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,891.4 ns | 2.30 ns | 2.04 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,870.7 ns | 4.38 ns | 3.89 ns | 0.99 | 0.0267 | - | - | 56 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 578.2 ns | 3.96 ns | 3.51 ns | 577.6 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 202.2 ns | 4.07 ns | 3.61 ns | 200.9 ns | 0.35 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 791.8 ns | 4.20 ns | 3.72 ns | 790.5 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 331.3 ns | 1.38 ns | 1.22 ns | 331.7 ns | 0.42 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 762.0 ns | 2.87 ns | 2.69 ns | 761.8 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 334.3 ns | 1.35 ns | 1.20 ns | 333.9 ns | 0.44 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 792.8 ns | 7.00 ns | 6.20 ns | 790.8 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 651.0 ns | 2.01 ns | 1.88 ns | 651.6 ns | 0.82 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,881.0 ns | 24.51 ns | 42.93 ns | 1,865.7 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,130.2 ns | 6.01 ns | 4.69 ns | 1,129.5 ns | 0.59 | 0.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 799.4 ns | 13.46 ns | 23.58 ns | 790.3 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 796.2 ns | 15.83 ns | 15.55 ns | 789.4 ns | 0.99 | 0.05 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 763.8 ns | 3.89 ns | 3.45 ns | 763.3 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 839.9 ns | 16.22 ns | 21.66 ns | 827.3 ns | 1.10 | 0.03 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 760.8 ns | 2.52 ns | 2.23 ns | 760.6 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 679.7 ns | 5.17 ns | 4.58 ns | 679.4 ns | 0.89 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,866.1 ns | 3.78 ns | 3.35 ns | 1,866.0 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,870.3 ns | 3.93 ns | 3.48 ns | 1,871.0 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | diff --git a/Benchmarks/CountBenchmarks.md b/Benchmarks/CountBenchmarks.md index 5bd360155..5250c04b2 100644 --- a/Benchmarks/CountBenchmarks.md +++ b/Benchmarks/CountBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |--------------:|-----------:|----------:|-------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 11.2255 ns | 0.0273 ns | 0.0228 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Array | Array | 100 | 0.9603 ns | 0.0093 ns | 0.0087 ns | 0.09 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 7.9730 ns | 0.0152 ns | 0.0127 ns | 0.71 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 355.4883 ns | 1.6482 ns | 1.4611 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 603.7159 ns | 2.1824 ns | 1.9346 ns | 1.70 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 158.3521 ns | 0.2623 ns | 0.2454 ns | 0.45 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.6527 ns | 0.0269 ns | 0.0251 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Value | Collection_Value | 100 | 605.6038 ns | 3.7534 ns | 3.5109 ns | 130.17 | 1.10 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.7639 ns | 0.0187 ns | 0.0175 ns | 1.67 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.4788 ns | 0.0126 ns | 0.0098 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Value | List_Value | 100 | 2.0882 ns | 0.0132 ns | 0.0110 ns | 0.38 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.6687 ns | 0.0630 ns | 0.0647 ns | 0.30 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,821.3896 ns | 3.9189 ns | 3.4740 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 939.0860 ns | 3.5278 ns | 3.2999 ns | 0.52 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 348.7667 ns | 1.4129 ns | 1.2525 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 603.3495 ns | 2.1976 ns | 1.9481 ns | 1.73 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 365.2241 ns | 1.1188 ns | 0.9918 ns | 1.05 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.6612 ns | 0.0173 ns | 0.0153 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 606.8740 ns | 2.6887 ns | 2.3835 ns | 130.20 | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.5391 ns | 0.0104 ns | 0.0087 ns | 0.33 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.5106 ns | 0.0544 ns | 0.0482 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Reference | List_Reference | 100 | 610.2956 ns | 12.0029 ns | 9.3710 ns | 110.85 | 2.17 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.6216 ns | 0.0127 ns | 0.0119 ns | 0.29 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,819.4181 ns | 4.6820 ns | 4.1505 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,589.0589 ns | 4.1811 ns | 3.4914 ns | 0.87 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |--------------:|----------:|----------:|--------------:|-------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 10.3993 ns | 0.0441 ns | 0.0368 ns | 10.3876 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Array | Array | 100 | 0.9824 ns | 0.0801 ns | 0.2324 ns | 0.8387 ns | 0.10 | 0.01 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.7113 ns | 0.0235 ns | 0.0220 ns | 7.7153 ns | 0.74 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 356.9077 ns | 1.8740 ns | 1.6612 ns | 356.6942 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 576.8413 ns | 2.4870 ns | 2.2046 ns | 576.5287 ns | 1.62 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 142.7680 ns | 0.3979 ns | 0.3722 ns | 142.7317 ns | 0.40 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 4.6516 ns | 0.0187 ns | 0.0156 ns | 4.6471 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Value | Collection_Value | 100 | 602.4877 ns | 3.4145 ns | 3.1939 ns | 602.2316 ns | 129.35 | 0.83 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.5152 ns | 0.0144 ns | 0.0134 ns | 7.5154 ns | 1.62 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 5.5309 ns | 0.0427 ns | 0.0378 ns | 5.5097 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Value | List_Value | 100 | 2.1173 ns | 0.0114 ns | 0.0095 ns | 2.1155 ns | 0.38 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.5830 ns | 0.0067 ns | 0.0056 ns | 1.5826 ns | 0.29 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,798.5748 ns | 4.3133 ns | 3.8236 ns | 1,798.4897 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 937.4144 ns | 2.1488 ns | 2.0100 ns | 937.4766 ns | 0.52 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 348.9051 ns | 1.3518 ns | 1.1288 ns | 349.2017 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 604.3288 ns | 1.6966 ns | 1.3246 ns | 604.4109 ns | 1.73 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 365.9486 ns | 2.2888 ns | 2.0290 ns | 365.5504 ns | 1.05 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.6149 ns | 0.0363 ns | 0.0322 ns | 4.6059 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 576.8288 ns | 1.9345 ns | 1.7149 ns | 576.9421 ns | 125.00 | 0.98 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.5439 ns | 0.0139 ns | 0.0116 ns | 1.5435 ns | 0.33 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 5.4194 ns | 0.0493 ns | 0.0385 ns | 5.4114 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Reference | List_Reference | 100 | 576.9825 ns | 3.0149 ns | 2.6726 ns | 576.4323 ns | 106.53 | 0.70 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.6144 ns | 0.0079 ns | 0.0066 ns | 1.6134 ns | 0.30 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,793.2356 ns | 5.6385 ns | 5.2742 ns | 1,790.5483 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,562.0711 ns | 5.7935 ns | 5.1358 ns | 1,561.1134 ns | 0.87 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/DistinctBenchmarks.md b/Benchmarks/DistinctBenchmarks.md index be5d4fd87..d6d6c71b1 100644 --- a/Benchmarks/DistinctBenchmarks.md +++ b/Benchmarks/DistinctBenchmarks.md @@ -18,45 +18,45 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |---------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 2.917 μs | 0.0135 μs | 0.0119 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Array | Array | 100 | 1.325 μs | 0.0056 μs | 0.0049 μs | 0.45 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 1.494 μs | 0.0095 μs | 0.0084 μs | 0.51 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 1.520 μs | 0.0054 μs | 0.0048 μs | 0.52 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.602 μs | 0.0040 μs | 0.0031 μs | 0.55 | - | - | - | - | +| Linq_Array | Array | 100 | 2.886 μs | 0.0206 μs | 0.0193 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Array | Array | 100 | 1.329 μs | 0.0132 μs | 0.0123 μs | 0.46 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 1.515 μs | 0.0091 μs | 0.0085 μs | 0.52 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 1.513 μs | 0.0080 μs | 0.0071 μs | 0.52 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.638 μs | 0.0081 μs | 0.0067 μs | 0.57 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.196 μs | 0.0194 μs | 0.0172 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.227 μs | 0.0177 μs | 0.0148 μs | 0.70 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.513 μs | 0.0045 μs | 0.0040 μs | 0.47 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.192 μs | 0.0208 μs | 0.0184 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.264 μs | 0.0147 μs | 0.0138 μs | 0.71 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.513 μs | 0.0082 μs | 0.0077 μs | 0.47 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 3.208 μs | 0.0151 μs | 0.0134 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 2.222 μs | 0.0092 μs | 0.0077 μs | 0.69 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.591 μs | 0.0111 μs | 0.0103 μs | 0.50 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 3.177 μs | 0.0116 μs | 0.0109 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 2.255 μs | 0.0174 μs | 0.0154 μs | 0.71 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.611 μs | 0.0198 μs | 0.0175 μs | 0.51 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 3.196 μs | 0.0131 μs | 0.0109 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_List_Value | List_Value | 100 | 1.486 μs | 0.0061 μs | 0.0051 μs | 0.47 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.939 μs | 0.0130 μs | 0.0115 μs | 0.61 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 3.194 μs | 0.0141 μs | 0.0125 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_List_Value | List_Value | 100 | 1.479 μs | 0.0083 μs | 0.0073 μs | 0.46 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 2.150 μs | 0.0131 μs | 0.0102 μs | 0.67 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.568 μs | 0.0196 μs | 0.0164 μs | 1.00 | 2.0599 | - | - | 4,320 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.515 μs | 0.0255 μs | 0.0239 μs | 0.60 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.507 μs | 0.0173 μs | 0.0153 μs | 1.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.560 μs | 0.0202 μs | 0.0169 μs | 0.61 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 3.206 μs | 0.0117 μs | 0.0109 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.211 μs | 0.0129 μs | 0.0114 μs | 0.69 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.678 μs | 0.0103 μs | 0.0091 μs | 0.84 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 3.193 μs | 0.0142 μs | 0.0119 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.267 μs | 0.0097 μs | 0.0086 μs | 0.71 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.695 μs | 0.0076 μs | 0.0063 μs | 0.84 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 3.206 μs | 0.0098 μs | 0.0087 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 2.264 μs | 0.0071 μs | 0.0063 μs | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.747 μs | 0.0141 μs | 0.0125 μs | 0.86 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 3.201 μs | 0.0086 μs | 0.0076 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 2.272 μs | 0.0070 μs | 0.0058 μs | 0.71 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.684 μs | 0.0058 μs | 0.0055 μs | 0.84 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 3.197 μs | 0.0147 μs | 0.0131 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_List_Reference | List_Reference | 100 | 2.259 μs | 0.0107 μs | 0.0100 μs | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.946 μs | 0.0174 μs | 0.0154 μs | 0.61 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 3.231 μs | 0.0276 μs | 0.0230 μs | 1.00 | 2.0599 | - | - | 4,312 B | +| StructLinq_List_Reference | List_Reference | 100 | 2.264 μs | 0.0130 μs | 0.0115 μs | 0.70 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.961 μs | 0.0073 μs | 0.0064 μs | 0.61 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.581 μs | 0.0228 μs | 0.0202 μs | 1.00 | 2.0599 | - | - | 4,320 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5.285 μs | 0.0824 μs | 0.0731 μs | 0.70 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.527 μs | 0.0221 μs | 0.0196 μs | 1.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5.132 μs | 0.0460 μs | 0.0408 μs | 0.68 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ElementAtBenchmarks.md b/Benchmarks/ElementAtBenchmarks.md index 7471d3f4f..e97ffe3dd 100644 --- a/Benchmarks/ElementAtBenchmarks.md +++ b/Benchmarks/ElementAtBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 16.827 ns | 0.0864 ns | 0.0809 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 13.462 ns | 0.0422 ns | 0.0374 ns | 0.80 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 344.429 ns | 1.3959 ns | 1.2375 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 144.601 ns | 0.3814 ns | 0.3381 ns | 0.42 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 344.272 ns | 0.8262 ns | 0.7324 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 149.374 ns | 0.2419 ns | 0.2144 ns | 0.43 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 10.101 ns | 0.1818 ns | 0.1611 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 14.733 ns | 0.1009 ns | 0.0843 ns | 1.46 | 0.02 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,794.986 ns | 5.2256 ns | 4.8880 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 966.367 ns | 3.3670 ns | 2.8116 ns | 0.54 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 342.764 ns | 1.0983 ns | 0.8575 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 366.209 ns | 2.0936 ns | 1.8559 ns | 1.07 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 345.252 ns | 0.9672 ns | 0.8574 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 368.954 ns | 1.2762 ns | 1.0657 ns | 1.07 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 9.997 ns | 0.1035 ns | 0.1151 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 14.667 ns | 0.0498 ns | 0.0416 ns | 1.47 | 0.02 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,791.748 ns | 3.0825 ns | 2.7325 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,609.644 ns | 3.2502 ns | 2.8812 ns | 0.90 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-------------:|----------:|----------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 18.585 ns | 0.0733 ns | 0.0650 ns | 1.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 12.935 ns | 0.0287 ns | 0.0268 ns | 0.70 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 343.258 ns | 1.3405 ns | 1.1194 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 144.574 ns | 0.3296 ns | 0.2752 ns | 0.42 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 344.587 ns | 1.0413 ns | 0.8130 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 149.877 ns | 0.4437 ns | 0.3933 ns | 0.44 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 9.966 ns | 0.0418 ns | 0.0391 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 14.887 ns | 0.0451 ns | 0.0422 ns | 1.49 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,794.411 ns | 6.5545 ns | 5.4733 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 969.878 ns | 4.0156 ns | 3.7562 ns | 0.54 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 344.638 ns | 1.2438 ns | 1.1026 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 341.807 ns | 1.5447 ns | 1.3694 ns | 0.99 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 344.314 ns | 0.9447 ns | 0.8375 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 370.607 ns | 1.3467 ns | 1.1245 ns | 1.08 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 10.000 ns | 0.0869 ns | 0.0770 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 14.735 ns | 0.0550 ns | 0.0487 ns | 1.47 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,793.513 ns | 5.0783 ns | 4.5017 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,604.776 ns | 3.7408 ns | 3.1238 ns | 0.89 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/EmptyBenchmarks.md b/Benchmarks/EmptyBenchmarks.md index 9e7466e56..5e63a9d01 100644 --- a/Benchmarks/EmptyBenchmarks.md +++ b/Benchmarks/EmptyBenchmarks.md @@ -18,15 +18,15 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------------- |------------ |-----------:|----------:|----------:|------:|------:|------:|------:|----------:| -| Linq_Empty | Empty | 6.4623 ns | 0.0269 ns | 0.0239 ns | 1.000 | - | - | - | - | +| Linq_Empty | Empty | 6.3669 ns | 0.0298 ns | 0.0278 ns | 1.000 | - | - | - | - | | Hyperlinq_Empty | Empty | 0.0000 ns | 0.0000 ns | 0.0000 ns | 0.000 | - | - | - | - | | | | | | | | | | | | -| Linq_Empty_Async | Empty_Async | 40.5485 ns | 0.1036 ns | 0.0865 ns | 1.00 | - | - | - | - | -| Hyperlinq_Empty_Async | Empty_Async | 20.5118 ns | 0.1285 ns | 0.1139 ns | 0.51 | - | - | - | - | +| Linq_Empty_Async | Empty_Async | 40.5218 ns | 0.0720 ns | 0.0638 ns | 1.00 | - | - | - | - | +| Hyperlinq_Empty_Async | Empty_Async | 20.7372 ns | 0.0697 ns | 0.0618 ns | 0.51 | - | - | - | - | diff --git a/Benchmarks/FirstBenchmarks.md b/Benchmarks/FirstBenchmarks.md index 25924bafb..873b3b16a 100644 --- a/Benchmarks/FirstBenchmarks.md +++ b/Benchmarks/FirstBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 25.26 ns | 0.111 ns | 0.099 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 13.27 ns | 0.041 ns | 0.039 ns | 0.53 | - | - | - | - | +| Linq_Array | Array | 100 | 21.69 ns | 0.108 ns | 0.096 ns | 1.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 13.33 ns | 0.029 ns | 0.024 ns | 0.61 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 25.15 ns | 0.090 ns | 0.070 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.62 ns | 0.043 ns | 0.036 ns | 0.62 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 25.27 ns | 0.083 ns | 0.073 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.62 ns | 0.036 ns | 0.032 ns | 0.62 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 25.78 ns | 0.090 ns | 0.080 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 19.20 ns | 0.078 ns | 0.073 ns | 0.75 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 26.29 ns | 0.138 ns | 0.116 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 19.12 ns | 0.054 ns | 0.051 ns | 0.73 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 13.27 ns | 0.045 ns | 0.035 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 14.94 ns | 0.056 ns | 0.049 ns | 1.13 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 13.38 ns | 0.072 ns | 0.067 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 14.99 ns | 0.089 ns | 0.083 ns | 1.12 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 107.07 ns | 0.239 ns | 0.187 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 64.04 ns | 0.376 ns | 0.314 ns | 0.60 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 104.97 ns | 0.191 ns | 0.169 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 63.66 ns | 0.292 ns | 0.273 ns | 0.61 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 25.56 ns | 0.119 ns | 0.100 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 40.37 ns | 0.294 ns | 0.261 ns | 1.58 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 25.65 ns | 0.151 ns | 0.141 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 17.22 ns | 0.066 ns | 0.062 ns | 0.67 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 25.78 ns | 0.260 ns | 0.203 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 19.42 ns | 0.058 ns | 0.051 ns | 0.75 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 25.67 ns | 0.173 ns | 0.153 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 18.86 ns | 0.073 ns | 0.061 ns | 0.73 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 13.51 ns | 0.225 ns | 0.188 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 14.68 ns | 0.035 ns | 0.031 ns | 1.09 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 13.32 ns | 0.071 ns | 0.059 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 14.66 ns | 0.058 ns | 0.048 ns | 1.10 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 105.10 ns | 0.225 ns | 0.210 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 71.06 ns | 0.539 ns | 0.504 ns | 0.68 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 107.94 ns | 0.590 ns | 0.552 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 71.80 ns | 0.260 ns | 0.230 ns | 0.66 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/RangeBenchmarks.md b/Benchmarks/RangeBenchmarks.md index 8aa7b271f..76b97cec2 100644 --- a/Benchmarks/RangeBenchmarks.md +++ b/Benchmarks/RangeBenchmarks.md @@ -18,16 +18,16 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------ |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 415.68 ns | 1.053 ns | 0.879 ns | 1.00 | 0.0191 | - | - | 40 B | -| StructLinq | Range | 100 | 34.07 ns | 0.128 ns | 0.107 ns | 0.08 | - | - | - | - | -| Hyperlinq | Range | 100 | 48.49 ns | 0.752 ns | 0.703 ns | 0.12 | - | - | - | - | +| Linq | Range | 100 | 416.88 ns | 2.728 ns | 2.130 ns | 1.00 | 0.0191 | - | - | 40 B | +| StructLinq | Range | 100 | 34.04 ns | 0.144 ns | 0.128 ns | 0.08 | - | - | - | - | +| Hyperlinq | Range | 100 | 47.38 ns | 0.148 ns | 0.131 ns | 0.11 | - | - | - | - | | | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 3,916.42 ns | 14.040 ns | 12.446 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Range_Async | 100 | 1,349.05 ns | 15.800 ns | 13.194 ns | 0.34 | 0.0153 | - | - | 32 B | +| Linq_Async | Range_Async | 100 | 3,912.38 ns | 22.969 ns | 21.485 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Range_Async | 100 | 1,320.37 ns | 4.421 ns | 4.136 ns | 0.34 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/RangeToArrayBenchmarks.md b/Benchmarks/RangeToArrayBenchmarks.md index 7fce4e284..e0515d399 100644 --- a/Benchmarks/RangeToArrayBenchmarks.md +++ b/Benchmarks/RangeToArrayBenchmarks.md @@ -18,17 +18,17 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------ |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 82.53 ns | 0.745 ns | 0.660 ns | 1.00 | 0.2218 | - | - | 464 B | -| StructLinq | Range | 100 | 90.06 ns | 0.547 ns | 0.512 ns | 1.09 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Range | 100 | 36.82 ns | 0.510 ns | 0.477 ns | 0.45 | 0.2027 | - | - | 424 B | -| Hyperlinq | Range | 100 | 45.37 ns | 0.255 ns | 0.226 ns | 0.55 | 0.2027 | - | - | 424 B | +| Linq | Range | 100 | 82.74 ns | 0.862 ns | 0.807 ns | 1.00 | 0.2218 | - | - | 464 B | +| StructLinq | Range | 100 | 89.71 ns | 0.455 ns | 0.403 ns | 1.09 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Range | 100 | 36.82 ns | 0.408 ns | 0.382 ns | 0.45 | 0.2027 | - | - | 424 B | +| Hyperlinq | Range | 100 | 45.49 ns | 0.218 ns | 0.170 ns | 0.55 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 107.46 ns | 1.095 ns | 0.971 ns | 1.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Range_Async | 100 | 145.93 ns | 0.688 ns | 0.610 ns | 1.36 | 0.2027 | - | - | 424 B | +| Linq_Async | Range_Async | 100 | 108.02 ns | 0.607 ns | 0.538 ns | 1.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Range_Async | 100 | 146.15 ns | 0.743 ns | 0.620 ns | 1.35 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/RepeatBenchmarks.md b/Benchmarks/RepeatBenchmarks.md index 51a00309f..546acfade 100644 --- a/Benchmarks/RepeatBenchmarks.md +++ b/Benchmarks/RepeatBenchmarks.md @@ -18,16 +18,16 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 392.09 ns | 1.569 ns | 1.225 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq | Repeat | 100 | 34.55 ns | 0.134 ns | 0.119 ns | 0.09 | - | - | - | - | -| Hyperlinq | Repeat | 100 | 167.61 ns | 0.434 ns | 0.406 ns | 0.43 | - | - | - | - | +| Linq | Repeat | 100 | 415.37 ns | 0.629 ns | 0.589 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq | Repeat | 100 | 34.32 ns | 0.159 ns | 0.148 ns | 0.08 | - | - | - | - | +| Hyperlinq | Repeat | 100 | 167.30 ns | 0.277 ns | 0.259 ns | 0.40 | - | - | - | - | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 4,985.76 ns | 17.802 ns | 14.865 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Repeat_Async | 100 | 932.19 ns | 1.904 ns | 1.687 ns | 0.19 | - | - | - | - | +| Linq_Async | Repeat_Async | 100 | 4,969.95 ns | 19.484 ns | 16.270 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Repeat_Async | 100 | 933.46 ns | 1.937 ns | 1.717 ns | 0.19 | - | - | - | - | diff --git a/Benchmarks/RepeatToArrayBenchmarks.md b/Benchmarks/RepeatToArrayBenchmarks.md index 82fd0c0f4..b964ecac5 100644 --- a/Benchmarks/RepeatToArrayBenchmarks.md +++ b/Benchmarks/RepeatToArrayBenchmarks.md @@ -18,18 +18,18 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------- |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 91.48 ns | 0.341 ns | 0.285 ns | 1.00 | 0.2180 | - | - | 456 B | -| StructLinq | Repeat | 100 | 110.52 ns | 0.520 ns | 0.461 ns | 1.21 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Repeat | 100 | 28.03 ns | 0.611 ns | 0.654 ns | 0.31 | 0.2027 | - | - | 424 B | -| Hyperlinq | Repeat | 100 | 55.85 ns | 0.942 ns | 1.122 ns | 0.61 | 0.2027 | - | - | 424 B | -| Hyperlinq_SIMD | Repeat | 100 | 40.77 ns | 0.343 ns | 0.304 ns | 0.45 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 92.87 ns | 0.784 ns | 0.733 ns | 1.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Repeat_Async | 100 | 118.72 ns | 0.475 ns | 0.422 ns | 1.28 | 0.2027 | - | - | 424 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------- |------ |----------:|---------:|---------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq | Repeat | 100 | 92.29 ns | 0.656 ns | 0.582 ns | 92.23 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq | Repeat | 100 | 110.61 ns | 0.756 ns | 0.631 ns | 110.42 ns | 1.20 | 0.01 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Repeat | 100 | 28.17 ns | 0.569 ns | 0.504 ns | 28.10 ns | 0.31 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq | Repeat | 100 | 55.52 ns | 0.252 ns | 0.223 ns | 55.53 ns | 0.60 | 0.00 | 0.2027 | - | - | 424 B | +| Hyperlinq_SIMD | Repeat | 100 | 41.57 ns | 0.774 ns | 1.928 ns | 40.74 ns | 0.48 | 0.03 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Async | Repeat_Async | 100 | 91.33 ns | 0.327 ns | 0.256 ns | 91.29 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Repeat_Async | 100 | 119.23 ns | 0.548 ns | 0.428 ns | 119.24 ns | 1.31 | 0.00 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/ReturnBenchmarks.md b/Benchmarks/ReturnBenchmarks.md index df58a0150..7521fe228 100644 --- a/Benchmarks/ReturnBenchmarks.md +++ b/Benchmarks/ReturnBenchmarks.md @@ -18,15 +18,15 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |----------------------- |------------- |----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Return | Return | 15.616 ns | 0.0868 ns | 0.0812 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_Return | Return | 8.962 ns | 0.0241 ns | 0.0214 ns | 0.57 | - | - | - | - | +| Linq_Return | Return | 15.684 ns | 0.1203 ns | 0.1067 ns | 1.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_Return | Return | 8.965 ns | 0.0158 ns | 0.0140 ns | 0.57 | - | - | - | - | | | | | | | | | | | | -| Linq_Return_Async | Return_Async | 56.312 ns | 0.2665 ns | 0.2080 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Return_Async | Return_Async | 42.660 ns | 0.6350 ns | 0.5940 ns | 0.75 | - | - | - | - | +| Linq_Return_Async | Return_Async | 56.114 ns | 0.1545 ns | 0.1370 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Return_Async | Return_Async | 42.330 ns | 0.0832 ns | 0.0738 ns | 0.75 | - | - | - | - | diff --git a/Benchmarks/SelectBenchmarks.md b/Benchmarks/SelectBenchmarks.md index c02fe1adb..f4d375c51 100644 --- a/Benchmarks/SelectBenchmarks.md +++ b/Benchmarks/SelectBenchmarks.md @@ -18,50 +18,50 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-KXCEYC : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 662.5 ns | 13.09 ns | 12.85 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 234.5 ns | 0.94 ns | 0.84 ns | 0.35 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 225.5 ns | 0.73 ns | 0.61 ns | 0.34 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 209.5 ns | 0.83 ns | 0.78 ns | 0.32 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 198.5 ns | 0.69 ns | 0.64 ns | 0.30 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 208.6 ns | 0.48 ns | 0.45 ns | 0.31 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 353.6 ns | 1.81 ns | 1.69 ns | 0.53 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 237.4 ns | 1.06 ns | 0.99 ns | 0.36 | - | - | - | - | +| Linq_Array | Array | 100 | 634.6 ns | 2.38 ns | 2.11 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 232.2 ns | 0.37 ns | 0.29 ns | 0.37 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 226.5 ns | 3.05 ns | 2.54 ns | 0.36 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 209.0 ns | 0.85 ns | 0.76 ns | 0.33 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 199.0 ns | 0.86 ns | 0.76 ns | 0.31 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 209.5 ns | 0.96 ns | 0.90 ns | 0.33 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 352.7 ns | 1.13 ns | 1.00 ns | 0.56 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 237.4 ns | 1.09 ns | 0.97 ns | 0.37 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,214.8 ns | 5.55 ns | 4.92 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 738.4 ns | 4.03 ns | 3.77 ns | 0.61 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 210.4 ns | 0.54 ns | 0.47 ns | 0.17 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,216.2 ns | 5.09 ns | 4.25 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 739.1 ns | 4.27 ns | 3.57 ns | 0.61 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 211.1 ns | 1.23 ns | 1.09 ns | 0.17 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,165.4 ns | 4.55 ns | 3.80 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 736.0 ns | 3.95 ns | 3.30 ns | 0.63 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 210.7 ns | 0.78 ns | 0.69 ns | 0.18 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,165.7 ns | 6.67 ns | 5.91 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 735.9 ns | 3.02 ns | 2.68 ns | 0.63 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 211.3 ns | 0.64 ns | 0.57 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,169.6 ns | 5.22 ns | 4.63 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 371.5 ns | 1.38 ns | 1.22 ns | 0.32 | - | - | - | - | -| Hyperlinq_List_Value_For | List_Value | 100 | 377.6 ns | 1.43 ns | 1.27 ns | 0.32 | - | - | - | - | -| Hyperlinq_List_Value_Foreach | List_Value | 100 | 391.5 ns | 1.21 ns | 1.07 ns | 0.33 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 1,174.4 ns | 4.15 ns | 3.68 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 374.7 ns | 2.22 ns | 1.97 ns | 0.32 | - | - | - | - | +| Hyperlinq_List_Value_For | List_Value | 100 | 379.3 ns | 1.18 ns | 1.04 ns | 0.32 | - | - | - | - | +| Hyperlinq_List_Value_Foreach | List_Value | 100 | 393.0 ns | 1.47 ns | 1.38 ns | 0.33 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,242.1 ns | 26.11 ns | 21.80 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,225.4 ns | 15.83 ns | 14.03 ns | 0.72 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,148.1 ns | 18.84 ns | 16.70 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,148.5 ns | 16.21 ns | 15.16 ns | 0.72 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,166.3 ns | 8.20 ns | 7.27 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 786.8 ns | 2.88 ns | 2.41 ns | 0.67 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 791.6 ns | 9.23 ns | 8.18 ns | 0.68 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,164.0 ns | 4.45 ns | 3.95 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 790.4 ns | 4.13 ns | 3.66 ns | 0.68 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 780.9 ns | 3.94 ns | 3.49 ns | 0.67 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,196.1 ns | 2.06 ns | 1.61 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 737.8 ns | 2.97 ns | 2.78 ns | 0.62 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 814.8 ns | 2.78 ns | 2.46 ns | 0.68 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,197.2 ns | 4.66 ns | 4.36 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 736.3 ns | 2.27 ns | 2.01 ns | 0.61 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 814.1 ns | 2.98 ns | 2.79 ns | 0.68 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,201.1 ns | 3.43 ns | 2.86 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 735.1 ns | 2.54 ns | 2.12 ns | 0.61 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference_For | List_Reference | 100 | 405.1 ns | 1.33 ns | 1.18 ns | 0.34 | - | - | - | - | -| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 399.4 ns | 1.41 ns | 1.18 ns | 0.33 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 1,205.2 ns | 3.78 ns | 3.35 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 735.4 ns | 2.67 ns | 2.37 ns | 0.61 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference_For | List_Reference | 100 | 403.9 ns | 1.10 ns | 0.97 ns | 0.34 | - | - | - | - | +| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 399.8 ns | 1.51 ns | 1.18 ns | 0.33 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,095.8 ns | 37.36 ns | 29.17 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,536.8 ns | 16.65 ns | 15.58 ns | 0.78 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,226.5 ns | 19.84 ns | 17.58 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,544.6 ns | 21.90 ns | 19.41 ns | 0.77 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectCountBenchmarks.md b/Benchmarks/SelectCountBenchmarks.md index c8a5a260f..310108b9b 100644 --- a/Benchmarks/SelectCountBenchmarks.md +++ b/Benchmarks/SelectCountBenchmarks.md @@ -4,7 +4,7 @@ [SelectCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-------------:|-----------:|-----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 198.220 ns | 0.6773 ns | 0.6336 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 10.184 ns | 0.0197 ns | 0.0164 ns | 0.05 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 15.412 ns | 0.0319 ns | 0.0283 ns | 0.08 | - | - | - | - | +| Linq_Array | Array | 100 | 195.967 ns | 0.6597 ns | 0.5848 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 10.188 ns | 0.0342 ns | 0.0320 ns | 0.05 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 15.532 ns | 0.0697 ns | 0.0582 ns | 0.08 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 790.965 ns | 2.4941 ns | 2.2110 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 761.327 ns | 2.2745 ns | 1.7758 ns | 0.96 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 146.856 ns | 0.2308 ns | 0.2046 ns | 0.19 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 771.437 ns | 4.7738 ns | 4.2319 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 763.172 ns | 2.2538 ns | 2.1082 ns | 0.99 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 162.321 ns | 0.1898 ns | 0.1682 ns | 0.21 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 791.787 ns | 2.1413 ns | 1.8982 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 806.411 ns | 3.3071 ns | 2.9317 ns | 1.02 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 16.205 ns | 0.0335 ns | 0.0314 ns | 0.02 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 775.472 ns | 2.9631 ns | 2.7717 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 802.103 ns | 6.4102 ns | 5.3528 ns | 1.03 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 16.077 ns | 0.0369 ns | 0.0327 ns | 0.02 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 388.335 ns | 1.5311 ns | 1.4322 ns | 1.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Value | List_Value | 100 | 10.448 ns | 0.0232 ns | 0.0206 ns | 0.03 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 9.561 ns | 0.0320 ns | 0.0283 ns | 0.02 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 482.164 ns | 0.8969 ns | 0.7951 ns | 1.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Value | List_Value | 100 | 10.268 ns | 0.0340 ns | 0.0302 ns | 0.02 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 9.873 ns | 0.0109 ns | 0.0085 ns | 0.02 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,558.331 ns | 30.3258 ns | 28.3667 ns | 1.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,207.574 ns | 2.9260 ns | 2.4434 ns | 0.14 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,523.203 ns | 22.8359 ns | 20.2434 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 947.472 ns | 1.2425 ns | 1.1015 ns | 0.13 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 550.957 ns | 2.0793 ns | 1.9450 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 547.387 ns | 3.0914 ns | 2.8917 ns | 0.99 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 259.798 ns | 0.8359 ns | 0.6980 ns | 0.47 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 820.965 ns | 4.0317 ns | 3.7713 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 764.338 ns | 3.4927 ns | 2.9166 ns | 0.93 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 368.547 ns | 1.3929 ns | 1.1631 ns | 0.45 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 597.908 ns | 1.6524 ns | 1.5457 ns | 1.000 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 545.517 ns | 1.9988 ns | 1.8697 ns | 0.912 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.182 ns | 0.0329 ns | 0.0292 ns | 0.007 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 809.920 ns | 2.3646 ns | 1.9745 ns | 1.000 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 767.365 ns | 2.4976 ns | 2.0856 ns | 0.947 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.228 ns | 0.0221 ns | 0.0184 ns | 0.005 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 431.165 ns | 1.2621 ns | 0.9854 ns | 1.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Reference | List_Reference | 100 | 534.272 ns | 2.3511 ns | 2.0842 ns | 1.24 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 9.931 ns | 0.0424 ns | 0.0354 ns | 0.02 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 420.192 ns | 2.0857 ns | 1.9509 ns | 1.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Reference | List_Reference | 100 | 767.197 ns | 5.1913 ns | 4.6020 ns | 1.83 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 9.831 ns | 0.2176 ns | 0.2234 ns | 0.02 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,927.773 ns | 35.8253 ns | 33.5110 ns | 1.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,797.694 ns | 4.0443 ns | 3.5852 ns | 0.20 | 0.0191 | - | - | 40 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,586.118 ns | 32.0225 ns | 28.3871 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,630.690 ns | 31.2243 ns | 30.6665 ns | 0.22 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectManyBenchmarks.md b/Benchmarks/SelectManyBenchmarks.md index 9ab9aade6..7127f1f5d 100644 --- a/Benchmarks/SelectManyBenchmarks.md +++ b/Benchmarks/SelectManyBenchmarks.md @@ -4,7 +4,7 @@ [SelectManyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectManyBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,39 +14,39 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------- |-------------------------- |------ |----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 3.556 μs | 0.0119 μs | 0.0111 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_Array | Array | 100 | 1.226 μs | 0.0042 μs | 0.0035 μs | 0.34 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.381 μs | 0.0023 μs | 0.0021 μs | 0.39 | - | - | - | - | +| Linq_Array | Array | 100 | 2.825 μs | 0.0094 μs | 0.0084 μs | 1.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Array | Array | 100 | 1.227 μs | 0.0019 μs | 0.0016 μs | 0.43 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.415 μs | 0.0230 μs | 0.0215 μs | 0.50 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.817 μs | 0.0077 μs | 0.0065 μs | 1.00 | 1.9531 | - | - | 4096 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.439 μs | 0.0133 μs | 0.0111 μs | 0.90 | 2.3575 | - | - | 4936 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.925 μs | 0.0093 μs | 0.0077 μs | 1.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.394 μs | 0.0151 μs | 0.0141 μs | 1.16 | 2.3575 | - | - | 4,936 B | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 3.821 μs | 0.0122 μs | 0.0114 μs | 1.00 | 1.9531 | - | - | 4096 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.360 μs | 0.0157 μs | 0.0140 μs | 0.88 | 2.3575 | - | - | 4936 B | +| Linq_Collection_Value | Collection_Value | 100 | 2.993 μs | 0.0306 μs | 0.0255 μs | 1.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.451 μs | 0.0081 μs | 0.0067 μs | 1.15 | 2.3575 | - | - | 4,936 B | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 3.754 μs | 0.0147 μs | 0.0130 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_List_Value | List_Value | 100 | 3.530 μs | 0.0093 μs | 0.0078 μs | 0.94 | 2.3537 | - | - | 4928 B | +| Linq_List_Value | List_Value | 100 | 2.919 μs | 0.0096 μs | 0.0080 μs | 1.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_List_Value | List_Value | 100 | 3.660 μs | 0.0242 μs | 0.0214 μs | 1.25 | 2.3537 | - | - | 4,928 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 13.831 μs | 0.0353 μs | 0.0313 μs | 1.00 | 2.3346 | - | - | 4912 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 12.341 μs | 0.0542 μs | 0.0480 μs | 1.00 | 2.3346 | - | - | 4,904 B | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 3.596 μs | 0.0158 μs | 0.0148 μs | 1.00 | 1.9531 | - | - | 4096 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 3.201 μs | 0.0208 μs | 0.0185 μs | 0.89 | 2.3499 | - | - | 4920 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.992 μs | 0.0233 μs | 0.0218 μs | 1.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 3.384 μs | 0.0112 μs | 0.0099 μs | 1.13 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 3.545 μs | 0.0128 μs | 0.0113 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 3.193 μs | 0.0111 μs | 0.0098 μs | 0.90 | 2.3499 | - | - | 4920 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 2.966 μs | 0.0183 μs | 0.0171 μs | 1.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 3.468 μs | 0.0193 μs | 0.0171 μs | 1.17 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 3.528 μs | 0.0116 μs | 0.0103 μs | 1.00 | 1.9569 | - | - | 4096 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 3.620 μs | 0.0165 μs | 0.0146 μs | 1.03 | 2.3537 | - | - | 4928 B | +| Linq_List_Reference | List_Reference | 100 | 2.976 μs | 0.0175 μs | 0.0155 μs | 1.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 3.618 μs | 0.0194 μs | 0.0162 μs | 1.22 | 2.3537 | - | - | 4,928 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 13.608 μs | 0.0423 μs | 0.0375 μs | 1.00 | 2.3346 | - | - | 4912 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 12.289 μs | 0.0295 μs | 0.0247 μs | 1.00 | 2.3346 | - | - | 4,904 B | diff --git a/Benchmarks/SelectSumBenchmarks.md b/Benchmarks/SelectSumBenchmarks.md index a384b3f00..eb550e103 100644 --- a/Benchmarks/SelectSumBenchmarks.md +++ b/Benchmarks/SelectSumBenchmarks.md @@ -4,7 +4,7 @@ [SelectSumBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,48 +14,48 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 654.18 ns | 3.445 ns | 2.877 ns | 653.02 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 181.81 ns | 0.777 ns | 0.689 ns | 181.78 ns | 0.28 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 198.64 ns | 0.591 ns | 0.493 ns | 198.51 ns | 0.30 | 0.00 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 66.12 ns | 0.259 ns | 0.242 ns | 66.06 ns | 0.10 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,157.21 ns | 7.054 ns | 5.891 ns | 1,158.61 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 824.79 ns | 16.388 ns | 32.348 ns | 808.26 ns | 0.73 | 0.03 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 205.29 ns | 0.779 ns | 0.651 ns | 205.36 ns | 0.18 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,196.57 ns | 5.153 ns | 4.568 ns | 1,197.16 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 781.53 ns | 1.587 ns | 1.239 ns | 781.40 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 241.25 ns | 0.687 ns | 0.609 ns | 241.33 ns | 0.20 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,215.92 ns | 5.309 ns | 4.433 ns | 1,214.85 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 343.30 ns | 1.155 ns | 1.080 ns | 343.05 ns | 0.28 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 638.69 ns | 1.304 ns | 1.089 ns | 638.68 ns | 0.53 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 9,248.73 ns | 32.956 ns | 29.215 ns | 9,246.09 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,832.96 ns | 3.763 ns | 3.142 ns | 2,832.44 ns | 0.31 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 931.83 ns | 3.446 ns | 3.055 ns | 932.08 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 575.52 ns | 1.889 ns | 1.578 ns | 575.47 ns | 0.62 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 547.15 ns | 2.083 ns | 1.847 ns | 546.84 ns | 0.59 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 972.85 ns | 4.653 ns | 4.352 ns | 970.63 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 580.05 ns | 2.791 ns | 2.610 ns | 579.80 ns | 0.60 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 541.45 ns | 2.817 ns | 2.497 ns | 540.77 ns | 0.56 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 967.52 ns | 3.570 ns | 3.165 ns | 967.75 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 573.72 ns | 2.226 ns | 1.973 ns | 573.90 ns | 0.59 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 638.77 ns | 2.185 ns | 1.825 ns | 639.27 ns | 0.66 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,606.46 ns | 23.219 ns | 20.583 ns | 8,604.72 ns | 1.00 | 0.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,493.55 ns | 8.193 ns | 7.664 ns | 3,492.49 ns | 0.41 | 0.00 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 624.04 ns | 3.238 ns | 3.029 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 206.45 ns | 0.546 ns | 0.456 ns | 0.33 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 200.01 ns | 0.456 ns | 0.404 ns | 0.32 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 66.82 ns | 0.265 ns | 0.234 ns | 0.11 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,160.78 ns | 6.146 ns | 5.448 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 776.38 ns | 4.821 ns | 4.509 ns | 0.67 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 204.93 ns | 0.518 ns | 0.433 ns | 0.18 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,164.42 ns | 2.973 ns | 2.781 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 795.29 ns | 2.956 ns | 2.468 ns | 0.68 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 213.97 ns | 0.790 ns | 0.700 ns | 0.18 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,174.97 ns | 7.585 ns | 7.095 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 347.10 ns | 1.846 ns | 1.636 ns | 0.30 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 619.75 ns | 2.497 ns | 2.085 ns | 0.53 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,626.26 ns | 25.790 ns | 22.863 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,295.19 ns | 6.061 ns | 5.373 ns | 0.30 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,166.44 ns | 2.742 ns | 2.430 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 780.54 ns | 4.485 ns | 4.196 ns | 0.67 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 769.02 ns | 3.871 ns | 3.431 ns | 0.66 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,160.10 ns | 6.752 ns | 5.985 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 791.96 ns | 2.826 ns | 2.360 ns | 0.68 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 744.96 ns | 3.601 ns | 3.192 ns | 0.64 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,170.01 ns | 6.032 ns | 5.347 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 772.95 ns | 4.429 ns | 3.926 ns | 0.66 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 692.92 ns | 3.153 ns | 2.950 ns | 0.59 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,577.98 ns | 27.143 ns | 24.062 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,061.96 ns | 6.833 ns | 6.057 ns | 0.40 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectToArrayBenchmarks.md b/Benchmarks/SelectToArrayBenchmarks.md index d7a998884..8fea5ca6b 100644 --- a/Benchmarks/SelectToArrayBenchmarks.md +++ b/Benchmarks/SelectToArrayBenchmarks.md @@ -4,7 +4,7 @@ [SelectToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|-----------:|-----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 266.30 ns | 0.996 ns | 0.883 ns | 266.33 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | -| StructLinq_Array | Array | 100 | 230.11 ns | 0.430 ns | 0.402 ns | 230.07 ns | 0.86 | 0.00 | 0.2027 | - | - | 424 B | -| LinqFasterSIMD_Array | Array | 100 | 61.06 ns | 0.906 ns | 0.848 ns | 61.18 ns | 0.23 | 0.00 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 228.43 ns | 4.636 ns | 6.795 ns | 225.50 ns | 0.87 | 0.03 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array_SIMD | Array | 100 | 80.84 ns | 0.477 ns | 0.422 ns | 80.85 ns | 0.30 | 0.00 | 0.2027 | - | - | 424 B | +| Linq_Array | Array | 100 | 219.64 ns | 3.342 ns | 2.609 ns | 218.45 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | +| StructLinq_Array | Array | 100 | 239.53 ns | 4.705 ns | 6.118 ns | 237.06 ns | 1.10 | 0.04 | 0.2027 | - | - | 424 B | +| LinqFasterSIMD_Array | Array | 100 | 61.80 ns | 0.444 ns | 0.371 ns | 61.78 ns | 0.28 | 0.00 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 228.42 ns | 1.300 ns | 1.216 ns | 228.24 ns | 1.04 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array_SIMD | Array | 100 | 83.17 ns | 0.507 ns | 0.423 ns | 82.98 ns | 0.38 | 0.00 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,087.02 ns | 4.618 ns | 4.320 ns | 1,086.41 ns | 1.00 | 0.00 | 0.5913 | - | - | 1240 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,027.28 ns | 3.503 ns | 3.105 ns | 1,026.13 ns | 0.95 | 0.00 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 577.04 ns | 7.168 ns | 6.354 ns | 574.94 ns | 0.53 | 0.01 | 0.2022 | - | - | 424 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,083.36 ns | 17.145 ns | 14.317 ns | 1,078.07 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,094.55 ns | 6.370 ns | 5.319 ns | 1,094.50 ns | 1.01 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 590.88 ns | 2.817 ns | 2.497 ns | 591.27 ns | 0.55 | 0.01 | 0.2022 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,016.00 ns | 4.421 ns | 3.919 ns | 1,015.71 ns | 1.00 | 0.00 | 0.5913 | - | - | 1240 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,003.42 ns | 3.857 ns | 3.608 ns | 1,003.91 ns | 0.99 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 329.29 ns | 6.231 ns | 10.238 ns | 326.48 ns | 0.33 | 0.01 | 0.2027 | - | - | 424 B | +| Linq_Collection_Value | Collection_Value | 100 | 1,108.09 ns | 21.893 ns | 33.433 ns | 1,100.53 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,063.27 ns | 5.059 ns | 4.485 ns | 1,063.31 ns | 0.96 | 0.03 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 337.41 ns | 2.007 ns | 1.780 ns | 336.84 ns | 0.30 | 0.01 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 450.50 ns | 1.984 ns | 1.856 ns | 450.73 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Value | List_Value | 100 | 420.33 ns | 0.768 ns | 0.600 ns | 420.47 ns | 0.93 | 0.00 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 710.39 ns | 2.213 ns | 2.070 ns | 710.80 ns | 1.58 | 0.01 | 0.2022 | - | - | 424 B | +| Linq_List_Value | List_Value | 100 | 464.84 ns | 9.535 ns | 26.421 ns | 451.63 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Value | List_Value | 100 | 429.96 ns | 1.118 ns | 0.933 ns | 430.25 ns | 0.88 | 0.06 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 731.32 ns | 14.433 ns | 24.114 ns | 719.49 ns | 1.53 | 0.12 | 0.2022 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 9,100.44 ns | 173.408 ns | 269.975 ns | 8,970.54 ns | 1.00 | 0.00 | 0.7935 | - | - | 1680 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,243.73 ns | 5.176 ns | 4.588 ns | 3,242.45 ns | 0.36 | 0.01 | 0.5646 | - | - | 1184 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,013.72 ns | 43.980 ns | 36.725 ns | 8,010.56 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,691.14 ns | 8.372 ns | 7.831 ns | 2,690.70 ns | 0.34 | 0.00 | 0.5646 | - | - | 1,184 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 880.15 ns | 17.540 ns | 38.502 ns | 859.06 ns | 1.00 | 0.00 | 0.5922 | - | - | 1240 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 848.52 ns | 2.958 ns | 2.622 ns | 848.33 ns | 0.97 | 0.04 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 870.31 ns | 4.246 ns | 3.764 ns | 870.27 ns | 1.00 | 0.04 | 0.2174 | - | - | 456 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,070.31 ns | 3.945 ns | 3.497 ns | 1,069.38 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,038.29 ns | 4.257 ns | 3.555 ns | 1,038.69 ns | 0.97 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,116.07 ns | 4.839 ns | 4.290 ns | 1,115.42 ns | 1.04 | 0.00 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 809.89 ns | 4.995 ns | 4.428 ns | 809.57 ns | 1.00 | 0.00 | 0.5922 | - | - | 1240 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 817.48 ns | 3.859 ns | 3.421 ns | 817.35 ns | 1.01 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 603.54 ns | 2.087 ns | 1.952 ns | 603.40 ns | 0.75 | 0.00 | 0.2174 | - | - | 456 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,098.39 ns | 3.601 ns | 3.192 ns | 1,098.48 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,046.69 ns | 3.930 ns | 3.483 ns | 1,046.08 ns | 0.95 | 0.00 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 812.84 ns | 2.602 ns | 2.434 ns | 812.98 ns | 0.74 | 0.00 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 411.50 ns | 3.098 ns | 2.587 ns | 411.04 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Reference | List_Reference | 100 | 864.78 ns | 6.857 ns | 6.079 ns | 864.46 ns | 2.10 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 725.33 ns | 1.868 ns | 1.656 ns | 725.76 ns | 1.76 | 0.01 | 0.2022 | - | - | 424 B | +| Linq_List_Reference | List_Reference | 100 | 412.14 ns | 2.762 ns | 2.448 ns | 411.58 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,046.03 ns | 3.970 ns | 3.099 ns | 1,045.62 ns | 2.54 | 0.02 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 733.19 ns | 2.886 ns | 2.700 ns | 733.51 ns | 1.78 | 0.01 | 0.2022 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 9,888.42 ns | 33.364 ns | 29.576 ns | 9,880.00 ns | 1.00 | 0.00 | 0.7935 | - | - | 1680 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,841.00 ns | 11.640 ns | 10.318 ns | 4,841.20 ns | 0.49 | 0.00 | 0.5798 | - | - | 1224 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,264.86 ns | 163.535 ns | 307.158 ns | 8,161.45 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,500.80 ns | 28.083 ns | 23.450 ns | 3,491.77 ns | 0.42 | 0.02 | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/SelectToListBenchmarks.md b/Benchmarks/SelectToListBenchmarks.md index 7570cac33..1dfe244bd 100644 --- a/Benchmarks/SelectToListBenchmarks.md +++ b/Benchmarks/SelectToListBenchmarks.md @@ -4,7 +4,7 @@ [SelectToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,46 +14,48 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|-----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 253.61 ns | 1.216 ns | 1.078 ns | 253.58 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | -| StructLinq_Array | Array | 100 | 240.35 ns | 0.978 ns | 0.867 ns | 240.29 ns | 0.95 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 233.42 ns | 0.858 ns | 0.803 ns | 233.15 ns | 0.92 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array_SIMD | Array | 100 | 92.40 ns | 0.458 ns | 0.406 ns | 92.34 ns | 0.36 | 0.00 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,041.43 ns | 3.515 ns | 3.116 ns | 1,040.74 ns | 1.00 | 0.00 | 0.6065 | - | - | 1272 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,063.21 ns | 4.399 ns | 3.899 ns | 1,063.23 ns | 1.02 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 608.65 ns | 5.087 ns | 4.248 ns | 608.84 ns | 0.58 | 0.00 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,080.18 ns | 5.664 ns | 5.021 ns | 1,079.65 ns | 1.00 | 0.00 | 0.6065 | - | - | 1272 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,014.86 ns | 3.208 ns | 2.679 ns | 1,015.04 ns | 0.94 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 254.47 ns | 0.771 ns | 0.684 ns | 254.55 ns | 0.24 | 0.00 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 476.58 ns | 8.462 ns | 12.403 ns | 471.41 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Value | List_Value | 100 | 404.32 ns | 1.011 ns | 0.946 ns | 404.40 ns | 0.84 | 0.02 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 716.97 ns | 2.596 ns | 2.301 ns | 717.30 ns | 1.49 | 0.04 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 862.70 ns | 2.807 ns | 2.488 ns | 863.12 ns | 1.00 | 0.00 | 0.6075 | - | - | 1272 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 862.81 ns | 2.362 ns | 1.973 ns | 862.31 ns | 1.00 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 928.89 ns | 5.865 ns | 5.486 ns | 927.72 ns | 1.08 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 888.21 ns | 16.842 ns | 34.403 ns | 871.97 ns | 1.00 | 0.00 | 0.6075 | - | - | 1272 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 811.46 ns | 4.436 ns | 3.704 ns | 812.39 ns | 0.88 | 0.04 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 604.53 ns | 3.046 ns | 2.850 ns | 604.67 ns | 0.66 | 0.03 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 488.13 ns | 1.409 ns | 1.318 ns | 487.52 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Reference | List_Reference | 100 | 809.28 ns | 2.379 ns | 2.226 ns | 809.99 ns | 1.66 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 736.16 ns | 14.615 ns | 20.961 ns | 726.79 ns | 1.52 | 0.05 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,239.23 ns | 5.002 ns | 4.177 ns | 3,239.25 ns | ? | ? | 0.5798 | - | - | 1216 B | -| | | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,100.41 ns | 80.671 ns | 104.895 ns | 4,072.31 ns | ? | ? | 0.5951 | - | - | 1256 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 328.41 ns | 1.343 ns | 1.190 ns | 328.28 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | +| StructLinq_Array | Array | 100 | 250.78 ns | 1.578 ns | 1.398 ns | 250.56 ns | 0.76 | 0.00 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 238.97 ns | 0.796 ns | 0.705 ns | 238.75 ns | 0.73 | 0.00 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array_SIMD | Array | 100 | 91.71 ns | 0.274 ns | 0.229 ns | 91.75 ns | 0.28 | 0.00 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,077.53 ns | 3.826 ns | 3.391 ns | 1,077.96 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,086.74 ns | 4.359 ns | 3.864 ns | 1,087.33 ns | 1.01 | 0.00 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 584.68 ns | 1.477 ns | 1.233 ns | 584.39 ns | 0.54 | 0.00 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,075.27 ns | 5.659 ns | 4.418 ns | 1,073.35 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,090.71 ns | 4.000 ns | 3.546 ns | 1,092.31 ns | 1.01 | 0.00 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 284.67 ns | 0.905 ns | 0.802 ns | 284.70 ns | 0.26 | 0.00 | 0.2179 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 494.15 ns | 2.027 ns | 1.693 ns | 494.24 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Value | List_Value | 100 | 421.75 ns | 2.045 ns | 1.913 ns | 421.72 ns | 0.85 | 0.00 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 699.97 ns | 2.857 ns | 2.385 ns | 700.04 ns | 1.42 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,072.61 ns | 63.935 ns | 49.916 ns | 8,072.89 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,752.00 ns | 10.470 ns | 9.281 ns | 2,749.44 ns | 0.34 | 0.00 | 0.5798 | - | - | 1,216 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,057.57 ns | 6.568 ns | 5.823 ns | 1,056.86 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,070.48 ns | 3.387 ns | 3.168 ns | 1,070.46 ns | 1.01 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,130.56 ns | 6.983 ns | 6.190 ns | 1,129.37 ns | 1.07 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,056.31 ns | 4.561 ns | 3.808 ns | 1,056.26 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,045.65 ns | 4.994 ns | 4.671 ns | 1,045.30 ns | 0.99 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 863.54 ns | 17.211 ns | 40.229 ns | 848.88 ns | 0.85 | 0.05 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 507.48 ns | 2.043 ns | 1.811 ns | 507.20 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,047.64 ns | 3.631 ns | 3.397 ns | 1,046.74 ns | 2.06 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 696.65 ns | 2.076 ns | 1.734 ns | 697.20 ns | 1.37 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,329.45 ns | 30.382 ns | 26.933 ns | 8,333.65 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,534.33 ns | 6.510 ns | 5.436 ns | 3,532.52 ns | 0.42 | 0.00 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/SingleBenchmarks.md b/Benchmarks/SingleBenchmarks.md index ef8be53fa..b25c4e2ff 100644 --- a/Benchmarks/SingleBenchmarks.md +++ b/Benchmarks/SingleBenchmarks.md @@ -18,34 +18,34 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-QTIORM : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------- |-------------------------- |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 11.111 ns | 0.1723 ns | 0.2783 ns | 11.048 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 14.543 ns | 0.1511 ns | 0.1339 ns | 14.520 ns | 1.31 | 0.03 | - | - | - | - | +| Linq_Array | Array | 11.635 ns | 0.0684 ns | 0.0640 ns | 11.627 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 13.992 ns | 0.0369 ns | 0.0346 ns | 13.991 ns | 1.20 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 31.916 ns | 1.9593 ns | 5.7769 ns | 29.905 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 17.802 ns | 0.0964 ns | 0.0805 ns | 17.776 ns | 0.58 | 0.08 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 22.812 ns | 0.1626 ns | 0.1357 ns | 22.762 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 16.591 ns | 0.0190 ns | 0.0148 ns | 16.588 ns | 0.73 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 33.340 ns | 1.2638 ns | 3.7263 ns | 33.084 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 21.505 ns | 0.4538 ns | 0.8299 ns | 21.617 ns | 0.67 | 0.06 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 24.000 ns | 0.0923 ns | 0.0771 ns | 24.008 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 20.092 ns | 0.4312 ns | 0.9283 ns | 19.611 ns | 0.83 | 0.04 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 8.142 ns | 0.1845 ns | 0.1895 ns | 8.073 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 17.170 ns | 0.5859 ns | 1.7275 ns | 16.305 ns | 2.11 | 0.25 | - | - | - | - | +| Linq_List_Value | List_Value | 7.458 ns | 0.0386 ns | 0.0342 ns | 7.458 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 15.178 ns | 0.0638 ns | 0.0533 ns | 15.181 ns | 2.04 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 87.198 ns | 0.7828 ns | 0.6940 ns | 87.109 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 80.227 ns | 0.2933 ns | 0.2449 ns | 80.195 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 27.682 ns | 0.5862 ns | 0.6751 ns | 27.613 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 29.365 ns | 1.7127 ns | 5.0498 ns | 27.674 ns | 1.11 | 0.22 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 23.091 ns | 0.1006 ns | 0.0892 ns | 23.088 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 20.565 ns | 0.2968 ns | 0.3048 ns | 20.477 ns | 0.89 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 29.387 ns | 0.6172 ns | 1.6152 ns | 28.745 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 26.202 ns | 0.7604 ns | 2.1447 ns | 26.031 ns | 0.89 | 0.10 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 23.872 ns | 0.1125 ns | 0.1052 ns | 23.871 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 19.679 ns | 0.1339 ns | 0.1187 ns | 19.635 ns | 0.82 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 7.951 ns | 0.1252 ns | 0.1171 ns | 7.915 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 16.146 ns | 0.3480 ns | 0.6276 ns | 16.051 ns | 2.03 | 0.08 | - | - | - | - | +| Linq_List_Reference | List_Reference | 7.714 ns | 0.1763 ns | 0.3223 ns | 7.603 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 15.060 ns | 0.0598 ns | 0.0530 ns | 15.045 ns | 1.93 | 0.11 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 89.215 ns | 1.7324 ns | 2.2526 ns | 88.796 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 81.415 ns | 1.6193 ns | 3.4857 ns | 79.958 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SkipTakeBenchmarks.md b/Benchmarks/SkipTakeBenchmarks.md index 439aa3d75..880a317b1 100644 --- a/Benchmarks/SkipTakeBenchmarks.md +++ b/Benchmarks/SkipTakeBenchmarks.md @@ -4,7 +4,7 @@ [SkipTakeBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,54 +14,54 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Skip | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |----- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 100 | 849.41 ns | 3.438 ns | 2.870 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| StructLinq_Array | Array | 100 | 100 | 116.34 ns | 2.178 ns | 3.927 ns | 0.14 | 0.01 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 100 | 144.20 ns | 0.462 ns | 0.386 ns | 0.17 | 0.00 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 100 | 179.67 ns | 0.847 ns | 0.708 ns | 0.21 | 0.00 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 100 | 80.75 ns | 0.520 ns | 0.461 ns | 0.10 | 0.00 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 100 | 172.12 ns | 0.463 ns | 0.361 ns | 0.20 | 0.00 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 100 | 226.10 ns | 0.961 ns | 0.852 ns | 0.27 | 0.00 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 176.70 ns | 0.371 ns | 0.329 ns | 0.21 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 100 | 902.71 ns | 2.658 ns | 2.219 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| StructLinq_Array | Array | 100 | 100 | 112.12 ns | 0.192 ns | 0.160 ns | 0.12 | 0.00 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 100 | 107.79 ns | 0.367 ns | 0.287 ns | 0.12 | 0.00 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 100 | 186.24 ns | 0.505 ns | 0.448 ns | 0.21 | 0.00 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 100 | 81.25 ns | 0.248 ns | 0.219 ns | 0.09 | 0.00 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 100 | 172.23 ns | 0.336 ns | 0.298 ns | 0.19 | 0.00 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 100 | 230.42 ns | 0.646 ns | 0.539 ns | 0.26 | 0.00 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 183.45 ns | 0.349 ns | 0.310 ns | 0.20 | 0.00 | - | - | - | - | | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,494.65 ns | 3.827 ns | 3.196 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,022.35 ns | 20.233 ns | 33.244 ns | 0.70 | 0.03 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 447.26 ns | 1.050 ns | 0.931 ns | 0.30 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,559.15 ns | 6.211 ns | 5.506 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 994.03 ns | 4.729 ns | 3.692 ns | 0.64 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 475.14 ns | 0.961 ns | 0.852 ns | 0.30 | 0.00 | - | - | - | - | | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,491.03 ns | 3.881 ns | 3.440 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 997.75 ns | 3.011 ns | 2.350 ns | 0.67 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 551.51 ns | 2.405 ns | 2.132 ns | 0.37 | 0.00 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,558.00 ns | 7.834 ns | 6.945 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 994.20 ns | 3.863 ns | 3.226 ns | 0.64 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 597.12 ns | 3.689 ns | 3.270 ns | 0.38 | 0.00 | - | - | - | - | | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 100 | 795.02 ns | 5.166 ns | 4.314 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Value | List_Value | 100 | 100 | 224.83 ns | 0.397 ns | 0.310 ns | 0.28 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 245.96 ns | 0.985 ns | 0.921 ns | 0.31 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 219.36 ns | 0.923 ns | 0.771 ns | 0.28 | 0.00 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 100 | 841.66 ns | 2.832 ns | 2.211 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Value | List_Value | 100 | 100 | 252.80 ns | 1.332 ns | 1.040 ns | 0.30 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 249.39 ns | 1.399 ns | 1.309 ns | 0.30 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 220.75 ns | 0.740 ns | 0.618 ns | 0.26 | 0.00 | - | - | - | - | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 9,739.61 ns | 26.639 ns | 23.615 ns | 1.00 | 0.00 | 0.0763 | - | - | 184 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 5,344.59 ns | 13.071 ns | 11.587 ns | 0.55 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 8,763.59 ns | 33.055 ns | 30.920 ns | 1.00 | 0.00 | 0.0763 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 4,701.30 ns | 15.689 ns | 14.676 ns | 0.54 | 0.00 | - | - | - | - | | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,180.94 ns | 5.532 ns | 4.619 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 712.26 ns | 2.693 ns | 2.387 ns | 0.60 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 835.20 ns | 2.755 ns | 2.442 ns | 0.71 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,560.19 ns | 9.015 ns | 7.992 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 997.33 ns | 3.544 ns | 3.141 ns | 0.64 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,098.92 ns | 3.134 ns | 2.778 ns | 0.70 | 0.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,179.76 ns | 4.184 ns | 3.709 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 713.51 ns | 2.994 ns | 2.801 ns | 0.60 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 889.84 ns | 5.805 ns | 5.146 ns | 0.75 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,564.56 ns | 10.457 ns | 9.782 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 992.69 ns | 4.468 ns | 4.180 ns | 0.63 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 1,395.36 ns | 24.772 ns | 23.171 ns | 0.89 | 0.02 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 100 | 797.12 ns | 3.318 ns | 2.941 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Reference | List_Reference | 100 | 100 | 710.34 ns | 2.152 ns | 1.908 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 265.26 ns | 1.894 ns | 1.679 ns | 0.33 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 220.22 ns | 1.062 ns | 0.887 ns | 0.28 | 0.00 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 100 | 839.72 ns | 3.032 ns | 2.532 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Reference | List_Reference | 100 | 100 | 993.12 ns | 5.039 ns | 4.467 ns | 1.18 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 247.86 ns | 0.783 ns | 0.694 ns | 0.30 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 220.54 ns | 0.657 ns | 0.548 ns | 0.26 | 0.00 | - | - | - | - | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 9,553.58 ns | 31.181 ns | 27.641 ns | 1.00 | 0.00 | 0.0763 | - | - | 184 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 6,700.30 ns | 19.039 ns | 16.878 ns | 0.70 | 0.00 | 0.0153 | - | - | 40 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 8,813.65 ns | 35.743 ns | 31.685 ns | 1.00 | 0.00 | 0.0763 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 5,739.89 ns | 18.257 ns | 17.078 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SumBenchmarks.md b/Benchmarks/SumBenchmarks.md index 78ef29451..ebb517241 100644 --- a/Benchmarks/SumBenchmarks.md +++ b/Benchmarks/SumBenchmarks.md @@ -4,7 +4,7 @@ [SumBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,48 +14,48 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 439.06 ns | 1.415 ns | 1.324 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | Array | 100 | 61.70 ns | 0.275 ns | 0.230 ns | 0.14 | - | - | - | - | -| LinqFasterSIMD_Array | Array | 100 | 12.18 ns | 0.033 ns | 0.030 ns | 0.03 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 23.31 ns | 0.081 ns | 0.076 ns | 0.05 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 626.31 ns | 4.614 ns | 3.853 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 613.05 ns | 2.688 ns | 2.383 ns | 0.98 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 217.91 ns | 0.335 ns | 0.297 ns | 0.35 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 629.35 ns | 6.732 ns | 6.297 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 614.08 ns | 1.502 ns | 1.254 ns | 0.98 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 218.77 ns | 0.326 ns | 0.305 ns | 0.35 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 630.95 ns | 2.247 ns | 1.876 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Value | List_Value | 100 | 221.11 ns | 0.569 ns | 0.476 ns | 0.35 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 218.26 ns | 0.609 ns | 0.540 ns | 0.35 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,103.14 ns | 6.460 ns | 5.726 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,250.68 ns | 2.283 ns | 2.024 ns | 0.59 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 413.93 ns | 2.534 ns | 2.116 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 389.11 ns | 1.314 ns | 1.165 ns | 0.94 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 414.19 ns | 2.253 ns | 1.997 ns | 1.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 412.53 ns | 1.369 ns | 1.143 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 389.06 ns | 0.867 ns | 0.724 ns | 0.94 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 410.67 ns | 2.361 ns | 2.209 ns | 1.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 413.93 ns | 1.624 ns | 1.356 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Reference | List_Reference | 100 | 390.65 ns | 1.376 ns | 1.287 ns | 0.94 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 217.56 ns | 0.706 ns | 0.661 ns | 0.53 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,903.89 ns | 6.329 ns | 5.610 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,932.12 ns | 4.151 ns | 3.883 ns | 1.02 | 0.0191 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 425.27 ns | 2.881 ns | 2.695 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 65.84 ns | 0.273 ns | 0.242 ns | 0.15 | 0.00 | - | - | - | - | +| LinqFasterSIMD_Array | Array | 100 | 10.69 ns | 0.044 ns | 0.041 ns | 0.03 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 23.66 ns | 0.072 ns | 0.068 ns | 0.06 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 634.67 ns | 2.631 ns | 2.054 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 605.39 ns | 3.714 ns | 3.474 ns | 0.95 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 219.93 ns | 0.603 ns | 0.534 ns | 0.35 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 634.89 ns | 3.052 ns | 2.706 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 602.10 ns | 2.106 ns | 1.867 ns | 0.95 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 219.81 ns | 0.299 ns | 0.265 ns | 0.35 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 633.89 ns | 4.020 ns | 3.761 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 225.58 ns | 3.444 ns | 4.939 ns | 0.36 | 0.01 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 538.85 ns | 1.711 ns | 1.517 ns | 0.85 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,758.59 ns | 4.769 ns | 4.227 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 991.61 ns | 3.324 ns | 2.947 ns | 0.56 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 630.94 ns | 2.925 ns | 2.736 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 604.48 ns | 2.336 ns | 2.071 ns | 0.96 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 634.73 ns | 2.188 ns | 1.939 ns | 1.01 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 632.99 ns | 3.984 ns | 3.532 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 603.76 ns | 2.819 ns | 2.354 ns | 0.95 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 627.49 ns | 1.632 ns | 1.447 ns | 0.99 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 647.44 ns | 11.664 ns | 19.806 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 604.37 ns | 1.283 ns | 1.137 ns | 0.92 | 0.03 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 494.88 ns | 2.268 ns | 1.894 ns | 0.75 | 0.03 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,757.92 ns | 4.957 ns | 4.139 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,776.30 ns | 4.838 ns | 4.288 ns | 1.01 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ToArrayBenchmarks.md b/Benchmarks/ToArrayBenchmarks.md index 661fd5b88..d1b08099b 100644 --- a/Benchmarks/ToArrayBenchmarks.md +++ b/Benchmarks/ToArrayBenchmarks.md @@ -4,7 +4,7 @@ [ToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,45 +14,45 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 49.55 ns | 0.656 ns | 0.582 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Array | Array | 100 | 79.60 ns | 0.239 ns | 0.200 ns | 1.61 | 0.02 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 37.57 ns | 0.124 ns | 0.110 ns | 0.76 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 942.82 ns | 4.818 ns | 3.762 ns | 1.00 | 0.00 | 0.5646 | - | - | 1184 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 940.98 ns | 2.934 ns | 2.450 ns | 1.00 | 0.00 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 506.45 ns | 2.280 ns | 2.133 ns | 0.54 | 0.00 | 0.2213 | - | - | 464 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 43.92 ns | 0.171 ns | 0.143 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 886.16 ns | 3.552 ns | 3.323 ns | 20.17 | 0.07 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 132.67 ns | 1.076 ns | 1.007 ns | 3.02 | 0.02 | 0.2217 | - | - | 464 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 45.17 ns | 0.369 ns | 0.308 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Value | List_Value | 100 | 272.36 ns | 0.609 ns | 0.475 ns | 6.03 | 0.04 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 524.33 ns | 2.163 ns | 1.807 ns | 11.61 | 0.09 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 717.70 ns | 3.132 ns | 2.777 ns | 1.00 | 0.00 | 0.5655 | - | - | 1184 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 691.29 ns | 3.306 ns | 2.930 ns | 0.96 | 0.00 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 794.63 ns | 4.396 ns | 3.897 ns | 1.11 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 43.62 ns | 0.555 ns | 0.519 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 726.35 ns | 3.630 ns | 3.218 ns | 16.66 | 0.25 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 486.52 ns | 3.939 ns | 3.491 ns | 11.16 | 0.16 | 0.2289 | - | - | 480 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 45.43 ns | 0.153 ns | 0.136 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Reference | List_Reference | 100 | 681.49 ns | 3.162 ns | 2.803 ns | 15.00 | 0.08 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 555.79 ns | 2.546 ns | 2.126 ns | 12.24 | 0.05 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,648.08 ns | 4.695 ns | 4.162 ns | ? | ? | 0.5646 | - | - | 1184 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,283.01 ns | 5.415 ns | 4.800 ns | ? | ? | 0.5836 | - | - | 1224 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 50.97 ns | 0.450 ns | 0.399 ns | 50.91 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Array | Array | 100 | 82.41 ns | 0.398 ns | 0.372 ns | 82.48 ns | 1.62 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 38.24 ns | 0.447 ns | 0.396 ns | 38.21 ns | 0.75 | 0.01 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 924.44 ns | 16.211 ns | 26.178 ns | 911.77 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 855.97 ns | 4.395 ns | 3.896 ns | 855.47 ns | 0.91 | 0.03 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 535.49 ns | 2.560 ns | 2.137 ns | 535.19 ns | 0.57 | 0.02 | 0.2213 | - | - | 464 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 45.29 ns | 0.259 ns | 0.230 ns | 45.28 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 880.78 ns | 3.505 ns | 2.926 ns | 880.52 ns | 19.45 | 0.09 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 137.30 ns | 0.759 ns | 0.673 ns | 137.27 ns | 3.03 | 0.02 | 0.2217 | - | - | 464 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 48.02 ns | 0.598 ns | 0.530 ns | 48.10 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Value | List_Value | 100 | 275.88 ns | 1.662 ns | 1.555 ns | 275.99 ns | 5.75 | 0.08 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 552.05 ns | 3.294 ns | 2.920 ns | 551.52 ns | 11.50 | 0.17 | 0.2022 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 913.85 ns | 7.358 ns | 6.144 ns | 911.78 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 880.11 ns | 4.908 ns | 4.351 ns | 879.76 ns | 0.96 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,012.75 ns | 3.967 ns | 3.517 ns | 1,011.31 ns | 1.11 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 48.19 ns | 1.145 ns | 3.172 ns | 46.69 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 930.43 ns | 6.676 ns | 6.245 ns | 928.30 ns | 19.60 | 1.21 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 718.27 ns | 6.036 ns | 5.646 ns | 717.41 ns | 15.13 | 0.90 | 0.2289 | - | - | 480 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 49.20 ns | 1.051 ns | 2.330 ns | 48.29 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Reference | List_Reference | 100 | 882.71 ns | 6.091 ns | 5.399 ns | 880.09 ns | 17.43 | 1.03 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 549.66 ns | 2.190 ns | 1.829 ns | 549.87 ns | 10.82 | 0.64 | 0.2022 | - | - | 424 B | +| | | | | | | | | | | | | | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,335.34 ns | 3.342 ns | 2.791 ns | 1,335.74 ns | ? | ? | 0.5646 | - | - | 1,184 B | +| | | | | | | | | | | | | | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,126.59 ns | 5.203 ns | 4.062 ns | 2,126.87 ns | ? | ? | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/ToListBenchmarks.md b/Benchmarks/ToListBenchmarks.md index 2938195f5..39f882f6c 100644 --- a/Benchmarks/ToListBenchmarks.md +++ b/Benchmarks/ToListBenchmarks.md @@ -4,7 +4,7 @@ [ToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 55.46 ns | 0.762 ns | 0.675 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Array | Array | 100 | 114.42 ns | 0.588 ns | 0.521 ns | 2.06 | 0.03 | 0.2180 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 46.29 ns | 0.394 ns | 0.329 ns | 0.84 | 0.01 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 879.10 ns | 3.996 ns | 3.337 ns | 1.00 | 0.00 | 0.5808 | - | - | 1216 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 950.25 ns | 7.034 ns | 6.235 ns | 1.08 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 535.21 ns | 1.916 ns | 1.698 ns | 0.61 | 0.00 | 0.2365 | - | - | 496 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 47.68 ns | 0.359 ns | 0.336 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 953.11 ns | 11.902 ns | 9.939 ns | 20.02 | 0.18 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 147.80 ns | 1.565 ns | 1.307 ns | 3.10 | 0.03 | 0.2370 | - | - | 496 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 49.68 ns | 0.454 ns | 0.402 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Value | List_Value | 100 | 252.02 ns | 0.966 ns | 0.904 ns | 5.07 | 0.04 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 613.03 ns | 3.689 ns | 3.270 ns | 12.34 | 0.15 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,375.78 ns | 10.666 ns | 9.455 ns | 1.00 | 0.00 | 0.5836 | - | - | 1224 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,694.93 ns | 8.596 ns | 7.620 ns | 0.71 | 0.00 | 0.5798 | - | - | 1216 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 658.08 ns | 3.375 ns | 2.992 ns | 1.00 | 0.00 | 0.5808 | - | - | 1216 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 696.58 ns | 3.669 ns | 3.064 ns | 1.06 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 807.41 ns | 4.501 ns | 4.210 ns | 1.23 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 47.90 ns | 0.709 ns | 0.592 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 743.68 ns | 3.335 ns | 2.956 ns | 15.53 | 0.18 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 492.61 ns | 1.405 ns | 1.245 ns | 10.29 | 0.14 | 0.2441 | - | - | 512 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 49.95 ns | 0.224 ns | 0.198 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Reference | List_Reference | 100 | 743.40 ns | 2.663 ns | 2.491 ns | 14.88 | 0.07 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 602.74 ns | 2.613 ns | 2.317 ns | 12.07 | 0.08 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,211.75 ns | 6.184 ns | 5.164 ns | 1.00 | 0.00 | 0.5836 | - | - | 1224 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,367.85 ns | 6.742 ns | 5.630 ns | 1.07 | 0.00 | 0.5989 | - | - | 1256 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 57.07 ns | 0.628 ns | 0.556 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Array | Array | 100 | 117.12 ns | 0.639 ns | 0.598 ns | 2.05 | 0.02 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 48.40 ns | 0.729 ns | 0.682 ns | 0.85 | 0.02 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 880.19 ns | 3.297 ns | 2.922 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 881.63 ns | 3.729 ns | 3.306 ns | 1.00 | 0.00 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 548.65 ns | 6.695 ns | 10.224 ns | 0.62 | 0.01 | 0.2365 | - | - | 496 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 51.04 ns | 0.384 ns | 0.340 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 883.85 ns | 5.757 ns | 4.807 ns | 17.33 | 0.15 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 149.37 ns | 0.969 ns | 0.809 ns | 2.93 | 0.02 | 0.2370 | - | - | 496 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 53.30 ns | 0.464 ns | 0.412 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Value | List_Value | 100 | 256.68 ns | 1.914 ns | 1.598 ns | 4.82 | 0.05 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 600.97 ns | 2.968 ns | 2.776 ns | 11.27 | 0.10 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,045.94 ns | 9.630 ns | 8.042 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,402.94 ns | 4.992 ns | 4.669 ns | 0.69 | 0.00 | 0.5798 | - | - | 1,216 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 880.06 ns | 4.079 ns | 3.616 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 910.87 ns | 3.254 ns | 2.885 ns | 1.04 | 0.00 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,019.00 ns | 3.928 ns | 3.674 ns | 1.16 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 50.64 ns | 0.554 ns | 0.519 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 886.92 ns | 6.848 ns | 5.719 ns | 17.50 | 0.17 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 748.21 ns | 9.986 ns | 8.339 ns | 14.76 | 0.23 | 0.2441 | - | - | 512 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 52.48 ns | 0.279 ns | 0.248 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Reference | List_Reference | 100 | 886.53 ns | 4.900 ns | 4.344 ns | 16.89 | 0.08 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 562.00 ns | 3.656 ns | 3.419 ns | 10.71 | 0.09 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,070.35 ns | 11.109 ns | 9.276 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,190.63 ns | 6.834 ns | 6.392 ns | 1.06 | 0.00 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/WhereBenchmarks.md b/Benchmarks/WhereBenchmarks.md index 1e93a8617..e63a126d7 100644 --- a/Benchmarks/WhereBenchmarks.md +++ b/Benchmarks/WhereBenchmarks.md @@ -4,7 +4,7 @@ [WhereBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 482.2 ns | 2.83 ns | 2.36 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 265.0 ns | 1.64 ns | 1.46 ns | 0.55 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 268.2 ns | 0.82 ns | 0.73 ns | 0.56 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 266.8 ns | 1.06 ns | 0.88 ns | 0.55 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 292.4 ns | 5.44 ns | 5.08 ns | 0.61 | - | - | - | - | +| Linq_Array | Array | 100 | 482.7 ns | 2.93 ns | 2.60 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 255.5 ns | 1.88 ns | 1.76 ns | 0.53 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 275.0 ns | 2.62 ns | 2.32 ns | 0.57 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 283.5 ns | 1.19 ns | 0.99 ns | 0.59 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 258.8 ns | 1.24 ns | 1.16 ns | 0.54 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,400.0 ns | 6.33 ns | 5.28 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,270.8 ns | 7.32 ns | 6.49 ns | 0.91 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 269.4 ns | 1.07 ns | 1.00 ns | 0.19 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,378.9 ns | 4.68 ns | 4.15 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,281.6 ns | 4.92 ns | 4.36 ns | 0.93 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 245.6 ns | 1.43 ns | 1.27 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,386.5 ns | 6.28 ns | 4.91 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,220.8 ns | 3.54 ns | 3.13 ns | 0.88 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 300.0 ns | 1.66 ns | 1.56 ns | 0.22 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,372.2 ns | 5.77 ns | 5.40 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,309.7 ns | 5.30 ns | 4.70 ns | 0.95 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 246.7 ns | 1.16 ns | 1.03 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,393.3 ns | 4.63 ns | 4.11 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 612.6 ns | 2.87 ns | 2.54 ns | 0.44 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 700.7 ns | 2.21 ns | 1.96 ns | 0.50 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 1,430.2 ns | 3.68 ns | 3.07 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 592.9 ns | 3.64 ns | 3.22 ns | 0.41 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 668.1 ns | 1.79 ns | 1.59 ns | 0.47 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,300.8 ns | 15.66 ns | 13.88 ns | 1.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,654.6 ns | 18.68 ns | 16.56 ns | 1.07 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,788.7 ns | 13.25 ns | 11.07 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,136.0 ns | 13.36 ns | 11.85 ns | 1.07 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 993.3 ns | 2.83 ns | 2.51 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 696.3 ns | 2.10 ns | 1.97 ns | 0.70 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 709.3 ns | 4.12 ns | 3.65 ns | 0.71 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,384.4 ns | 5.79 ns | 4.83 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,292.5 ns | 4.30 ns | 3.59 ns | 0.93 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,279.8 ns | 7.65 ns | 6.39 ns | 0.92 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 995.1 ns | 3.68 ns | 3.44 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 730.5 ns | 1.67 ns | 1.48 ns | 0.73 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 760.3 ns | 1.89 ns | 1.76 ns | 0.76 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,404.8 ns | 6.73 ns | 5.97 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,286.7 ns | 3.31 ns | 3.10 ns | 0.92 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,255.1 ns | 3.37 ns | 3.15 ns | 0.89 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 994.5 ns | 6.59 ns | 6.17 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 726.1 ns | 2.60 ns | 2.17 ns | 0.73 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 650.1 ns | 2.65 ns | 2.35 ns | 0.65 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 1,379.1 ns | 4.52 ns | 4.01 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,288.6 ns | 5.30 ns | 4.70 ns | 0.93 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 675.4 ns | 2.44 ns | 2.28 ns | 0.49 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,900.0 ns | 34.57 ns | 28.86 ns | 1.00 | 0.0458 | - | - | 104 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,680.1 ns | 52.87 ns | 41.27 ns | 0.96 | 0.0153 | - | - | 40 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,819.7 ns | 23.74 ns | 22.20 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,155.6 ns | 15.89 ns | 12.40 ns | 1.07 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereCountBenchmarks.md b/Benchmarks/WhereCountBenchmarks.md index 0f814ff5e..8e7d6af7f 100644 --- a/Benchmarks/WhereCountBenchmarks.md +++ b/Benchmarks/WhereCountBenchmarks.md @@ -4,7 +4,7 @@ [WhereCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 676.9 ns | 3.86 ns | 3.61 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | Array | 100 | 227.9 ns | 0.80 ns | 0.67 ns | 0.34 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 198.1 ns | 0.73 ns | 0.57 ns | 0.29 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 195.3 ns | 0.52 ns | 0.46 ns | 0.29 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 175.4 ns | 0.38 ns | 0.32 ns | 0.26 | - | - | - | - | +| Linq_Array | Array | 100 | 683.0 ns | 3.38 ns | 2.82 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 242.0 ns | 2.34 ns | 2.07 ns | 0.35 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 175.4 ns | 0.35 ns | 0.27 ns | 0.26 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 197.9 ns | 0.64 ns | 0.54 ns | 0.29 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 201.8 ns | 0.50 ns | 0.41 ns | 0.30 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,142.8 ns | 4.04 ns | 3.78 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,129.2 ns | 4.64 ns | 3.87 ns | 0.99 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 254.8 ns | 0.97 ns | 0.86 ns | 0.22 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,173.3 ns | 7.26 ns | 6.79 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,117.3 ns | 4.93 ns | 4.37 ns | 0.95 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 206.0 ns | 1.31 ns | 1.02 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,144.0 ns | 4.62 ns | 4.32 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,122.3 ns | 6.15 ns | 5.45 ns | 0.98 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 262.7 ns | 0.61 ns | 0.54 ns | 0.23 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,187.3 ns | 9.07 ns | 7.57 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,139.5 ns | 5.64 ns | 5.00 ns | 0.96 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 213.0 ns | 0.73 ns | 0.64 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,151.2 ns | 3.85 ns | 3.41 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Value | List_Value | 100 | 446.5 ns | 3.22 ns | 2.86 ns | 0.39 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 591.0 ns | 1.82 ns | 1.70 ns | 0.51 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 1,168.6 ns | 4.37 ns | 3.65 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 498.9 ns | 2.41 ns | 2.13 ns | 0.43 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 702.5 ns | 2.26 ns | 2.11 ns | 0.60 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,131.5 ns | 5.79 ns | 5.42 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,373.4 ns | 6.91 ns | 6.12 ns | 1.58 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,849.7 ns | 5.54 ns | 4.91 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,816.1 ns | 3.11 ns | 2.42 ns | 1.52 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 779.2 ns | 4.05 ns | 3.79 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 667.9 ns | 3.40 ns | 3.18 ns | 0.86 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 572.9 ns | 1.84 ns | 1.64 ns | 0.74 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,165.7 ns | 6.51 ns | 5.77 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,139.5 ns | 4.77 ns | 4.47 ns | 0.98 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 769.7 ns | 3.39 ns | 3.01 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 773.6 ns | 3.83 ns | 3.19 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 655.9 ns | 1.85 ns | 1.64 ns | 0.85 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 576.3 ns | 2.26 ns | 2.12 ns | 0.75 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,165.7 ns | 6.68 ns | 6.25 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,099.9 ns | 2.64 ns | 2.47 ns | 0.94 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 804.9 ns | 2.60 ns | 2.30 ns | 0.69 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 781.2 ns | 4.21 ns | 3.94 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Reference | List_Reference | 100 | 658.1 ns | 2.69 ns | 2.39 ns | 0.84 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 612.7 ns | 1.73 ns | 1.45 ns | 0.78 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 1,162.3 ns | 4.96 ns | 4.64 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,100.8 ns | 4.93 ns | 4.61 ns | 0.95 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 688.8 ns | 3.99 ns | 3.54 ns | 0.59 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,055.3 ns | 5.14 ns | 4.56 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,573.3 ns | 8.78 ns | 7.79 ns | 1.74 | 0.0191 | - | - | 40 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,849.7 ns | 4.99 ns | 4.42 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,148.6 ns | 7.67 ns | 6.80 ns | 1.70 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereFirstBenchmarks.md b/Benchmarks/WhereFirstBenchmarks.md index 4964c5a15..9efc1de34 100644 --- a/Benchmarks/WhereFirstBenchmarks.md +++ b/Benchmarks/WhereFirstBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.2.21155.3 [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-TQOBKL : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|----------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 650.6 ns | 5.75 ns | 4.49 ns | 651.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Array | Array | 100 | 198.5 ns | 3.99 ns | 6.55 ns | 195.7 ns | 0.31 | 0.01 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 808.7 ns | 12.89 ns | 11.43 ns | 807.9 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 230.4 ns | 3.54 ns | 2.76 ns | 230.0 ns | 0.28 | 0.01 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 833.0 ns | 16.62 ns | 39.18 ns | 819.0 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 265.0 ns | 5.19 ns | 13.85 ns | 258.3 ns | 0.32 | 0.02 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 870.0 ns | 21.85 ns | 63.03 ns | 847.6 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Value | List_Value | 100 | 645.5 ns | 12.66 ns | 17.75 ns | 639.0 ns | 0.71 | 0.06 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,989.3 ns | 36.09 ns | 32.00 ns | 1,973.8 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,029.3 ns | 60.12 ns | 59.04 ns | 3,007.0 ns | 1.52 | 0.04 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 836.0 ns | 23.27 ns | 66.38 ns | 825.5 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 877.0 ns | 17.50 ns | 41.25 ns | 858.1 ns | 1.06 | 0.08 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 858.2 ns | 27.33 ns | 78.85 ns | 829.2 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 891.4 ns | 22.61 ns | 66.67 ns | 877.6 ns | 1.05 | 0.12 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 782.1 ns | 15.12 ns | 13.40 ns | 775.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 782.2 ns | 15.48 ns | 31.26 ns | 780.2 ns | 1.00 | 0.05 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,057.0 ns | 41.10 ns | 103.12 ns | 2,010.2 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,424.3 ns | 53.95 ns | 50.47 ns | 3,427.0 ns | 1.60 | 0.09 | 0.0458 | - | - | 96 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 585.0 ns | 3.10 ns | 2.75 ns | 584.7 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Array | Array | 100 | 211.1 ns | 0.79 ns | 0.74 ns | 211.1 ns | 0.36 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 755.3 ns | 4.54 ns | 4.03 ns | 754.5 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 219.2 ns | 0.84 ns | 0.75 ns | 219.4 ns | 0.29 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 752.8 ns | 4.13 ns | 3.87 ns | 752.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 225.7 ns | 0.79 ns | 0.70 ns | 225.6 ns | 0.30 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 753.9 ns | 2.72 ns | 2.41 ns | 753.9 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Value | List_Value | 100 | 670.8 ns | 2.08 ns | 1.74 ns | 670.9 ns | 0.89 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,914.6 ns | 4.18 ns | 3.49 ns | 1,915.0 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,934.7 ns | 7.32 ns | 6.84 ns | 2,933.2 ns | 1.53 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 796.3 ns | 3.15 ns | 2.79 ns | 796.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 775.8 ns | 2.32 ns | 2.06 ns | 776.4 ns | 0.97 | 0.00 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 792.5 ns | 2.01 ns | 1.78 ns | 792.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 793.4 ns | 2.35 ns | 2.08 ns | 793.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 816.9 ns | 16.29 ns | 32.15 ns | 801.4 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 676.6 ns | 2.79 ns | 2.61 ns | 676.2 ns | 0.83 | 0.03 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,918.5 ns | 7.27 ns | 6.07 ns | 1,919.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,241.0 ns | 21.98 ns | 18.35 ns | 3,236.1 ns | 1.69 | 0.01 | 0.0458 | - | - | 96 B | diff --git a/Benchmarks/WhereSelectBenchmarks.md b/Benchmarks/WhereSelectBenchmarks.md index cee6e8fa8..baeab94a0 100644 --- a/Benchmarks/WhereSelectBenchmarks.md +++ b/Benchmarks/WhereSelectBenchmarks.md @@ -4,7 +4,7 @@ [WhereSelectBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 697.2 ns | 4.30 ns | 3.59 ns | 1.00 | 0.00 | 0.0496 | - | - | 104 B | -| StructLinq_Array | Array | 100 | 352.7 ns | 1.50 ns | 1.33 ns | 0.51 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 635.9 ns | 8.41 ns | 7.02 ns | 0.91 | 0.01 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 347.9 ns | 0.76 ns | 0.67 ns | 0.50 | 0.00 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 350.6 ns | 4.74 ns | 4.20 ns | 0.50 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,514.8 ns | 5.30 ns | 4.70 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,368.5 ns | 25.69 ns | 30.58 ns | 0.91 | 0.02 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 388.9 ns | 1.24 ns | 1.16 ns | 0.26 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,508.8 ns | 4.02 ns | 3.56 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,336.6 ns | 3.76 ns | 3.33 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 393.9 ns | 2.18 ns | 1.82 ns | 0.26 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,528.9 ns | 3.72 ns | 3.29 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Value | List_Value | 100 | 733.3 ns | 2.60 ns | 2.30 ns | 0.48 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 786.1 ns | 2.85 ns | 2.38 ns | 0.51 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,547.6 ns | 22.18 ns | 19.66 ns | 1.00 | 0.00 | 0.0839 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,511.1 ns | 25.67 ns | 22.76 ns | 1.17 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,222.2 ns | 2.52 ns | 2.23 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 912.5 ns | 2.92 ns | 2.44 ns | 0.75 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 843.7 ns | 4.50 ns | 3.76 ns | 0.69 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,200.7 ns | 5.00 ns | 4.44 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 871.8 ns | 2.53 ns | 2.12 ns | 0.73 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 937.9 ns | 3.48 ns | 2.90 ns | 0.78 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,257.7 ns | 3.14 ns | 2.78 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Reference | List_Reference | 100 | 900.6 ns | 2.82 ns | 2.50 ns | 0.72 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 840.8 ns | 7.53 ns | 6.29 ns | 0.67 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,301.6 ns | 14.40 ns | 12.77 ns | 1.00 | 0.00 | 0.0839 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,497.4 ns | 34.76 ns | 30.81 ns | 1.23 | 0.01 | 0.0153 | - | - | 40 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 699.0 ns | 8.31 ns | 7.37 ns | 1.00 | 0.00 | 0.0496 | - | - | 104 B | +| StructLinq_Array | Array | 100 | 354.4 ns | 1.18 ns | 1.05 ns | 0.51 | 0.01 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 376.4 ns | 2.92 ns | 2.58 ns | 0.54 | 0.01 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 370.5 ns | 2.20 ns | 1.95 ns | 0.53 | 0.01 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 389.2 ns | 1.10 ns | 0.97 ns | 0.56 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,565.5 ns | 5.14 ns | 4.02 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,397.1 ns | 7.10 ns | 6.29 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 360.3 ns | 0.96 ns | 0.75 ns | 0.23 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,606.3 ns | 24.27 ns | 18.95 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,331.4 ns | 7.65 ns | 6.78 ns | 0.83 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 388.9 ns | 7.71 ns | 14.85 ns | 0.24 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,587.1 ns | 28.89 ns | 22.56 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Value | List_Value | 100 | 805.4 ns | 3.80 ns | 2.97 ns | 0.51 | 0.01 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 777.0 ns | 11.53 ns | 14.15 ns | 0.49 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,871.2 ns | 62.58 ns | 55.47 ns | 1.00 | 0.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,789.1 ns | 51.25 ns | 47.94 ns | 1.19 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,565.6 ns | 6.76 ns | 5.99 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,345.7 ns | 17.99 ns | 25.80 ns | 0.86 | 0.02 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,301.5 ns | 25.08 ns | 31.72 ns | 0.83 | 0.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,561.5 ns | 5.99 ns | 5.31 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,395.4 ns | 4.25 ns | 3.98 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,278.9 ns | 5.40 ns | 5.05 ns | 0.82 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,556.2 ns | 15.73 ns | 12.28 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,327.4 ns | 5.37 ns | 4.48 ns | 0.85 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 783.5 ns | 3.26 ns | 3.05 ns | 0.50 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,026.8 ns | 100.49 ns | 181.20 ns | 1.00 | 0.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,829.7 ns | 16.69 ns | 14.80 ns | 1.13 | 0.05 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereSelectCountBenchmarks.md b/Benchmarks/WhereSelectCountBenchmarks.md index 4d6578c23..178275130 100644 --- a/Benchmarks/WhereSelectCountBenchmarks.md +++ b/Benchmarks/WhereSelectCountBenchmarks.md @@ -4,7 +4,7 @@ [WhereSelectCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 311.0 ns | 1.27 ns | 1.13 ns | 1.00 | 0.0496 | - | - | 104 B | -| Hyperlinq_Array | Array | 100 | 179.1 ns | 0.41 ns | 0.39 ns | 0.58 | - | - | - | - | +| Linq_Array | Array | 100 | 345.9 ns | 0.90 ns | 0.84 ns | 1.00 | 0.0496 | - | - | 104 B | +| Hyperlinq_Array | Array | 100 | 209.4 ns | 1.38 ns | 1.15 ns | 0.61 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,230.8 ns | 4.24 ns | 3.97 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 260.2 ns | 0.85 ns | 0.79 ns | 0.21 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,264.3 ns | 4.34 ns | 4.06 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 214.1 ns | 0.76 ns | 0.67 ns | 0.17 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,211.5 ns | 2.55 ns | 2.39 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 216.4 ns | 0.99 ns | 0.87 ns | 0.18 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,279.1 ns | 4.00 ns | 3.34 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 221.3 ns | 1.91 ns | 1.69 ns | 0.17 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,204.5 ns | 3.22 ns | 2.86 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Value | List_Value | 100 | 641.8 ns | 1.79 ns | 1.67 ns | 0.53 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 1,246.3 ns | 4.13 ns | 3.44 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Value | List_Value | 100 | 630.4 ns | 2.49 ns | 2.21 ns | 0.51 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,789.2 ns | 8.70 ns | 7.71 ns | 1.00 | 0.0839 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,353.5 ns | 4.98 ns | 4.66 ns | 0.58 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,311.0 ns | 22.90 ns | 21.42 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,826.6 ns | 7.29 ns | 6.47 ns | 0.53 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 825.5 ns | 5.57 ns | 5.21 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 555.2 ns | 6.33 ns | 5.29 ns | 0.67 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,274.2 ns | 5.65 ns | 5.00 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 775.7 ns | 3.07 ns | 2.88 ns | 0.61 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 811.7 ns | 1.99 ns | 1.76 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 591.8 ns | 2.44 ns | 2.04 ns | 0.73 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,261.5 ns | 4.05 ns | 3.59 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 799.5 ns | 3.15 ns | 2.79 ns | 0.63 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 828.4 ns | 3.43 ns | 3.21 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 716.2 ns | 3.67 ns | 3.06 ns | 0.86 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 1,265.8 ns | 2.83 ns | 2.36 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 649.8 ns | 2.98 ns | 2.49 ns | 0.51 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,741.1 ns | 34.42 ns | 28.74 ns | 1.00 | 0.0839 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,554.6 ns | 6.29 ns | 5.25 ns | 0.62 | 0.0191 | - | - | 40 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,174.8 ns | 38.53 ns | 30.08 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,162.1 ns | 9.40 ns | 8.80 ns | 0.61 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereSingleBenchmarks.md b/Benchmarks/WhereSingleBenchmarks.md index 93589eab3..a98ae37b5 100644 --- a/Benchmarks/WhereSingleBenchmarks.md +++ b/Benchmarks/WhereSingleBenchmarks.md @@ -4,7 +4,7 @@ [WhereSingleBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,51 +14,38 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 180.3 ns | 1.15 ns | 1.08 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 220.2 ns | 0.54 ns | 0.51 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 221.4 ns | 0.66 ns | 0.58 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 688.4 ns | 2.21 ns | 1.85 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,409.6 ns | 5.87 ns | 4.90 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 546.4 ns | 1.15 ns | 1.02 ns | ? | ? | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 521.9 ns | 1.43 ns | 1.34 ns | ? | ? | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 690.2 ns | 1.25 ns | 1.17 ns | ? | ? | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | NA | NA | NA | ? | ? | - | - | - | - | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,545.9 ns | 5.21 ns | 4.62 ns | ? | ? | 0.0496 | - | - | 104 B | - -Benchmarks with issues: - WhereSingleBenchmarks.Linq_Array: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Linq_Enumerable_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Linq_Collection_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Linq_List_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Linq_AsyncEnumerable_Value: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Linq_Enumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Linq_Collection_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Linq_List_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] - WhereSingleBenchmarks.Linq_AsyncEnumerable_Reference: .NET Core 5.0(Runtime=.NET Core 5.0) [Count=100] +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------- |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 599.1 ns | 3.34 ns | 2.97 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Array | Array | 100 | 187.4 ns | 0.61 ns | 0.54 ns | 0.31 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 803.8 ns | 3.14 ns | 2.78 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 225.4 ns | 0.87 ns | 0.77 ns | 0.28 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 770.7 ns | 4.53 ns | 4.02 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 226.8 ns | 0.82 ns | 0.72 ns | 0.29 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 770.0 ns | 3.13 ns | 2.77 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Value | List_Value | 100 | 699.6 ns | 1.56 ns | 1.38 ns | 0.91 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,910.7 ns | 4.99 ns | 4.67 ns | 1.00 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 770.5 ns | 4.03 ns | 3.37 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 779.4 ns | 3.55 ns | 3.15 ns | 1.01 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 821.6 ns | 3.66 ns | 3.25 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 752.5 ns | 3.27 ns | 3.06 ns | 0.92 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 801.4 ns | 3.33 ns | 3.12 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 635.3 ns | 1.86 ns | 1.56 ns | 0.79 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,938.1 ns | 6.93 ns | 6.14 ns | 1.00 | 0.0458 | - | - | 96 B | diff --git a/Benchmarks/WhereToArrayBenchmarks.md b/Benchmarks/WhereToArrayBenchmarks.md index 4a7daec43..07840b8c2 100644 --- a/Benchmarks/WhereToArrayBenchmarks.md +++ b/Benchmarks/WhereToArrayBenchmarks.md @@ -4,7 +4,7 @@ [WhereToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 422.3 ns | 1.36 ns | 1.20 ns | 1.00 | 0.3519 | - | - | 736 B | -| StructLinq_Array | Array | 100 | 382.9 ns | 1.39 ns | 1.30 ns | 0.91 | 0.1144 | - | - | 240 B | -| Hyperlinq_Array | Array | 100 | 493.0 ns | 3.14 ns | 2.78 ns | 1.17 | 0.1144 | - | - | 240 B | +| Linq_Array | Array | 100 | 427.1 ns | 1.44 ns | 1.20 ns | 1.00 | 0.3519 | - | - | 736 B | +| StructLinq_Array | Array | 100 | 403.1 ns | 1.33 ns | 1.11 ns | 0.94 | 0.1144 | - | - | 240 B | +| Hyperlinq_Array | Array | 100 | 508.5 ns | 2.19 ns | 1.94 ns | 1.19 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,224.2 ns | 8.59 ns | 7.17 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,209.0 ns | 2.97 ns | 2.32 ns | 0.99 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 539.5 ns | 2.89 ns | 2.71 ns | 0.44 | 0.1144 | - | - | 240 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,196.0 ns | 7.47 ns | 6.63 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,231.8 ns | 2.70 ns | 2.10 ns | 1.03 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 550.9 ns | 3.57 ns | 3.16 ns | 0.46 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,210.4 ns | 7.42 ns | 6.94 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,205.9 ns | 4.23 ns | 3.96 ns | 1.00 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 522.0 ns | 1.40 ns | 1.24 ns | 0.43 | 0.1144 | - | - | 240 B | +| Linq_Collection_Value | Collection_Value | 100 | 1,205.4 ns | 3.50 ns | 2.92 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,257.0 ns | 6.59 ns | 5.84 ns | 1.04 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 521.4 ns | 1.31 ns | 1.03 ns | 0.43 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,234.6 ns | 2.62 ns | 2.19 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Value | List_Value | 100 | 746.1 ns | 1.91 ns | 1.59 ns | 0.60 | 0.1144 | - | - | 240 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,187.8 ns | 2.97 ns | 2.48 ns | 0.96 | 0.1144 | - | - | 240 B | +| Linq_List_Value | List_Value | 100 | 1,208.0 ns | 3.79 ns | 3.36 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Value | List_Value | 100 | 806.1 ns | 3.44 ns | 3.05 ns | 0.67 | 0.1144 | - | - | 240 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,147.2 ns | 2.94 ns | 2.45 ns | 0.95 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,969.1 ns | 13.03 ns | 12.19 ns | 1.00 | 0.4578 | - | - | 960 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,744.0 ns | 6.22 ns | 5.82 ns | 0.63 | 0.3433 | - | - | 720 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,377.3 ns | 32.86 ns | 29.13 ns | 1.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,278.9 ns | 11.69 ns | 10.94 ns | 0.61 | 0.3433 | - | - | 720 B | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 799.8 ns | 7.74 ns | 6.86 ns | 1.00 | 0.3710 | - | - | 776 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 820.6 ns | 4.80 ns | 4.01 ns | 1.03 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 902.3 ns | 2.42 ns | 2.27 ns | 1.13 | 0.1297 | - | - | 272 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,241.1 ns | 5.44 ns | 4.82 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,250.7 ns | 4.35 ns | 3.85 ns | 1.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,347.2 ns | 5.68 ns | 4.74 ns | 1.09 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 824.0 ns | 10.71 ns | 10.02 ns | 1.00 | 0.3710 | - | - | 776 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 800.1 ns | 2.62 ns | 2.32 ns | 0.97 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 895.4 ns | 1.71 ns | 1.60 ns | 1.09 | 0.1297 | - | - | 272 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,233.7 ns | 3.62 ns | 3.21 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,240.4 ns | 3.89 ns | 3.25 ns | 1.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,373.4 ns | 2.59 ns | 2.16 ns | 1.11 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 786.8 ns | 3.06 ns | 2.56 ns | 1.00 | 0.3710 | - | - | 776 B | -| StructLinq_List_Reference | List_Reference | 100 | 803.5 ns | 2.77 ns | 2.16 ns | 1.02 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,148.8 ns | 2.14 ns | 2.01 ns | 1.46 | 0.1144 | - | - | 240 B | +| Linq_List_Reference | List_Reference | 100 | 1,267.2 ns | 6.20 ns | 5.50 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,245.2 ns | 3.72 ns | 3.29 ns | 0.98 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,184.4 ns | 2.50 ns | 1.95 ns | 0.94 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,849.0 ns | 16.69 ns | 15.61 ns | 1.00 | 0.4578 | - | - | 960 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,270.8 ns | 7.87 ns | 7.36 ns | 0.73 | 0.3586 | - | - | 760 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,438.5 ns | 40.03 ns | 37.45 ns | 1.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,029.0 ns | 9.78 ns | 9.15 ns | 0.74 | 0.3586 | - | - | 752 B | diff --git a/Benchmarks/WhereToListBenchmarks.md b/Benchmarks/WhereToListBenchmarks.md index 4e8e636c6..a7c6ec886 100644 --- a/Benchmarks/WhereToListBenchmarks.md +++ b/Benchmarks/WhereToListBenchmarks.md @@ -4,7 +4,7 @@ [WhereToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs) ### References: -- Linq: 5.0.3 +- Linq: 6.0.0-preview.2.21154.6 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET Core SDK=6.0.100-preview.1.21103.13 - [Host] : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT - .NET Core 5.0 : .NET Core 5.0.3 (CoreCLR 5.0.321.7212, CoreFX 5.0.321.7212), X64 RyuJIT +.NET SDK=6.0.100-preview.2.21155.3 + [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT + Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT -Job=.NET Core 5.0 Runtime=.NET Core 5.0 +Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 375.1 ns | 5.55 ns | 9.28 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | -| StructLinq_Array | Array | 100 | 410.1 ns | 1.43 ns | 1.27 ns | 1.09 | 0.03 | 0.1297 | - | - | 272 B | -| Hyperlinq_Array | Array | 100 | 456.5 ns | 2.38 ns | 1.99 ns | 1.22 | 0.03 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,153.2 ns | 11.58 ns | 10.83 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,253.5 ns | 4.78 ns | 4.47 ns | 1.09 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 498.4 ns | 1.37 ns | 1.14 ns | 0.43 | 0.00 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,149.2 ns | 3.76 ns | 3.33 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,246.2 ns | 4.17 ns | 3.69 ns | 1.08 | 0.00 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 534.1 ns | 1.21 ns | 1.14 ns | 0.46 | 0.00 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,146.6 ns | 2.95 ns | 2.76 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Value | List_Value | 100 | 784.8 ns | 1.36 ns | 1.27 ns | 0.68 | 0.00 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,191.6 ns | 3.49 ns | 3.10 ns | 1.04 | 0.00 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,752.4 ns | 10.63 ns | 9.95 ns | 1.00 | 0.00 | 0.3586 | - | - | 752 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,836.1 ns | 5.23 ns | 4.37 ns | 0.57 | 0.00 | 0.3586 | - | - | 752 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 765.5 ns | 8.02 ns | 7.11 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 823.5 ns | 3.46 ns | 3.24 ns | 1.08 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 882.2 ns | 2.51 ns | 2.35 ns | 1.15 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 752.3 ns | 4.44 ns | 4.16 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 824.1 ns | 2.11 ns | 1.76 ns | 1.09 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 899.8 ns | 6.27 ns | 5.56 ns | 1.20 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 859.6 ns | 3.99 ns | 3.74 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | -| StructLinq_List_Reference | List_Reference | 100 | 818.0 ns | 2.88 ns | 2.56 ns | 0.95 | 0.00 | 0.1450 | - | - | 304 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,178.0 ns | 2.29 ns | 2.03 ns | 1.37 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,754.1 ns | 27.70 ns | 25.91 ns | 1.00 | 0.00 | 0.3586 | - | - | 752 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,324.2 ns | 6.54 ns | 5.80 ns | 0.75 | 0.00 | 0.3738 | - | - | 792 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 360.4 ns | 0.78 ns | 0.65 ns | 1.00 | 0.3328 | - | - | 696 B | +| StructLinq_Array | Array | 100 | 413.7 ns | 2.24 ns | 1.99 ns | 1.15 | 0.1297 | - | - | 272 B | +| Hyperlinq_Array | Array | 100 | 506.2 ns | 4.85 ns | 4.05 ns | 1.40 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,223.5 ns | 4.30 ns | 3.59 ns | 1.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,261.3 ns | 6.69 ns | 6.25 ns | 1.03 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 521.5 ns | 3.36 ns | 3.14 ns | 0.43 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,232.6 ns | 11.34 ns | 9.47 ns | 1.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,253.2 ns | 2.26 ns | 1.89 ns | 1.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 532.1 ns | 3.83 ns | 3.59 ns | 0.43 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,227.6 ns | 3.87 ns | 3.23 ns | 1.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Value | List_Value | 100 | 812.6 ns | 5.19 ns | 4.05 ns | 0.66 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,228.8 ns | 8.43 ns | 7.89 ns | 1.00 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,264.3 ns | 14.12 ns | 13.21 ns | 1.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,278.2 ns | 9.48 ns | 8.40 ns | 0.62 | 0.3586 | - | - | 752 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,225.8 ns | 2.45 ns | 1.91 ns | 1.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,258.7 ns | 3.44 ns | 3.05 ns | 1.03 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,319.2 ns | 5.28 ns | 4.41 ns | 1.08 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,226.7 ns | 3.26 ns | 2.89 ns | 1.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,247.0 ns | 4.48 ns | 3.97 ns | 1.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,370.6 ns | 5.58 ns | 4.66 ns | 1.12 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,231.1 ns | 7.91 ns | 7.01 ns | 1.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,242.9 ns | 4.32 ns | 3.37 ns | 1.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,210.8 ns | 5.63 ns | 5.27 ns | 0.98 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,347.5 ns | 15.41 ns | 13.66 ns | 1.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,975.5 ns | 9.77 ns | 9.14 ns | 0.74 | 0.3738 | - | - | 784 B | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs index 55c11b1df..2f03107d3 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq.Benchmarks { [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] [CategoriesColumn] - public class WhereSingleBenchmarks: RandomBenchmarksBase + public class WhereSingleBenchmarks: SequentialBenchmarksBase { [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] @@ -85,13 +85,13 @@ public Option Hyperlinq_List_Value() .Where(item => item == Count - 1) .Single(); - [BenchmarkCategory("AsyncEnumerable_Value")] - [Benchmark] - public ValueTask> Hyperlinq_AsyncEnumerable_Value() - => asyncEnumerableValue - .AsAsyncValueEnumerable() - .Where((item, _) => new ValueTask(item == Count - 1)) - .SingleAsync(); + // [BenchmarkCategory("AsyncEnumerable_Value")] + // [Benchmark] + // public ValueTask> Hyperlinq_AsyncEnumerable_Value() + // => asyncEnumerableValue + // .AsAsyncValueEnumerable() + // .Where((item, _) => new ValueTask(item == Count - 1)) + // .SingleAsync(); [BenchmarkCategory("Enumerable_Reference")] [Benchmark] @@ -117,12 +117,12 @@ public Option Hyperlinq_List_Reference() .Where(item => item == Count - 1) .Single(); - [BenchmarkCategory("AsyncEnumerable_Reference")] - [Benchmark] - public ValueTask> Hyperlinq_AsyncEnumerable_Reference() - => asyncEnumerableReference - .AsAsyncValueEnumerable() - .Where((item, _) => new ValueTask(item == Count - 1)) - .SingleAsync(); + // [BenchmarkCategory("AsyncEnumerable_Reference")] + // [Benchmark] + // public ValueTask> Hyperlinq_AsyncEnumerable_Reference() + // => asyncEnumerableReference + // .AsAsyncValueEnumerable() + // .Where((item, _) => new ValueTask(item == Count - 1)) + // .SingleAsync(); } } From a86fad2d782c09390f556cc23c45b95bb81afd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Wed, 12 May 2021 21:56:48 +0100 Subject: [PATCH 28/61] Add ValueMemoryOwner (#355) --- .../Utils/MethodSymbolExtensions.cs | 11 +- .../Utils/TypeSymbolExtensions.cs | 1 + .../ToArray/LargeArrayBuilder.Tests.cs | 8 +- .../ToArray/ToArray.ReadOnlyList.Tests.cs | 12 +- .../ToArray/ToArray.ReadOnlySpan.Tests.cs | 12 +- .../ToArray/ToArray.ValueEnumerable.Tests.cs | 12 +- .../ToArray.ValueReadOnlyCollection.Tests.cs | 6 +- ...ToArrayAsync.AsyncValueEnumerable.Tests.cs | 12 +- .../Distinct/Distinct.ArraySegment.Tests.cs | 2 +- .../Distinct.AsyncValueEnumerable.Tests.cs | 2 +- .../Distinct/Distinct.ReadOnlyList.Tests.cs | 2 +- .../Distinct/Distinct.ReadOnlyMemory.Tests.cs | 2 +- .../Distinct/Distinct.ReadOnlySpan.Tests.cs | 2 +- .../Distinct.ValueEnumerable.Tests.cs | 2 +- .../ToArray/ToArray.ReadOnlySpan.cs | 119 +++++------------- .../ToArray/ToArray.ValueEnumerable.cs | 48 +++---- .../ToArray.ValueReadOnlyCollection.cs | 75 +++-------- .../ToArray/ToArray.ValueReadOnlyList.cs | 103 ++++----------- .../ToArrayAsync.AsyncValueEnumerable.cs | 36 +++--- .../Where/Where/Where.ArraySegment.cs | 4 +- .../Where/Where/Where.AsyncValueEnumerable.cs | 4 +- .../Where/Where/Where.ReadOnlyMemory.cs | 4 +- .../Where/Where/Where.ReadOnlySpan.cs | 4 +- .../Where/Where/Where.ValueEnumerable.cs | 4 +- .../Where/Where.ValueReadOnlyCollection.cs | 4 +- .../Where/Where/Where.ValueReadOnlyList.cs | 4 +- .../Where/WhereAt/WhereAt.ArraySegment.cs | 4 +- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 4 +- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 4 +- .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 4 +- .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 4 +- .../WhereAt.ValueReadOnlyCollection.cs | 4 +- .../WhereAt/WhereAt.ValueReadOnlyList.cs | 4 +- .../WhereSelect/WhereSelect.ArraySegment.cs | 4 +- .../WhereSelect.AsyncValueEnumerable.cs | 4 +- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 4 +- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 4 +- .../WhereSelect.ValueEnumerable.cs | 4 +- .../WhereSelect.ValueReadOnlyCollection.cs | 4 +- .../WhereSelect.ValueReadOnlyList.cs | 4 +- .../Generation/AsyncValueEnumerable/Repeat.cs | 6 +- .../Generation/ValueEnumerable/Range.cs | 4 +- .../Generation/ValueEnumerable/Repeat.cs | 8 +- .../Select/Select/Select.ArraySegment.cs | 4 +- .../Select/Select.AsyncValueEnumerable.cs | 4 +- .../Select/Select/Select.ReadOnlyMemory.cs | 4 +- .../Select/Select/Select.ReadOnlySpan.cs | 4 +- .../Select/Select/Select.ValueEnumerable.cs | 4 +- .../Select/Select.ValueReadOnlyCollection.cs | 4 +- .../Select/Select/Select.ValueReadOnlyList.cs | 4 +- .../Select/SelectAt/SelectAt.ArraySegment.cs | 4 +- .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 4 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 4 +- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 4 +- .../SelectAt/SelectAt.ValueEnumerable.cs | 4 +- .../SelectAt.ValueReadOnlyCollection.cs | 4 +- .../SelectAt/SelectAt.ValueReadOnlyList.cs | 4 +- .../Select/SelectVector/SelectVector.Range.cs | 4 +- .../SelectVector/SelectVector.ReadOnlySpan.cs | 4 +- .../Set/Distinct/Distinct.ArraySegment.cs | 8 +- .../Distinct/Distinct.AsyncValueEnumerable.cs | 4 +- .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 8 +- .../Set/Distinct/Distinct.ReadOnlySpan.cs | 8 +- .../Set/Distinct/Distinct.ValueEnumerable.cs | 4 +- .../Distinct/Distinct.ValueReadOnlyList.cs | 8 +- NetFabric.Hyperlinq/Set/Distinct/Set.cs | 4 +- .../Utils/ArrayBuilder/LargeArrayBuilder.cs | 16 +-- .../ToArrayBuilder.AsyncValueEnumerable.cs | 24 ++-- .../ToArrayBuilder.ReadOnlySpan.cs | 12 +- .../ToArrayBuilder.ValueEnumerable.cs | 24 ++-- .../ToArrayBuilder.ValueReadOnlyList.cs | 12 +- ...oArrayBuilderAsync.AsyncValueEnumerable.cs | 51 ++++---- .../Utils/ArrayPoolExtensions.cs | 50 +++++++- .../Utils/MemoryPoolExtensions.cs | 30 ----- NetFabric.Hyperlinq/Utils/Throw.cs | 22 ++-- 75 files changed, 388 insertions(+), 530 deletions(-) delete mode 100644 NetFabric.Hyperlinq/Utils/MemoryPoolExtensions.cs diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs index 8dec54151..8b92294ce 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs @@ -40,7 +40,7 @@ public static MethodInfo GetInfo(this IMethodSymbol method, CompilationContext c Name = method.Name, Parameters = method.Parameters .Skip(skip) - .Select(parameter => (parameter.Name, parameter.Type.ToDisplayString(), parameter.HasExplicitDefaultValue ? (parameter.ExplicitDefaultValue is null ? "default" : parameter.ExplicitDefaultValue.ToString()) : default)) + .Select(parameter => (parameter.Name, parameter.Type.ToDisplayString(), parameter.HasExplicitDefaultValue ? parameter.ExplicitDefaultValue is null ? "default" : ToDisplayString(parameter.ExplicitDefaultValue) : default)) .ToArray(), TypeParameters = method.ContainingType.TypeParameters.Concat(method.TypeParameters) @@ -53,6 +53,15 @@ public static MethodInfo GetInfo(this IMethodSymbol method, CompilationContext c { throw; } + + string ToDisplayString(object? obj) + => obj switch + { + null => "", + true => "true", + false => "false", + _ => obj.ToString() + }; } public static MethodInfo ApplyMappings(this MethodInfo method, ImmutableArray typeGenericsMapping) diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs index 21733e322..171729f9f 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs @@ -17,6 +17,7 @@ public static IEnumerable GetAllInterfaces(this ITypeSymbol ty yield return (INamedTypeSymbol)typeSymbol; #pragma warning disable IDE0007 // Use implicit type + // ReSharper disable once SuggestVarOrType_SimpleTypes ITypeSymbol? currentTypeSymbol = typeSymbol; #pragma warning restore IDE0007 // Use implicit type do diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs index 8897c7f7a..2b4739215 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs @@ -20,7 +20,7 @@ public void ToArray_Must_Succeed(int count) var expected = Enumerable .Range(0, count) .ToArray(); - using var builder = new LargeArrayBuilder(ArrayPool.Shared); + using var builder = new LargeArrayBuilder(ArrayPool.Shared, false); for (var index = 0; index < count; index++) builder.Add(expected[index]); @@ -39,16 +39,16 @@ public void ToArray_Must_Succeed(int count) public void ToArray_MemoryPool_Must_Succeed(int count) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var expected = Enumerable .Range(0, count) .ToArray(); - using var builder = new LargeArrayBuilder(ArrayPool.Shared); + using var builder = new LargeArrayBuilder(ArrayPool.Shared, false); for (var index = 0; index < count; index++) builder.Add(expected[index]); // Act - using var result = builder.ToArray(pool); + using var result = builder.ToArray(pool, false); // Assert _ = result.Memory.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs index f8db401e1..d0c43ab4c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs @@ -43,7 +43,7 @@ public void ToArray_Must_Succeed(int[] source, int skip, int take) public void ToArray_MemoryPool_Must_Succeed(int[] source, int skip, int take) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); var expected = source .Skip(skip) @@ -100,7 +100,7 @@ public void ToArray_Predicate_Must_Succeed(int[] source, int skip, int take, Fun public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func predicate) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); var expected = source .Skip(skip) @@ -159,7 +159,7 @@ public void ToArray_PredicateAt_Must_Succeed(int[] source, int skip, int take, F public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func predicate) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); var expected = source .Skip(skip) @@ -217,7 +217,7 @@ public void ToArray_Selector_Must_Succeed(int[] source, int skip, int take, Func public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); var expected = source .Skip(skip) @@ -275,7 +275,7 @@ public void ToArray_SelectorAt_Must_Succeed(int[] source, int skip, int take, Fu public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); var expected = source .Skip(skip) @@ -335,7 +335,7 @@ public void ToArray_Predicate_Selector_Must_Succeed(int[] source, int skip, int public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func predicate, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); var expected = source .Skip(skip) diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs index 4e5928502..6c6fbabc1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs @@ -17,7 +17,7 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source) { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var expected = source .ToArray(); @@ -66,7 +66,7 @@ public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func)source.AsSpan(); - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var expected = source .Where(predicate) .ToArray(); @@ -117,7 +117,7 @@ public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func)source.AsSpan(); - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var expected = source .Where(predicate) .ToArray(); @@ -167,7 +167,7 @@ public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, Func)source.AsSpan(); - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var expected = source .Select(selector) .ToArray(); @@ -217,7 +217,7 @@ public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func)source.AsSpan(); - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var expected = source .Select(selector) .ToArray(); @@ -269,7 +269,7 @@ public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Fun { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var expected = source .Where(predicate) .Select(selector) diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs index ba3dd60ed..ccb6f82cb 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs @@ -59,7 +59,7 @@ public void ToArray_With_ValidData_Collections_Must_Succeed(int[] source) public void ToArray_MemoryPool_Must_Succeed(int[] source) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); var expected = source @@ -107,7 +107,7 @@ public void ToArray_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); var expected = source @@ -157,7 +157,7 @@ public void ToArray_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); var expected = source @@ -207,7 +207,7 @@ public void ToArray_Selector_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); var expected = source @@ -257,7 +257,7 @@ public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); var expected = source @@ -309,7 +309,7 @@ public void ToArray_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, public void ToArray_Predicate_Selector_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsValueEnumerable(source); var expected = source diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs index 3768ec8e9..83e80e7a8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs @@ -59,7 +59,7 @@ public void ToArray_With_ValidData_Collections_Must_Succeed(int[] source) public void ToArray_MemoryPool_Must_Succeed(int[] source) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsValueReadOnlyCollection(source); var expected = source @@ -107,7 +107,7 @@ public void ToArray_Predicate_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsValueReadOnlyCollection(source); var expected = source @@ -157,7 +157,7 @@ public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsValueReadOnlyCollection(source); var expected = source diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs index 6013be4ce..dde125896 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs @@ -39,7 +39,7 @@ public async ValueTask ToArrayAsync_With_ValidData_Must_Succeed(int[] source) public async ValueTask ToArrayAsync_MemoryPool_Must_Succeed(int[] source) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = source @@ -89,7 +89,7 @@ public async ValueTask ToArrayAsync_Predicate_With_ValidData_Must_Succeed(int[] public async ValueTask ToArrayAsync_Predicate_MemoryPool_Must_Succeed(int[] source, Func predicate) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = source @@ -141,7 +141,7 @@ public async ValueTask ToArrayAsync_PredicateAt_With_ValidData_Must_Succeed(int[ public async ValueTask ToArrayAsync_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func predicate) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = source @@ -193,7 +193,7 @@ public async ValueTask ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] s public async ValueTask ToArrayAsync_Selector_MemoryPool_Must_Succeed(int[] source, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = source @@ -245,7 +245,7 @@ public async ValueTask ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[] public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = source @@ -300,7 +300,7 @@ public async ValueTask ToArrayAsync_Predicate_Selector_With_ValidData_Must_Succe public async ValueTask ToArrayAsync_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = source diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs index 64a448b3d..210557769 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs @@ -80,7 +80,7 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source, int skip, public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source, int skip, int take) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var (offset, count) = Utils.SkipTake(source.Length, skip, take); var wrapped = new ArraySegment(source, offset, count); var expected = wrapped diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs index fa566b562..25a111f94 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs @@ -60,7 +60,7 @@ public async ValueTask Distinct_ToArrayAsync_With_ValidData_Must_Succeed(int[] s public async ValueTask Distinct_ToArrayAsync_MemoryPool_With_ValidData_Must_Succeed(int[] source) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap.AsAsyncValueEnumerable(source); var expected = source .Distinct() diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs index ecd8f4315..5dfde9022 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs @@ -66,7 +66,7 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source, int skip, public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source, int skip, int take) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap.AsReadOnlyList(source); var expected = source .Skip(skip) diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs index aec1fa52f..9f280e6d5 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs @@ -59,7 +59,7 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = (ReadOnlyMemory)source.AsMemory(); var expected = source .Distinct() diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs index 69814c95b..e4c6457ad 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs @@ -65,7 +65,7 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source // Act using var result = wrapped.AsValueEnumerable() .Distinct() - .ToArray(MemoryPool.Shared); + .ToArray(ArrayPool.Shared); // Assert _ = result.Memory.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs index 226016257..5066776eb 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs @@ -58,7 +58,7 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source) { // Arrange - var pool = MemoryPool.Shared; + var pool = ArrayPool.Shared; var wrapped = Wrap.AsValueEnumerable(source); var expected = source .Distinct() diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index 60372b4c5..6a7b9a4aa 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -14,20 +14,11 @@ static TSource[] ToArray(this ReadOnlySpan source) [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool) + public static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose = default) { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, pool) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool) - { - var result = pool.RentSliced(source.Length); - Copy(source, result.Memory.Span); - return result; - } + var result = pool.RentSliced(source.Length, clearOnDispose); + Copy(source, result.Memory.Span); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -44,26 +35,17 @@ static TSource[] ToArray(this ReadOnlySpan source, static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool, TPredicate predicate) + static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, pool, predicate) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TPredicate predicate) - { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate); - return arrayBuilder.ToArray(pool); - } + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -81,26 +63,17 @@ static TSource[] ToArrayAt(this ReadOnlySpan sourc static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, false, predicate); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this ReadOnlySpan source, MemoryPool pool, TPredicate predicate) + static ValueMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, pool, predicate) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TPredicate predicate) - { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate); - return arrayBuilder.ToArray(pool); - } + using var arrayBuilder = ToArrayBuilderAt(source, pool, clearOnDispose, predicate); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -146,42 +119,24 @@ static TResult[] BuildArray(ReadOnlySpan source, TVectorSelector vector } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayVector(this ReadOnlySpan source, MemoryPool pool, TVectorSelector vectorSelector, TSelector selector) + static ValueMemoryOwner ToArrayVector(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct where TResult : struct { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, pool, vectorSelector, selector) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TVectorSelector vectorSelector, TSelector selector) - { - var result = pool.RentSliced(source.Length); - CopyVector(source, result.Memory.Span, vectorSelector, selector); - return result; - } + var result = pool.RentSliced(source.Length, clearOnDispose); + CopyVector(source, result.Memory.Span, vectorSelector, selector); + return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool, TSelector selector) + static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, pool, selector) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TSelector selector) - { - var result = pool.RentSliced(source.Length); - Copy(source, result.Memory.Span, selector); - return result; - } + var result = pool.RentSliced(source.Length, clearOnDispose); + Copy(source, result.Memory.Span, selector); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -205,21 +160,12 @@ static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this ReadOnlySpan source, MemoryPool pool, TSelector selector) + static ValueMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, pool, selector) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TSelector selector) - { - var result = pool.RentSliced(source.Length); - CopyAt(source, result.Memory.Span, selector); - return result; - } + var result = pool.RentSliced(source.Length, clearOnDispose); + CopyAt(source, result.Memory.Span, selector); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -238,27 +184,18 @@ static TResult[] ToArray(this ReadOnlyS static TResult[] BuildArray(ReadOnlySpan source, TPredicate predicate, TSelector selector) { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate, selector); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this ReadOnlySpan source, MemoryPool pool, TPredicate predicate, TSelector selector) + static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction { - return source switch - { - { Length: 0 } => pool.Rent(0), - _ => BuildArray(source, pool, predicate, selector) - }; - - static IMemoryOwner BuildArray(ReadOnlySpan source, MemoryPool pool, TPredicate predicate, TSelector selector) - { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector); - return arrayBuilder.ToArray(pool); - } + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate, selector); + return arrayBuilder.ToArray(pool, clearOnDispose); } } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index 776cdb82d..974a61bd1 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -26,18 +26,18 @@ static TSource[] BuildArrayFromCollection(ICollection collection) static TSource[] BuildArray(TEnumerable source) { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool) + public static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared); - return arrayBuilder.ToArray(pool); + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -49,18 +49,18 @@ internal static TSource[] ToArray where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TPredicate predicate) + internal static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate); - return arrayBuilder.ToArray(pool); + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -72,18 +72,18 @@ internal static TSource[] ToArrayAt where TPredicate : struct, IFunction { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, false, predicate); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static IMemoryOwner ToArrayAt(this TEnumerable source, MemoryPool pool, TPredicate predicate) + internal static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate); - return arrayBuilder.ToArray(pool); + using var arrayBuilder = ToArrayBuilderAt(source, pool, clearOnDispose, predicate); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -95,18 +95,18 @@ static TResult[] ToArray( where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, selector); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, selector); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TSelector selector) + static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, selector); - return arrayBuilder.ToArray(pool); + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, selector); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -117,18 +117,18 @@ static TResult[] ToArrayAt where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, selector); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, false, selector); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TEnumerable source, MemoryPool pool, TSelector selector) + static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, selector); - return arrayBuilder.ToArray(pool); + using var arrayBuilder = ToArrayBuilderAt(source, pool, clearOnDispose, selector); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -141,19 +141,19 @@ internal static TResult[] ToArray where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate, selector); return arrayBuilder.ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TPredicate predicate, TSelector selector) + internal static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction where TSelector : struct, IFunction { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector); - return arrayBuilder.ToArray(pool); + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate, selector); + return arrayBuilder.ToArray(pool, clearOnDispose); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index d9f09ef03..152c39639 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -36,22 +36,13 @@ static TSource[] BuildArray(TEnumerable source) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool) + public static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator { - return source switch - { - { Count: 0 } => pool.Rent(0), - _ => BuildArray(source, pool) - }; - - static IMemoryOwner BuildArray(TEnumerable source, MemoryPool pool) - { - var result = pool.RentSliced(source.Count); - Copy(source, result.Memory.Span); - return result; - } + var result = pool.RentSliced(source.Count, clearOnDispose); + Copy(source, result.Memory.Span); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -68,15 +59,11 @@ static TSource[] ToArray(this TEn }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TPredicate predicate) + static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction - => source switch - { - { Count: 0 } => pool.Rent(0), - _ => ValueEnumerableExtensions.ToArray(source, pool, predicate) - }; + => ValueEnumerableExtensions.ToArray(source, pool, clearOnDispose, predicate); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -92,15 +79,11 @@ static TSource[] ToArrayAt(this T }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TEnumerable source, MemoryPool pool, TPredicate predicate) + static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction - => source switch - { - { Count: 0 } => pool.Rent(0), - _ => ValueEnumerableExtensions.ToArrayAt(source, pool, predicate) - }; + => ValueEnumerableExtensions.ToArrayAt(source, pool, clearOnDispose, predicate); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -126,23 +109,14 @@ static TResult[] BuildArray(TEnumerable source, TSelector selector) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TEnumerable source, MemoryPool pool, TSelector selector) + static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - return source switch - { - { Count: 0 } => pool.Rent(0), - _ => BuildArray(source, pool, selector) - }; - - static IMemoryOwner BuildArray(TEnumerable source, MemoryPool pool, TSelector selector) - { - var result = pool.RentSliced(source.Count); - Copy(source, result.Memory.Span, selector); - return result; - } + var result = pool.RentSliced(source.Count, clearOnDispose); + Copy(source, result.Memory.Span, selector); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -170,23 +144,14 @@ static TResult[] BuildArray(TEnumerable source, TSelector selector) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TEnumerable source, MemoryPool pool, TSelector selector) + static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - return source switch - { - { Count: 0 } => pool.Rent(0), - _ => BuildArray(source, pool, selector) - }; - - static IMemoryOwner BuildArray(TEnumerable source, MemoryPool pool, TSelector selector) - { - var result = pool.RentSliced(source.Count); - CopyAt(source, result.Memory.Span, selector); - return result; - } + var result = pool.RentSliced(source.Count, clearOnDispose); + CopyAt(source, result.Memory.Span, selector); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -204,15 +169,11 @@ static TResult[] ToArray ToArray(this TEnumerable source, MemoryPool pool, TPredicate predicate, TSelector selector) + static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction where TSelector : struct, IFunction - => source switch - { - { Count: 0 } => pool.Rent(0), - _ => ValueEnumerableExtensions.ToArray(source, pool, predicate, selector) - }; + => ValueEnumerableExtensions.ToArray(source, pool, clearOnDispose, predicate, selector); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs index 91a344b74..2940afcb0 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs @@ -32,22 +32,12 @@ static TSource[] BuildArray(TList source, int offset, int count) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TList source, MemoryPool pool, int offset, int count) + static ValueMemoryOwner ToArray(this TList source, ArrayPool pool, bool clearOnDispose, int offset, int count) where TList : struct, IReadOnlyList { - return count switch - { - 0 => pool.Rent(0), - _ => BuildArray(source, offset, count, pool) - }; - - static IMemoryOwner BuildArray(TList source, int offset, int count, - MemoryPool pool) - { - var result = pool.RentSliced(count); - Copy(source, offset, result.Memory.Span, count); - return result; - } + var result = pool.RentSliced(count, clearOnDispose); + Copy(source, offset, result.Memory.Span, count); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -65,27 +55,18 @@ static TSource[] ToArray(this TList source, TPredica static TSource[] BuildArray(TList source, TPredicate predicate, int offset, int count) { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, offset, count); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate, offset, count); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TList source, MemoryPool pool, TPredicate predicate, int offset, int count) + static ValueMemoryOwner ToArray(this TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction { - return count switch - { - 0 => pool.Rent(0), - _ => BuildArray(source, pool, predicate, offset, count) - }; - - static IMemoryOwner BuildArray(TList source, MemoryPool pool, TPredicate predicate, int offset, int count) - { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, offset, count); - return arrayBuilder.ToArray(pool); - } + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate, offset, count); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -104,27 +85,18 @@ static TSource[] ToArrayAt(this TList source, TPredi static TSource[] BuildArray(TList source, TPredicate predicate, int offset, int count) { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate, offset, count); + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, false, predicate, offset, count); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TList source, MemoryPool pool, TPredicate predicate, int offset, int count) + static ValueMemoryOwner ToArrayAt(this TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction { - return count switch - { - 0 => pool.Rent(0), - _ => BuildArray(source, pool, predicate, offset, count) - }; - - static IMemoryOwner BuildArray(TList source, MemoryPool pool, TPredicate predicate, int offset, int count) - { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, predicate, offset, count); - return arrayBuilder.ToArray(pool); - } + using var arrayBuilder = ToArrayBuilderAt(source, pool, clearOnDispose, predicate, offset, count); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -150,22 +122,13 @@ static TResult[] BuildArray(TList source, TSelector selector, int offset, int co } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TList source, MemoryPool pool, TSelector selector, int offset, int count) + static ValueMemoryOwner ToArray(this TList source, ArrayPool pool, bool clearOnDispose, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction { - return count switch - { - 0 => pool.Rent(0), - _ => BuildArray(source, pool, selector, offset, count) - }; - - static IMemoryOwner BuildArray(TList source, MemoryPool pool, TSelector selector, int offset, int count) - { - var result = pool.RentSliced(count); - Copy(source, offset, result.Memory.Span, count, selector); - return result; - } + var result = pool.RentSliced(count, clearOnDispose); + Copy(source, offset, result.Memory.Span, count, selector); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -191,22 +154,13 @@ static TResult[] BuildArray(TList source, TSelector selector, int offset, int co } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TList source, MemoryPool pool, TSelector selector, int offset, int count) + static ValueMemoryOwner ToArrayAt(this TList source, ArrayPool pool, bool clearOnDispose, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction { - return count switch - { - 0 => pool.Rent(0), - _ => BuildArray(source, pool, selector, offset, count) - }; - - static IMemoryOwner BuildArray(TList source, MemoryPool pool, TSelector selector, int offset, int count) - { - var result = pool.RentSliced(count); - CopyAt(source, offset, result.Memory.Span, count, selector); - return result; - } + var result = pool.RentSliced(count, clearOnDispose); + CopyAt(source, offset, result.Memory.Span, count, selector); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -226,28 +180,19 @@ static TResult[] ToArray(this TL static TResult[] BuildArray(TList source, TPredicate predicate, TSelector selector, int offset, int count) { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector, offset, count); + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate, selector, offset, count); return arrayBuilder.ToArray(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArray(this TList source, MemoryPool pool, TPredicate predicate, TSelector selector, int offset, int count) + static ValueMemoryOwner ToArray(this TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TPredicate : struct, IFunction where TSelector : struct, IFunction { - return count switch - { - 0 => pool.Rent(0), - _ => BuildArray(source, pool, predicate, selector, offset, count) - }; - - static IMemoryOwner BuildArray(TList source, MemoryPool pool, TPredicate predicate, TSelector selector, int offset, int count) - { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, predicate, selector, offset, count); - return arrayBuilder.ToArray(pool); - } + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate, selector, offset, count); + return arrayBuilder.ToArray(pool, clearOnDispose); } } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs index 0f0c13a12..4f4840312 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs @@ -13,13 +13,13 @@ public static partial class AsyncValueEnumerableExtensions public static async ValueTask ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator - => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static async ValueTask> ToArrayAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken = default) + public static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator - => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAsync(pool, clearOnDispose, cancellationToken).ConfigureAwait(false)).ToArray(pool, clearOnDispose); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -28,14 +28,14 @@ static async ValueTask ToArrayAsync where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate) + static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, predicate).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAsync(pool, clearOnDispose, cancellationToken, predicate).ConfigureAwait(false)).ToArray(pool, clearOnDispose); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -44,14 +44,14 @@ static async ValueTask ToArrayAtAsync where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, false, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAtAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate) + static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction - => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, cancellationToken, predicate).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAtAsync(pool, clearOnDispose, cancellationToken, predicate).ConfigureAwait(false)).ToArray(pool, clearOnDispose); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -60,14 +60,14 @@ static async ValueTask ToArrayAsync where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, selector).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, selector).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TSelector selector) + static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, selector).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAsync(pool, clearOnDispose, cancellationToken, selector).ConfigureAwait(false)).ToArray(pool, clearOnDispose); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -76,14 +76,14 @@ static async ValueTask ToArrayAtAsync where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, cancellationToken, selector).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, false, cancellationToken, selector).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAtAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TSelector selector) + static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, cancellationToken, selector).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAtAsync(pool, clearOnDispose, cancellationToken, selector).ConfigureAwait(false)).ToArray(pool, clearOnDispose); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -93,14 +93,14 @@ static async ValueTask ToArrayAsync where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, predicate, selector).ConfigureAwait(false)).ToArray(); + => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, predicate, selector).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - static async ValueTask> ToArrayAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) + static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction - => (await source.ToArrayBuilderAsync(ArrayPool.Shared, cancellationToken, predicate, selector).ConfigureAwait(false)).ToArray(pool); + => (await source.ToArrayBuilderAsync(pool, clearOnDispose, cancellationToken, predicate, selector).ConfigureAwait(false)).ToArray(pool, clearOnDispose); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index 57c87b757..d4a1aaed8 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -201,8 +201,8 @@ public TSource[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => ((ReadOnlySpan)source.AsSpan()).ToArray(memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index 48f2e4473..b7b90705c 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -307,8 +307,8 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAsync(pool, cancellationToken, predicate); + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + => source.ToArrayAsync(pool, clearOnDispose, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index f13985846..5588a7dbb 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -194,8 +194,8 @@ public Option Single() public TSource[] ToArray() => source.Span.ToArray(predicate); - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.Span.ToArray(memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.Span.ToArray(pool, clearOnDispose, predicate); public List ToList() => source.Span.ToList(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index 9bb883d6d..8391b6c00 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -140,8 +140,8 @@ public Option Single() public TSource[] ToArray() => source.ToArray(predicate); - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, predicate); public List ToList() => source.ToList(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index 7a371fa27..9e5d8d967 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -113,8 +113,8 @@ public TSource[] ToArray() => source.ToArray(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index 58a1c4af3..36d31acc7 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -203,8 +203,8 @@ public TSource[] ToArray() => ValueReadOnlyCollectionExtensions.ToArray(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => ValueReadOnlyCollectionExtensions.ToArray(source, memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs index de634d7df..068b86eb5 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs @@ -255,8 +255,8 @@ public TSource[] ToArray() => source.ToArray(predicate, offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(memoryPool, predicate, offset, count); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, predicate, offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index 47eca0a51..444c345d0 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -197,8 +197,8 @@ public TSource[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index 4fbdf3a50..559126eff 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -300,8 +300,8 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAtAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAtAsync(pool, cancellationToken, predicate); + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + => source.ToArrayAtAsync(pool, clearOnDispose, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index 62a92c5cc..7e8966b5a 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -185,8 +185,8 @@ public Option Single() public TSource[] ToArray() => source.Span.ToArrayAt(predicate); - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.Span.ToArrayAt(memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.Span.ToArrayAt(pool, clearOnDispose, predicate); public List ToList() => source.Span.ToListAt(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index e92d93d57..0420632e2 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -129,8 +129,8 @@ public Option Single() public TSource[] ToArray() => source.ToArrayAt(predicate); - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArrayAt(memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArrayAt(pool, clearOnDispose, predicate); public List ToList() => source.ToListAt(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index cef6a201d..bdc940d7b 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -200,8 +200,8 @@ public TSource[] ToArray() => source.ToArrayAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArrayAt(memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArrayAt(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index 951b226e4..87488c274 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -199,8 +199,8 @@ public TSource[] ToArray() => ToArrayAt(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => ToArrayAt(source, memoryPool, predicate); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ToArrayAt(source, pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs index fe68887d4..349e01d09 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs @@ -248,8 +248,8 @@ public TSource[] ToArray() => source.ToArrayAt(predicate, offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArrayAt(memoryPool, predicate, offset, count); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArrayAt(pool, clearOnDispose, predicate, offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index 93b50dd7f..6be400e83 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -213,8 +213,8 @@ public TResult[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => ((ReadOnlySpan)source.AsSpan()).ToArray(memoryPool, predicate, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index 52b449141..d7a989050 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -334,8 +334,8 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAsync(cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAsync(pool, cancellationToken, predicate, selector); + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + => source.ToArrayAsync(pool, clearOnDispose, cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index 3a4375e94..5ab16fad2 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -217,8 +217,8 @@ public TResult[] ToArray() => source.Span.ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.Span.ToArray(memoryPool, predicate, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.Span.ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index bc5351e19..ad8ece9a3 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -93,8 +93,8 @@ public TResult[] ToArray() => source.ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool memoryPool) - => source.ToArray(memoryPool, predicate, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index 26cb5a182..03e4038f2 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -221,8 +221,8 @@ public TResult[] ToArray() => source.ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(pool, predicate, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index 69e770be4..57b4c6d6f 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -221,8 +221,8 @@ public TResult[] ToArray() => ValueReadOnlyCollectionExtensions.ToArray(source, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => ValueReadOnlyCollectionExtensions.ToArray(source, pool, predicate, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs index d5f342431..da005389b 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs @@ -257,8 +257,8 @@ public TResult[] ToArray() => source.ToArray(predicate, selector, offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(pool, predicate, selector, offset, count); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, predicate, selector, offset, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs index 9fc649a32..9fac293e5 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs @@ -177,9 +177,9 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d return new ValueTask(result: array); } - public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) { - var result = pool.RentSliced(count); + var result = pool.RentSliced(count, clearOnDispose); var array = result.Memory.Span; var end = count - 1; for (var index = 0; index <= end; index++) @@ -187,7 +187,7 @@ public ValueTask> ToArrayAsync(MemoryPool pool, C cancellationToken.ThrowIfCancellationRequested(); array[index] = value; } - return new ValueTask>(result: result); + return new ValueTask>(result: result); } public async ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs index 856d01c51..b89e34708 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs @@ -226,9 +226,9 @@ public int[] ToArray() return array; } - public IMemoryOwner ToArray(MemoryPool pool) + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentSliced(Count); + var result = pool.RentSliced(Count, clearOnDispose); ArrayExtensions.CopyRange(start, Count, result.Memory.Span); return result; } diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs index 98d8d2b1b..90af0e24f 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs @@ -179,9 +179,9 @@ public TSource[] ToArray() return array; } - public IMemoryOwner ToArray(MemoryPool pool) + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentSliced(Count); + var result = pool.RentSliced(Count, clearOnDispose); CopyTo(result.Memory.Span); return result; } @@ -232,10 +232,10 @@ public static TSource[] ToArrayVector(this RepeatEnumerable so return array; } - public static IMemoryOwner ToArrayVector(this RepeatEnumerable source, MemoryPool pool) + public static ValueMemoryOwner ToArrayVector(this RepeatEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TSource : struct { - var result = pool.RentSliced(source.count); + var result = pool.RentSliced(source.count, clearOnDispose); source.CopyToVector(result.Memory.Span); return result; } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 90818e728..40fb756ee 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -210,8 +210,8 @@ public TResult[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs index 97863d6d0..be3b3847e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -254,8 +254,8 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAsync(pool, cancellationToken, selector); + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + => source.ToArrayAsync(pool, cancellationToken, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index 08721d353..883dcbd48 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -204,8 +204,8 @@ public TResult[] ToArray() => source.Span.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.Span.ToArray(pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.Span.ToArray(pool, clearOnDispose, selector); public List ToList() => source.Span.ToList(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index 4ab310a89..f531d39f4 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -103,8 +103,8 @@ public TResult[] ToArray() => source.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, selector); public List ToList() => source.ToList(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index 7049b8d40..dfb4b54da 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -158,8 +158,8 @@ public TResult[] ToArray() => source.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, selector); public List ToList() => source.ToList(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index c00ad0465..46705f2f8 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -195,8 +195,8 @@ public TResult[] ToArray() => ValueReadOnlyCollectionExtensions.ToArray(source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => ValueReadOnlyCollectionExtensions.ToArray(source, pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs index 22f744baf..0711575b1 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -276,8 +276,8 @@ public TResult[] ToArray() => source.ToArray(selector, offset, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArray(pool, selector, offset, Count); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, selector, offset, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index fdf73b7ee..732fd4ea9 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -204,8 +204,8 @@ public TResult[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index 7bcf61c44..5ab12a46b 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -256,8 +256,8 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAtAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => source.ToArrayAtAsync(pool, cancellationToken, selector); + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + => source.ToArrayAtAsync(pool, cancellationToken, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 9bc93b1e3..d4e00b16d 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -198,8 +198,8 @@ public TResult[] ToArray() => source.Span.ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.Span.ToArrayAt(pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.Span.ToArrayAt(pool, clearOnDispose, selector); public List ToList() => source.Span.ToListAt(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index e26d28541..2304fa3bd 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -103,8 +103,8 @@ public TResult[] ToArray() => source.ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArrayAt(pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArrayAt(pool, clearOnDispose, selector); public List ToList() => source.ToListAt(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index 64bcd4454..aa6ec3931 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -168,8 +168,8 @@ public TResult[] ToArray() => source.ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArrayAt(pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArrayAt(pool, clearOnDispose, selector); public List ToList() => source.ToListAt(selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index 0e22d4ebc..72d595b69 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -204,8 +204,8 @@ public TResult[] ToArray() => ToArrayAt(source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => ToArrayAt(source, pool, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ToArrayAt(source, pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs index 60e82d14b..3c8d2c478 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -296,8 +296,8 @@ public TResult[] ToArray() => source.ToArrayAt(selector, offset, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArrayAt(pool, selector, offset, Count); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArrayAt(pool, clearOnDispose, selector, offset, Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs index d00c70a84..afcfec9e1 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs @@ -86,9 +86,9 @@ public TResult[] ToArray() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentSliced(count); + var result = pool.RentSliced(count, clearOnDispose); ArrayExtensions.CopyRange(start, count, result.Memory.Span, vectorSelector, selector); return result; } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs index ace8dec3b..c7ac45bd2 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs @@ -89,8 +89,8 @@ public TResult[] ToArray() => source.ToArrayVector(vectorSelector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(MemoryPool pool) - => source.ToArrayVector(pool, vectorSelector, selector); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArrayVector(pool, clearOnDispose, vectorSelector, selector); public List ToList() => source.ToListVector(vectorSelector, selector); diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs index 25c3724c7..b6fb0e3e6 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs @@ -110,12 +110,8 @@ public readonly TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly IMemoryOwner ToArray(MemoryPool pool) - => source switch - { - { Count: 0 } => pool.Rent(0), - _ => GetSet().ToArray(pool) - }; + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly List ToList() diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs index 018303936..ead4fb045 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs @@ -200,8 +200,8 @@ public readonly async ValueTask ToArrayAsync(CancellationToken cancel => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly async ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) - => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToArray(pool); + public readonly async ValueTask> ToArrayAsync(ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken = default) + => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly async ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs index 2a4ac1fa7..63810e374 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -113,12 +113,8 @@ public readonly TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly IMemoryOwner ToArray(MemoryPool pool) - => source switch - { - { Length: 0 } => pool.Rent(0), - _ => GetSet().ToArray(pool) - }; + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly List ToList() diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs index e40dbed74..4c7c42c09 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs @@ -97,12 +97,8 @@ public readonly TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly IMemoryOwner ToArray(MemoryPool pool) - => source.Length switch - { - 0 => pool.Rent(0), - _ => GetSet().ToArray(pool) - }; + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly List ToList() diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs index ecbc2ed9f..9c6a7c772 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs @@ -112,8 +112,8 @@ public readonly TSource[] ToArray() => GetSet().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly IMemoryOwner ToArray(MemoryPool pool) - => GetSet().ToArray(pool); + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly List ToList() diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs index 512667e7d..53a7d55e2 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs @@ -138,12 +138,8 @@ public readonly TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly IMemoryOwner ToArray(MemoryPool pool) - => count switch - { - 0 => pool.RentSliced(0), - _ => GetSet().ToArray(pool) - }; + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly List ToList() diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index 74e1393e0..83f50c7e1 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -170,9 +170,9 @@ public readonly TElement[] ToArray() return array; } - public readonly IMemoryOwner ToArray(MemoryPool pool) + public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) { - var result = pool.RentSliced(Count); + var result = pool.RentSliced(Count, clearOnDispose); CopyTo(result.Memory.Span); return result; } diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs index 7ab715f02..5e715adf3 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs @@ -30,12 +30,13 @@ struct LargeArrayBuilder T[] current; // Current buffer we're reading into. If _count <= ResizeLimit, this is _first. int index; // Index into the current buffer. int storedCount; // Number of items stored in buffers. + readonly bool clearOnDispose; /// /// Constructs a new builder. /// - public LargeArrayBuilder(ArrayPool pool) - : this(maxCapacity: int.MaxValue, pool: pool, arrayBuilderPool: ArrayPool.Shared) + public LargeArrayBuilder(ArrayPool pool, bool clearOnDispose) + : this(maxCapacity: int.MaxValue, pool: pool, arrayBuilderPool: ArrayPool.Shared, clearOnDispose) { } @@ -46,7 +47,7 @@ public LargeArrayBuilder(ArrayPool pool) /// /// Do not add more than items to this builder. /// - public LargeArrayBuilder(int maxCapacity, ArrayPool pool, ArrayPool arrayBuilderPool) + public LargeArrayBuilder(int maxCapacity, ArrayPool pool, ArrayPool arrayBuilderPool, bool clearOnDispose) { Debug.Assert(maxCapacity >= 0); @@ -56,6 +57,7 @@ public LargeArrayBuilder(int maxCapacity, ArrayPool pool, ArrayPool arra current = Array.Empty(); index = 0; storedCount = 0; + this.clearOnDispose = clearOnDispose; } /// @@ -148,9 +150,9 @@ public readonly T[] ToArray() return array; } - public readonly IMemoryOwner ToArray(MemoryPool pool) + public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) { - var result = pool.RentSliced(Count); + var result = pool.RentSliced(Count, clearOnDispose); if (Count is not 0) CopyTo(result.Memory.Span); return result; @@ -190,9 +192,9 @@ void AllocateBuffer() public readonly void Dispose() { - pool.Return(current); + pool.Return(current, clearOnDispose); foreach(var item in buffers.AsSpan()) - pool.Return(item); + pool.Return(item, clearOnDispose); buffers.Dispose(); } diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs index cf6290c33..77d3778ff 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs @@ -8,11 +8,11 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -29,12 +29,12 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TPredicate predicate) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -54,12 +54,12 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TPredicate predicate) + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -82,12 +82,12 @@ static async ValueTask> ToArrayBuilderAtAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TSelector selector) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -105,12 +105,12 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TSelector selector) + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -131,13 +131,13 @@ static async ValueTask> ToArrayBuilderAtAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction where TSelector : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs index ebf472a96..47c3cdc71 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs @@ -6,10 +6,10 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, TPredicate predicate) + static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TPredicate: struct, IFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); foreach (var item in source) { if (predicate.Invoke(item)) @@ -18,10 +18,10 @@ static LargeArrayBuilder ToArrayBuilder(ReadOnlySp return builder; } - static LargeArrayBuilder ToArrayBuilderAt(ReadOnlySpan source, ArrayPool arrayPool, TPredicate predicate) + static LargeArrayBuilder ToArrayBuilderAt(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TPredicate: struct, IFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); for (var index = 0; index < source.Length; index++) { var item = source[index]; @@ -31,11 +31,11 @@ static LargeArrayBuilder ToArrayBuilderAt(ReadOnly return builder; } - static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, TPredicate predicate, TSelector selector) + static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate: struct, IFunction where TSelector: struct, IFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); foreach (var item in source) { if (predicate.Invoke(item)) diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs index 24e54987b..8a92f1490 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs @@ -6,23 +6,23 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool) + static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) builder.Add(enumerator.Current); return builder; } - static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, TPredicate predicate) + static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { @@ -33,12 +33,12 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, TPredicate predicate) + static LargeArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); using var enumerator = source.GetEnumerator(); for (var index = 0; enumerator.MoveNext(); index++) { @@ -49,24 +49,24 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, TSelector selector) + static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) builder.Add(selector.Invoke(enumerator.Current)); return builder; } - static LargeArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, TSelector selector) + static LargeArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); using var enumerator = source.GetEnumerator(); checked { @@ -76,13 +76,13 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, TPredicate predicate, TSelector selector) + static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction where TSelector : struct, IFunction { - var builder = new LargeArrayBuilder(arrayPool); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs index 0e2d7863f..5ac08f295 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs @@ -6,11 +6,11 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyListExtensions { - static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, TPredicate predicate, int offset, int count) + static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate: struct, IFunction { - var builder = new LargeArrayBuilder(pool); + var builder = new LargeArrayBuilder(pool, clearOnDispose); var end = offset + count; for (var index = offset; index < end; index++) { @@ -21,11 +21,11 @@ static LargeArrayBuilder ToArrayBuilder(in return builder; } - static LargeArrayBuilder ToArrayBuilderAt(in TList source, ArrayPool pool, TPredicate predicate, int offset, int count) + static LargeArrayBuilder ToArrayBuilderAt(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate: struct, IFunction { - var builder = new LargeArrayBuilder(pool); + var builder = new LargeArrayBuilder(pool, clearOnDispose); var end = count; if (offset is 0) { @@ -48,12 +48,12 @@ static LargeArrayBuilder ToArrayBuilderAt(i return builder; } - static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, TPredicate predicate, TSelector selector, int offset, int count) + static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector: struct, IFunction where TPredicate: struct, IFunction { - var builder = new LargeArrayBuilder(pool); + var builder = new LargeArrayBuilder(pool, clearOnDispose); var end = offset + count; for (var index = offset; index < end; index++) { diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs index 2a24bd922..b8f153139 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs @@ -1,4 +1,5 @@ -using System.Buffers; +using System; +using System.Buffers; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -12,7 +13,7 @@ public static async ValueTask ToArrayBuilderAsync where TEnumerator : struct, IAsyncEnumerator { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(ArrayPool.Shared, false); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -29,11 +30,11 @@ public static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken = default) + public static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(pool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -47,7 +48,7 @@ public static async ValueTask> ToArrayBuilderAsync ToArrayBuilderAsync where TPredicate: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(ArrayPool.Shared, false); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -77,12 +78,12 @@ static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(pool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -99,7 +100,7 @@ static async ValueTask> ToArrayBuilderAsync ToArrayBuilderAtAsync where TPredicate: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(ArrayPool.Shared, false); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -132,12 +133,12 @@ static async ValueTask ToArrayBuilderAtAsync> ToArrayBuilderAtAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate) + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(pool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -157,7 +158,7 @@ static async ValueTask> ToArrayBuilderAtAsync ToArrayBuilderAsync where TSelector: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(ArrayPool.Shared, false); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -185,12 +186,12 @@ static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TSelector selector) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(pool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -205,7 +206,7 @@ static async ValueTask> ToArrayBuilderAsync ToArrayBuilderAtAsync where TSelector: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(ArrayPool.Shared, false); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -236,12 +237,12 @@ static async ValueTask ToArrayBuilderAtAsync> ToArrayBuilderAtAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TSelector selector) + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(pool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -259,7 +260,7 @@ static async ValueTask> ToArrayBuilderAtAsync ToArrayBuilderAsync where TSelector: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(ArrayPool.Shared, false); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -290,13 +291,13 @@ static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, MemoryPool pool, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction where TSelector: struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared); + var builder = new LargeArrayBuilder(pool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -313,7 +314,7 @@ static async ValueTask> ToArrayBuilderAsync RentSliced(this ArrayPool pool, int count) - => new(pool.Rent(count), 0, count); + public static ValueMemoryOwner RentMemory(this ArrayPool pool, int length, bool clearOnDispose) + => new(pool, length, sliced: false, clearOnDispose); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueMemoryOwner RentSliced(this ArrayPool pool, int length, bool clearOnDispose) + => new(pool, length, sliced: true, clearOnDispose); + } + + public struct ValueMemoryOwner + : IMemoryOwner + { + readonly ArrayPool pool; + T[]? array; + readonly int length; + readonly bool clearOnDispose; + + internal ValueMemoryOwner(ArrayPool pool, int length, bool sliced, bool clearOnDispose) + { + this.pool = pool; + array = pool.Rent(length); + this.length = sliced ? length : array.Length; + this.clearOnDispose = clearOnDispose; + } + + public Memory Memory + { + get + { + var array = this.array; + if (array is null) + Throw.ObjectDisposedException(nameof(ValueMemoryOwner)); + + return new Memory(array, 0, length); + } + } + + public void Dispose() + { + var array = this.array; + if (array is not null) + { + this.array = null; + pool.Return(array, clearOnDispose); + } + } } + } diff --git a/NetFabric.Hyperlinq/Utils/MemoryPoolExtensions.cs b/NetFabric.Hyperlinq/Utils/MemoryPoolExtensions.cs deleted file mode 100644 index 795a7c317..000000000 --- a/NetFabric.Hyperlinq/Utils/MemoryPoolExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Buffers; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - static class MemoryPoolExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IMemoryOwner RentSliced(this MemoryPool pool, int count) - // ReSharper disable once HeapView.ObjectAllocation.Evident - => new SlicedMemoryOwner(pool.Rent(count), count); - - sealed class SlicedMemoryOwner - : IMemoryOwner - { - readonly IMemoryOwner oversized; - readonly int count; - - public SlicedMemoryOwner(IMemoryOwner oversized, int count) - => (this.oversized, this.count) = (oversized, count); - - public Memory Memory - => oversized.Memory.Slice(0, count); - - public void Dispose() - => oversized.Dispose(); - } - } -} diff --git a/NetFabric.Hyperlinq/Utils/Throw.cs b/NetFabric.Hyperlinq/Utils/Throw.cs index ad0f7901d..5a1610859 100644 --- a/NetFabric.Hyperlinq/Utils/Throw.cs +++ b/NetFabric.Hyperlinq/Utils/Throw.cs @@ -7,35 +7,35 @@ namespace NetFabric.Hyperlinq static class Throw { [DoesNotReturn] - public static void ArgumentArraySegmentNullException(string paramName) + public static void ArgumentArraySegmentNullException(string? paramName) => throw new ArgumentException(Resource.ArraySegmentNull, paramName); [DoesNotReturn] - public static void ArgumentException(string message, string paramName) + public static void ArgumentException(string? message, string? paramName) => throw new ArgumentException(message, paramName); [DoesNotReturn] - public static void ArgumentNullException(string paramName) + public static void ArgumentNullException(string? paramName) => throw new ArgumentNullException(paramName); [DoesNotReturn] - public static T ArgumentNullException(string paramName) + public static T ArgumentNullException(string? paramName) => throw new ArgumentNullException(paramName); [DoesNotReturn] - public static ref readonly T ArgumentNullExceptionRef(string paramName) + public static ref readonly T ArgumentNullExceptionRef(string? paramName) => throw new ArgumentNullException(paramName); [DoesNotReturn] - public static void ArgumentOutOfRangeException(string paramName) + public static void ArgumentOutOfRangeException(string? paramName) => throw new ArgumentOutOfRangeException(paramName); [DoesNotReturn] - public static T ArgumentOutOfRangeException(string paramName) + public static T ArgumentOutOfRangeException(string? paramName) => throw new ArgumentOutOfRangeException(paramName); [DoesNotReturn] - public static ref readonly T ArgumentOutOfRangeExceptionRef(string paramName) + public static ref readonly T ArgumentOutOfRangeExceptionRef(string? paramName) => throw new ArgumentOutOfRangeException(paramName); [DoesNotReturn] @@ -75,7 +75,7 @@ public static void InvalidOperationException() => throw new InvalidOperationException(); [DoesNotReturn] - public static void InvalidOperationException(string message) + public static void InvalidOperationException(string? message) => throw new InvalidOperationException(message); [DoesNotReturn] @@ -89,5 +89,9 @@ public static void NotSupportedException() [DoesNotReturn] public static T NotSupportedException() => throw new NotSupportedException(); + + [DoesNotReturn] + public static void ObjectDisposedException(string? objectName) + => throw new ObjectDisposedException(objectName); } } From 028db600cc8aa6d13b587f2d78ed1b1291bebd5f Mon Sep 17 00:00:00 2001 From: reegeek <10356780+reegeek@users.noreply.github.com> Date: Wed, 12 May 2021 23:51:10 +0200 Subject: [PATCH 29/61] Update StructLinq to 0.26.0 (#354) --- .../NetFabric.Hyperlinq.Benchmarks.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index b079575ac..cee2d5647 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -20,7 +20,7 @@ - + From a8e30a5325e113ea8d9c8c8c1b11fee7aacf1df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Tue, 18 May 2021 08:17:08 +0100 Subject: [PATCH 30/61] Refactor handling of lists (#356) --- .../Benchmarks/SelectBenchmarks.cs | 29 +- .../Count/Count.ReadOnlyList.Tests.cs | 84 ---- .../Aggregation/Sum/Sum.ReadOnlyList.Tests.cs | 46 -- ...ValueEnumerable.ValueReadOnlyList.Tests.cs | 2 +- .../ElementAt/ElementAt.ReadOnlyList.Tests.cs | 409 --------------- .../Element/First/First.ReadOnlyList.Tests.cs | 336 ------------- .../Single/Single.ReadOnlyList.Tests.cs | 473 ------------------ .../Where/Where.ReadOnlyList.Tests.cs | 65 --- .../WhereAt/WhereAt.ReadOnlyList.Tests.cs | 63 --- .../WhereSelect.ReadOnlyList.Tests.cs | 65 --- .../Select/Select.ReadOnlyList.Tests.cs | 61 --- .../SelectAt/SelectAt.ReadOnlyList.Tests.cs | 57 --- .../Quantifier/All/All.ReadOnlyList.Tests.cs | 103 ---- .../Quantifier/Any/Any.ReadOnlyList.Tests.cs | 144 ------ .../Contains/Contains.ReadOnlyList.Tests.cs | 260 ---------- .../Distinct/Distinct.ReadOnlyList.Tests.cs | 142 ------ .../Utils/Wrappers/Wrap.AsValueList.cs | 4 +- .../Wrappers/Wrap.AsValueReadOnlyList.cs | 4 +- .../Count/Count.ValueReadOnlyList.cs | 58 --- .../Aggregation/Sum/Sum.ValueReadOnlyList.cs | 106 ---- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 14 +- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 14 +- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 3 + ...lueEnumerable'6.ValueReadOnlyCollection.cs | 14 +- .../AsValueEnumerable.ReadOnlyList.cs | 79 ++- .../AsValueEnumerable.ValueReadOnlyList.cs | 257 ---------- .../ElementAt/ElementAt.ValueReadOnlyList.cs | 98 ---- .../Element/First/First.ValueReadOnlyList.cs | 100 ---- .../Single/Single.ValueReadOnlyList.cs | 139 ----- .../Where/Where/Where.ValueReadOnlyList.cs | 352 ------------- .../WhereAt/WhereAt.ValueReadOnlyList.cs | 367 -------------- .../WhereSelect.ValueReadOnlyList.cs | 386 -------------- .../Skip/Skip.ValueReadOnlyList.cs | 14 + .../SkipTake.ValueReadOnlyCollection.cs | 54 +- .../SkipTake/SkipTake.ValueReadOnlyList.cs | 240 +++++++++ .../Take/Take.ValueReadOnlyList.cs | 14 + .../Select/Select/Select.ArraySegment.cs | 11 +- .../Select/Select/Select.ReadOnlyMemory.cs | 11 +- .../Select/Select.ValueReadOnlyCollection.cs | 14 +- .../Select/Select/Select.ValueReadOnlyList.cs | 379 -------------- .../Select/SelectAt/SelectAt.ArraySegment.cs | 8 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 8 +- .../SelectAt.ValueReadOnlyCollection.cs | 14 +- .../SelectAt/SelectAt.ValueReadOnlyList.cs | 399 --------------- .../SelectMany.ValueReadOnlyList.cs | 316 ------------ .../Quantifier/All/All.ValueReadOnlyList.cs | 87 ---- .../Quantifier/Any/Any.ValueReadOnlyList.cs | 99 ---- .../Contains/Contains.Enumerable.cs | 6 +- .../Contains/Contains.ValueEnumerable.cs | 3 +- .../Contains/Contains.ValueReadOnlyList.cs | 159 ------ .../Distinct/Distinct.ValueReadOnlyList.cs | 227 --------- NetFabric.Hyperlinq/Set/Distinct/Set.cs | 5 +- .../Utils/IndexOf/IndexOf.ReadOnlyList.cs | 1 - .../IndexOf/IndexOf.ValueReadOnlyList.cs | 3 - .../Utils/Utils.EqualityComparer.cs | 5 +- 55 files changed, 384 insertions(+), 6027 deletions(-) delete mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs index c1baf3655..2afd7aac4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs @@ -269,21 +269,7 @@ public int Hyperlinq_Collection_Value() [BenchmarkCategory("List_Value")] [Benchmark] - public int Hyperlinq_List_Value_For() - { - var source = listValue.AsValueEnumerable().Select(item => item); - var sum = 0; - for (var index = 0; index < source.Count; index++) - { - var item = source[index]; - sum += item; - } - return sum; - } - - [BenchmarkCategory("List_Value")] - [Benchmark] - public int Hyperlinq_List_Value_Foreach() + public int Hyperlinq_List_Value() { var sum = 0; foreach (var item in listValue.AsValueEnumerable().Select(item => item)) @@ -321,21 +307,10 @@ public int Hyperlinq_Collection_Reference() return sum; } - [BenchmarkCategory("List_Reference")] - [Benchmark] - public int Hyperlinq_List_Reference_For() - { - var source = listReference.AsValueEnumerable().Select(item => item); - var sum = 0; - for (var index = 0; index < source.Count; index++) - sum += source[index]; - return sum; - } - #pragma warning disable HLQ010 // Consider using a 'for' loop instead. [BenchmarkCategory("List_Reference")] [Benchmark] - public int Hyperlinq_List_Reference_Foreach() + public int Hyperlinq_List_Reference() { var sum = 0; foreach (var item in listReference.AsValueEnumerable().Select(item => item)) diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyList.Tests.cs deleted file mode 100644 index 2281b873c..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,84 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Count -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Count_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Count(); - - // Act - var result = wrapped.AsValueEnumerable() - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void Count_Predicate_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Count(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Count(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs deleted file mode 100644 index 7d00a03b9..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,46 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public void Sum_With_ValidData_Must_Succeed(double[] source) - { - // Arrange - var wrapped = Wrap.AsList(source); - var expected = source - .Sum(); - - // Act - var result = wrapped.AsValueEnumerable() - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) - { - // Arrange - var wrapped = Wrap.AsList(source); - var expected = source - .Sum(); - - // Act - var result = wrapped.AsValueEnumerable() - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected!.Value); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs index 4fc411329..aa5fb3631 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs @@ -22,7 +22,7 @@ public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) // Assert _ = result.Must() - .BeOfType, int>>() + .BeOfType, int>>() .BeEnumerableOf() .BeEqualTo(wrapped); } diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs deleted file mode 100644 index ac1be3df1..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,409 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.ElementAt -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_OutOfRange_Must_Return_None(int[] source) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .ElementAt(source.Length); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void ElementAt_With_ValidData_Must_Return_Some(int[] source) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - - for (var index = 0; index < source.Length; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(source[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_With_OutOfRange_Must_Return_None(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .ElementAt(takeCount); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_Predicate_With_OutOfRange_Must_Return_None(int[] source, int skipCount, int takeCount, Func predicate) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .ElementAt(takeCount); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_Predicate_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount, Func predicate) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_PredicateAt_With_OutOfRange_Must_Return_None(int[] source, int skipCount, int takeCount, Func predicate) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .ElementAt(takeCount); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_PredicateAt_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount, Func predicate) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_Selector_With_OutOfRange_Must_Return_None(int[] source, int skipCount, int takeCount, Func selector) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Select(selector) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Select(selector) - .ElementAt(takeCount); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_Selector_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount, Func selector) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Select(selector) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, int skipCount, int takeCount, Func selector) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Select(selector) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Select(selector) - .ElementAt(takeCount); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_SelectorAt_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount, Func selector) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Select(selector) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] source, int skipCount, int takeCount, Func predicate, Func selector) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - - // Act - var optionTooSmall = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .Select(selector) - .ElementAt(-1); - var optionTooLarge = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .Select(selector) - .ElementAt(takeCount); - - // Assert - _ = optionTooSmall.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - _ = optionTooLarge.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void ElementAt_Skip_Take_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, int skipCount, int takeCount, Func predicate, Func selector) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .Select(selector) - .ToList(); - - for (var index = 0; index < expected.Count; index++) - { - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Where(predicate) - .Select(selector) - .ElementAt(index); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected[index]), - () => throw new Exception()); - } - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs deleted file mode 100644 index 1edfe5679..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,336 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.First -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void First_With_Empty_Must_Return_None(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void First_With_ValidData_Must_Return_Some(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - public void First_SkipTake_With_Empty_Must_Return_None(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void First_SkipTake_With_ValidData_Must_Return_Some(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - public void First_Predicate_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .First(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - public void First_PredicateAt_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = wrapped - .Skip(skip) - .Take(take) - .Where(predicate) - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - public void First_Selector_With_Empty_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void First_Selector_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtEmpty), MemberType = typeof(TestData))] - public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .First(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .First(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs deleted file mode 100644 index 075660b4d..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,473 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Element.Single -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - public void Single_With_Empty_Must_Return_None(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - public void Single_With_Single_Must_Return_Some(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Single_With_Multiple_Must_Return_None(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - public void Single_SkipTake_With_Empty_Must_Return_None(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - public void Single_SkipTake_With_Single_Must_Return_Some(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Single_SkipTake_With_Multiple_Must_Return_None(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - public void Single_Predicate_With_Single_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Single(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void Single_PredicateAt_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - public void Single_Selector_With_Empty_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - public void Single_Selector_With_Single_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void Single_Selector_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtEmpty), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Empty_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtSingle), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorAtMultiple), MemberType = typeof(TestData))] - public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Empty_Must_Return_None(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .Single(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void Single_Predicate_Selector_With_Multiple_Must_Return_None(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector) - .Single(); - - // Assert - _ = result.Must() - .BeOfType>() - .EvaluateTrue(option => option.IsNone); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyList.Tests.cs deleted file mode 100644 index d151cd185..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,65 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.Where -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void Where_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate); - - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void Where_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Sum(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Sum(); - - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyList.Tests.cs deleted file mode 100644 index cf5603d14..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,63 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereAt -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void Where_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void Where_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Sum(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyList.Tests.cs deleted file mode 100644 index 595c687a7..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,65 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Filtering.WhereSelect -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSelectorMultiple), MemberType = typeof(TestData))] - public void WhereSelect_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate, Func selector) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(selector); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void WhereSelect_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(item => item) - .Sum(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Where(predicate) - .Select(item => item) - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyList.Tests.cs deleted file mode 100644 index bb420e89a..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,61 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.Select -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.SkipTakeSelectorEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSelectorMultiple), MemberType = typeof(TestData))] - public void Select_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func selector) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Select(selector); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(selector); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Select_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Select(item => item) - .Sum(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select(item => item) - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyList.Tests.cs deleted file mode 100644 index 5c0b31a75..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,57 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectAt -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Select(selector); - - // Act - var result = wrapped.AsValueEnumerable() - .Select(selector); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Select_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Select((item, _) => item) - .Sum(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Select((item, _) => item) - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlyList.Tests.cs deleted file mode 100644 index b42b71781..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,103 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.All -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void All_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = source - .All(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void All_Skip_Take_Predicate_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .All(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void All_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = source - .Where(predicate).Count() == source.Length; - - // Act - var result = wrapped.AsValueEnumerable() - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void All_Skip_Take_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var count = source - .Skip(skip) - .Take(take) - .Count(); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Count() == count; - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .All(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlyList.Tests.cs deleted file mode 100644 index 361c00493..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,144 +0,0 @@ -using NetFabric.Assertive; -using System; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Any -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Any_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = source - .Any(); - - // Act - var result = wrapped.AsValueEnumerable() - .Any(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Any_Skip_Take_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Any(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Any(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public void Any_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = source - .Any(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateMultiple), MemberType = typeof(TestData))] - public void Any_Skip_Take_Predicate_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Any(predicate); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public void Any_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = source - .Where(predicate) - .Any(); - - // Act - var result = wrapped.AsValueEnumerable() - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakePredicateAtEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakePredicateAtMultiple), MemberType = typeof(TestData))] - public void Any_Skip_Take_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func predicate) - { - // Arrange - var wrapped = Wrap.AsValueReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Where(predicate) - .Any(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Any(predicate); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs deleted file mode 100644 index 7ad5facb1..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,260 +0,0 @@ -using NetFabric.Assertive; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Quantifier.Contains -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - const int value = int.MaxValue; - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - const string? value = default; - var wrapped = Wrap.AsValueReadOnlyList(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); - - // Act - var result = wrapped.AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = source - .Last(); - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = source - .Last() - .ToString(); - var wrapped = Wrap.AsValueReadOnlyList(source.AsValueEnumerable().Select(item => item.ToString()).ToArray()); - - // Act - var result = wrapped.AsValueEnumerable() - .Contains(value); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) - { - // Arrange - const int value = int.MaxValue; - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) - { - // Arrange - var value = source - .Last(); - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeTrue(); - } - - //////////////////// - // Skip Take - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_Skip_Take_With_Null_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) - { - // Arrange - const int value = int.MaxValue; - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Contains(value, null); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_Skip_Take_With_Null_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) - { - // Arrange - var value = source - .Skip(skip) - .Take(take) - .Last(); - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Contains(value, null); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_Skip_Take_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) - { - // Arrange - const int value = int.MaxValue; - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_Skip_Take_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) - { - // Arrange - var value = source - .Skip(skip) - .Take(take) - .Last(); - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Contains(value, EqualityComparer.Default); - - // Assert - _ = result.Must() - .BeTrue(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_Skip_Take_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source, int skip, int take) - { - // Arrange - const int value = int.MaxValue; - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Contains(value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeFalse(); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Contains_Skip_Take_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, int skip, int take) - { - // Arrange - var value = source - .Skip(skip) - .Take(take) - .Last(); - var wrapped = Wrap.AsValueReadOnlyList(source); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Contains(value, TestComparer.Instance); - - // Assert - _ = result.Must() - .BeTrue(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs deleted file mode 100644 index 5dfde9022..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,142 +0,0 @@ -using NetFabric.Assertive; -using System.Buffers; -using System.Linq; -using Xunit; - -namespace NetFabric.Hyperlinq.UnitTests.Set.Distinct -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Distinct_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Distinct(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Distinct(); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Distinct() - .ToArray(); - - // Act - var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Distinct() - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var pool = ArrayPool.Shared; - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Distinct() - .ToArray(); - - // Act - using var result = wrapped.AsValueEnumerable() - .Skip(skip) - .Take(take) - .Distinct() - .ToArray(pool); - - // Assert - _ = result - .SequenceEqual(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Distinct() - .ToList(); - - // Act - var result = wrapped - .Skip(skip) - .Take(take) - .Distinct() - .ToList(); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void Distinct_Sum_With_ValidData_Must_Succeed(int[] source, int skip, int take) - { - // Arrange - var wrapped = Wrap.AsReadOnlyList(source); - var expected = source - .Skip(skip) - .Take(take) - .Distinct() - .Sum(); - - // Act - var result = wrapped - .Skip(skip) - .Take(take) - .Distinct() - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs index 945035dca..af4e509cd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs @@ -68,8 +68,8 @@ void IList.RemoveAt(int index) => throw new NotSupportedException(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() - => ValueReadOnlyListExtensions.AsValueEnumerable, T>(this); + public ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() + => this.AsValueEnumerable, T>(); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs index 5cc5061d2..c525dc088 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs @@ -38,8 +38,8 @@ readonly IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() - => ValueReadOnlyListExtensions.AsValueEnumerable, T>(this); + public ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() + => this.AsValueEnumerable, T>(); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyList.cs deleted file mode 100644 index 9f99339b2..000000000 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyList.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static int Count(this TList source) - where TList : struct, IReadOnlyList - => source.Count(0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static int Count(this TList source, int offset, int count) - where TList : struct, IReadOnlyList - => count; - - static int Count(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - var counter = 0; - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - counter += predicate.Invoke(item).AsByte(); - } - return counter; - } - - static int CountAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate: struct, IFunction - { - var counter = 0; - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var item = source[index]; - counter += predicate.Invoke(item, index).AsByte(); - } - } - else - { - for (var index = 0; index < count; index++) - { - var item = source[index + offset]; - counter += predicate.Invoke(item, index).AsByte(); - } - } - return counter; - } - } -} - diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyList.cs deleted file mode 100644 index 8baa08230..000000000 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyList.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - public static TSum Sum(this TList source) - where TList : struct, IReadOnlyList - where TSum : struct - => source.Sum(0, source.Count); - - internal static TSum Sum(this TList source, int offset, int count) - where TList : struct, IReadOnlyList - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - sum = GenericsOperator.AddNullable(item, sum); - } - return sum; - } - - static TSum Sum(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - sum = GenericsOperator.AddNullable(item, sum); - } - return sum; - } - - static TSum SumAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item, index)) - sum = GenericsOperator.AddNullable(item, sum); - } - return sum; - } - - static TSum Sum(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - sum = GenericsOperator.AddNullable(selector.Invoke(item), sum); - } - return sum; - } - - static TSum SumAt(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - sum = GenericsOperator.AddNullable(selector.Invoke(item, index), sum); - } - return sum; - } - - static TSum Sum(this TList source, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - where TSum : struct - { - var sum = default(TSum); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - sum = GenericsOperator.AddNullable(selector.Invoke(item), sum); - } - return sum; - } - } -} - diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index a54ae40f7..e5a315368 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -42,17 +42,17 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { + if (Count is 0) + return; + if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - if (source.Count is not 0) + using var enumerator = GetEnumerator(); + checked { - using var enumerator = GetEnumerator(); - checked - { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; - } + for (var index = 0; enumerator.MoveNext(); index++) + span[index] = enumerator.Current; } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index 558866993..af5cc0269 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -47,17 +47,17 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { + if (Count is 0) + return; + if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - if (source.Count is not 0) + using var enumerator = GetEnumerator(); + checked { - using var enumerator = GetEnumerator(); - checked - { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; - } + for (var index = 0; enumerator.MoveNext(); index++) + span[index] = enumerator.Current; } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index 64525fc93..fdb935fd6 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -79,6 +79,9 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { + if (Count is 0) + return; + if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index 051a0300c..d61b4fee3 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -82,17 +82,17 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { + if (Count is 0) + return; + if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - if (source.Count is not 0) + using var enumerator = getEnumerator.Invoke(source); + checked { - using var enumerator = getEnumerator.Invoke(source); - checked - { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; - } + for (var index = 0; enumerator.MoveNext(); index++) + span[index] = enumerator.Current; } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs index 0f035d344..448817a06 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs @@ -18,7 +18,7 @@ public static ValueEnumerable, TSource> AsValueEnumerable [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueEnumerable AsValueEnumerable(this TList source) where TList : IReadOnlyList - => new(source, 0, source.Count); + => new(source); [StructLayout(LayoutKind.Auto)] public readonly partial struct ValueEnumerable @@ -27,23 +27,15 @@ public readonly partial struct ValueEnumerable where TList : IReadOnlyList { internal readonly TList source; - internal readonly int offset; - internal ValueEnumerable(TList source, int offset, int count) - => (this.source, this.offset, Count) = (source, offset, count); + internal ValueEnumerable(TList source) + => this.source = source; - public readonly int Count { get; } + public readonly int Count + => source.Count; - public readonly TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); - - return source[index + offset]; - } - } + public readonly TSource this[int index] + => source[index]; TSource IReadOnlyList.this[int index] => this[index]; @@ -78,22 +70,14 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - if (Count is 0) return; + + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - if (offset is 0) - { - for (var index = 0; index < Count && index < span.Length; index++) - span[index] = source[index]; - } - else - { - for (var index = 0; index < Count && index < span.Length; index++) - span[index] = source[index + offset]; - } + for (var index = 0; index < Count && index < span.Length; index++) + span[index] = source[index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -105,7 +89,7 @@ public bool Contains(TSource item) => Count is not 0 && source.Contains(item); public int IndexOf(TSource item) - => ReadOnlyListExtensions.IndexOf(source, item, offset, Count); + => ReadOnlyListExtensions.IndexOf(source, item, 0, Count); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -137,7 +121,7 @@ public struct Enumerator internal Enumerator(in ValueEnumerable enumerable) { source = enumerable.source; - index = enumerable.offset - 1; + index = -1; end = index + enumerable.Count; } @@ -163,7 +147,7 @@ public struct DisposableEnumerator internal DisposableEnumerator(in ValueEnumerable enumerable) { source = enumerable.source; - index = enumerable.offset - 1; + index = -1; end = index + enumerable.Count; } @@ -201,15 +185,12 @@ ValueEnumerable AsEnumerable() #region Partitioning [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable Skip(int count) - { - var (skipCount, takeCount) = Utils.Skip(Count, count); - return new ValueEnumerable(source, offset + skipCount, takeCount); - } - + public ValueReadOnlyListExtensions.SkipTakeEnumerable, TSource> Skip(int count) + => ValueReadOnlyListExtensions.Skip, TSource>(this, count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable Take(int count) - => new(source, offset, Utils.Take(Count, count)); + public ValueReadOnlyListExtensions.SkipTakeEnumerable, TSource> Take(int count) + => ValueReadOnlyListExtensions.Take, TSource>(this, count); #endregion } @@ -222,51 +203,51 @@ public static int Count(this in ValueEnumerable [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, int, int>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, int, int>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, int?, int>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, int?, int>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, long, long>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, long, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, long?, long>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, long?, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, float, int>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, float, int>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, float?, float>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, float?, float>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, double, double>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, double, double>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, double?, double>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, double?, double>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, decimal, decimal>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, decimal, decimal>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) where TList : IReadOnlyList - => source.Sum, decimal?, decimal>(); + => source.Sum, ValueEnumerable.DisposableEnumerator, decimal?, decimal>(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs deleted file mode 100644 index b866f7e33..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.cs +++ /dev/null @@ -1,257 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TList source) - where TList : struct, IReadOnlyList - => new(source, 0, source.Count); - - [GeneratorBindings(source: "source", sourceImplements: "IReadOnlyList`1", extraParameters: "offset, Count")] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueReadOnlyList.DisposableEnumerator> - , IList - where TList : struct, IReadOnlyList - { - internal readonly TList source; - internal readonly int offset; - - internal ValueEnumerable(TList source, int offset, int count) - => (this.source, this.offset, Count) = (source, offset, count); - - public readonly int Count { get; } - - public readonly TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if (index < 0 || index >= Count) - Throw.IndexOutOfRangeException(); - - return source[index + offset]; - } - } - - TSource IReadOnlyList.this[int index] - => this[index]; - - TSource IList.this[int index] - { - get => this[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() - => new(in this); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - Copy(this, 0, span, Count); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => Count is not 0 && ValueReadOnlyListExtensions.Contains(source, item); - - public int IndexOf(TSource item) - => ValueReadOnlyListExtensions.IndexOf(source, item, offset, Count); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - { - readonly TList source; - readonly int end; - int index; - - internal Enumerator(in ValueEnumerable enumerable) - { - source = enumerable.source; - index = enumerable.offset - 1; - end = index + enumerable.Count; - } - - public TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - } - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly TList source; - readonly int end; - int index; - - internal DisposableEnumerator(in ValueEnumerable enumerable) - { - source = enumerable.source; - index = enumerable.offset - 1; - end = index + enumerable.Count; - } - - public TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - TSource IEnumerator.Current - => source[index]; - object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source[index]; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public readonly void Dispose() { } - } - - #region Conversion - - ValueEnumerable AsValueEnumerable() - => this; - - ValueEnumerable AsEnumerable() - => this; - - #endregion - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable Skip(int count) - { - var (skipCount, takeCount) = Utils.Skip(Count, count); - return new ValueEnumerable(source, offset + skipCount, takeCount); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable Take(int count) - => new(source, offset, Utils.Take(Count, count)); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : struct, IReadOnlyList - => source.source.Sum(source.offset, source.Count); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyList.cs deleted file mode 100644 index c775623c5..000000000 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyList.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - internal static Option ElementAt(this TList source, int index) - where TList : struct, IReadOnlyList - => source.ElementAt(index, 0, source.Count); - - static Option ElementAt(this TList source, int index, int offset, int count) - where TList : struct, IReadOnlyList - => index < 0 || index >= count - ? Option.None - : Option.Some(source[index + offset]); - - - static Option ElementAt(this TList source, int index, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - if (index >= 0) - { - var end = offset + count; - for (var sourceIndex = offset; sourceIndex < end; sourceIndex++) - { - var item = source[sourceIndex]; - if (predicate.Invoke(item) && index-- is 0) - return Option.Some(item); - } - } - return Option.None; - } - - static Option ElementAtAt(this TList source, int index, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - if (index >= 0) - { - if (offset is 0) - { - for (var sourceIndex = 0; sourceIndex < count; sourceIndex++) - { - var item = source[sourceIndex]; - if (predicate.Invoke(item, sourceIndex) && index-- is 0) - return Option.Some(item); - } - } - else - { - for (var sourceIndex = 0; sourceIndex < count; sourceIndex++) - { - var item = source[sourceIndex + offset]; - if (predicate.Invoke(item, sourceIndex) && index-- is 0) - return Option.Some(item); - } - } - } - return Option.None; - } - - static Option ElementAt(this TList source, int index, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => index < 0 || index >= count - ? Option.None - : Option.Some(selector.Invoke(source[index + offset])); - - - static Option ElementAtAt(this TList source, int index, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => index < 0 || index >= count - ? Option.None - : Option.Some(selector.Invoke(source[index + offset], index)); - - static Option ElementAt(this TList source, int index, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - { - if (index >= 0) - { - var end = offset + count; - for (var sourceIndex = offset; sourceIndex < end; sourceIndex++) - { - var item = source[sourceIndex]; - if (predicate.Invoke(item) && index-- is 0) - return Option.Some(selector.Invoke(item)); - } - } - return Option.None; - } - } -} diff --git a/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyList.cs deleted file mode 100644 index 9ce96d7ee..000000000 --- a/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyList.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - internal static Option First(this TList source) - where TList : struct, IReadOnlyList - => source.First(0, source.Count); - - static Option First(this TList source, int offset, int count) - where TList : struct, IReadOnlyList - => count switch - { - 0 => Option.None, - _ => Option.Some(source[offset]), - }; - - - static Option First(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - return Option.Some(item); - } - return Option.None; - } - - - static Option FirstAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var item = source[index]; - if (predicate.Invoke(item, index)) - return Option.Some(item); - } - } - else - { - for (var index = 0; index < count; index++) - { - var item = source[index + offset]; - if (predicate.Invoke(item, index)) - return Option.Some(item); - } - } - return Option.None; - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static Option First(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => count switch - { - 0 => Option.None, - _ => Option.Some(selector.Invoke(source[offset])), - }; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static Option FirstAt(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => count switch - { - 0 => Option.None, - _ => Option.Some(selector.Invoke(source[offset], 0)), - }; - - - static Option First(this TList source, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - { - var end = offset + count; - for (var index = offset; index < end; index++) - { - if (predicate.Invoke(source[index])) - return Option.Some(selector.Invoke(source[index])); - } - return Option.None; - } - } -} diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyList.cs deleted file mode 100644 index 6a495a374..000000000 --- a/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyList.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - internal static Option Single(this TList source) - where TList : struct, IReadOnlyList - => source.Single(0, source.Count); - - static Option Single(this TList source, int offset, int count) - where TList : struct, IReadOnlyList - => count switch - { - 1 => Option.Some(source[offset]), - _ => Option.None, - }; - - - static Option Single(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.GetSingle(predicate, offset, count); - - - static Option SingleAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.GetSingleAt(predicate, offset, count); - - - static Option Single(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => count switch - { - 1 => Option.Some(selector.Invoke(source[offset])), - _ => Option.None, - }; - - - static Option SingleAt(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => count switch - { - 1 => Option.Some(selector.Invoke(source[offset], 0)), - _ => Option.None, - }; - - - static Option Single(this TList source, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.GetSingle(predicate, offset, count).Select(selector); - - //////////////////////////////// - // GetSingle - - - static Option GetSingle(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - { - var value = item; - - for (index++; index < end; index++) - { - item = source[index]; - if (predicate.Invoke(item)) - return Option.None; - } - - return Option.Some(value); - } - } - - return Option.None; - } - - - static Option GetSingleAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var item = source[index]; - if (predicate.Invoke(item, index)) - { - var value = item; - - for (index++; index < count; index++) - { - item = source[index]; - if (predicate.Invoke(item, index)) - return Option.None; - } - - return Option.Some(value); - } - } - } - else - { - for (var index = 0; index < count; index++) - { - var item = source[index + offset]; - if (predicate.Invoke(item, index)) - { - var value = item; - - for (index++; index < count; index++) - { - item = source[index + offset]; - if (predicate.Invoke(item, index)) - return Option.None; - } - - return Option.Some(value); - } - } - } - - return Option.None; - } - } -} diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs deleted file mode 100644 index 068b86eb5..000000000 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyList.cs +++ /dev/null @@ -1,352 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static WhereEnumerable> Where(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.Where(predicate, 0, source.Count); - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static WhereEnumerable> Where(this TList source, Func predicate, int offset, int count) - where TList : struct, IReadOnlyList - => source.Where>(new FunctionWrapper(predicate), offset, count); - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static WhereEnumerable Where(this TList source, TPredicate predicate = default) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.Where(predicate, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static WhereEnumerable Where(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => new(in source, predicate, offset, count); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct WhereEnumerable - : IValueEnumerable.DisposableEnumerator> - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - internal readonly TList source; - internal readonly TPredicate predicate; - internal readonly int offset; - internal readonly int count; - - internal WhereEnumerable(in TList source, TPredicate predicate, int offset, int count) - => (this.source, this.offset, this.count, this.predicate) = (source, offset, count, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() - => new(in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - { - readonly TList source; - TPredicate predicate; - readonly int end; - int index; - - internal Enumerator(in WhereEnumerable enumerable) - { - source = enumerable.source; - predicate = enumerable.predicate; - index = enumerable.offset - 1; - end = index + enumerable.count; - } - - public readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - while (++index <= end) - { - if (predicate.Invoke(source[index])) - return true; - } - return false; - } - } - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly TList source; - TPredicate predicate; - readonly int end; - int index; - - internal DisposableEnumerator(in WhereEnumerable enumerable) - { - source = enumerable.source; - predicate = enumerable.predicate; - index = enumerable.offset - 1; - end = index + enumerable.count; - } - - public readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - - readonly TSource IEnumerator.Current - => source[index]; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source[index]; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - while (++index <= end) - { - if (predicate.Invoke(source[index])) - return true; - } - return false; - } - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public readonly void Dispose() { } - } - - #region Aggregation - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count() - => source.Count(predicate, offset, count); - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All() - => source.All(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => source.All>(new PredicatePredicateCombination(this.predicate, predicate), offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => source.AllAt>(new PredicatePredicateAtCombination(this.predicate, predicate), offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.Any(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => source.Any>(new PredicatePredicateCombination(this.predicate, predicate), offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => source.AnyAt>(new PredicatePredicateAtCombination(this.predicate, predicate), offset, count); - - #endregion - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereEnumerable, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereEnumerable> Where(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => source.Where>(new PredicatePredicateCombination(this.predicate, predicate), offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => source.WhereAt>(new PredicatePredicateAtCombination(this.predicate, predicate), offset, count); - - #endregion - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereSelectEnumerable> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereSelectEnumerable Select(TSelector selector = default) - where TSelector : struct, IFunction - => source.WhereSelect(predicate, selector, offset, count); - - #endregion - #region Element - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option ElementAt(int index) - => source.ElementAt(index, predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option First() - => source.First(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option Single() -#pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() - => source.Single(predicate, offset, count); -#pragma warning restore HLQ005 // Avoid Single() and SingleOrDefault() - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TSource[] ToArray() - => source.ToArray(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => source.ToArray(pool, clearOnDispose, predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.ToList(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary(new FunctionWrapper(keySelector), comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - => source.ToDictionary(keySelector, comparer, predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => source.ToDictionary(keySelector, elementSelector, comparer, predicate, offset, count); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this WhereEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.Sum(source.predicate, source.offset, source.count); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs deleted file mode 100644 index 349e01d09..000000000 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs +++ /dev/null @@ -1,367 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static WhereAtEnumerable> Where(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.Where(predicate, 0, source.Count); - - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static WhereAtEnumerable> Where(this TList source, Func predicate, int offset, int count) - where TList : struct, IReadOnlyList - => source.WhereAt>(new FunctionWrapper(predicate), offset, count); - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static WhereAtEnumerable WhereAt(this TList source, TPredicate predicate = default) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.WhereAt(predicate, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static WhereAtEnumerable WhereAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => new(in source, predicate, offset, count); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct WhereAtEnumerable - : IValueEnumerable.DisposableEnumerator> - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - internal readonly TList source; - internal readonly TPredicate predicate; - internal readonly int offset; - internal readonly int count; - - internal WhereAtEnumerable(in TList source, TPredicate predicate, int offset, int count) - => (this.source, this.offset, this.count, this.predicate) = (source, offset, count, predicate); - - public readonly Enumerator GetEnumerator() - => new(in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - { - readonly TList source; - TPredicate predicate; - readonly int offset; - readonly int end; - int index; - - internal Enumerator(in WhereAtEnumerable enumerable) - { - source = enumerable.source; - predicate = enumerable.predicate; - offset = enumerable.offset; - index = -1; - end = index + enumerable.count; - } - - public readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index + offset]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - while (++index <= end) - { - if (predicate.Invoke(source[index + offset], index)) - return true; - } - return false; - } - } - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly TList source; - TPredicate predicate; - readonly int offset; - readonly int end; - int index; - - internal DisposableEnumerator(in WhereAtEnumerable enumerable) - { - source = enumerable.source; - predicate = enumerable.predicate; - offset = enumerable.offset; - index = -1; - end = index + enumerable.count; - } - - public readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index + offset]; - } - readonly TSource IEnumerator.Current - => source[index + offset]; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source[index + offset]; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - while (++index <= end) - { - if (predicate.Invoke(source[index + offset], index)) - return true; - } - return false; - } - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public readonly void Dispose() { } - } - - #region Aggregation - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count() - => source.CountAt(predicate, offset, count); - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All() - => source.AllAt(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => source.AllAt>(new PredicatePredicateAtCombination(predicate, this.predicate), offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => source.AllAt>(new PredicateAtPredicateAtCombination(this.predicate, predicate), offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.AnyAt(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => source.AnyAt>(new PredicatePredicateAtCombination(predicate, this.predicate), offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => source.AnyAt>(new PredicateAtPredicateAtCombination(this.predicate, predicate), offset, count); - - #endregion - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TPredicate, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable> Where(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => source.WhereAt>(new PredicatePredicateAtCombination(predicate, this.predicate), offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => source.WhereAt>(new PredicateAtPredicateAtCombination(this.predicate, predicate), offset, count); - - #endregion - #region Projection - - #endregion - #region Element - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option ElementAt(int index) - => source.ElementAtAt(index, predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option First() - => source.FirstAt(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option Single() -#pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() - => source.SingleAt(predicate, offset, count); -#pragma warning restore HLQ005 // Avoid Single() and SingleOrDefault() - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TSource[] ToArray() - => source.ToArrayAt(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => source.ToArrayAt(pool, clearOnDispose, predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.ToListAt(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionaryAt(new FunctionWrapper(keySelector), comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionaryAt(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - => source.ToDictionaryAt(keySelector, comparer, predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionaryAt, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionaryAt(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => source.ToDictionaryAt(keySelector, elementSelector, comparer, predicate, offset, count); - - #endregion - - public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this WhereAtEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.source.SumAt(source.predicate, source.offset, source.count); - } -} - diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs deleted file mode 100644 index da005389b..000000000 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyList.cs +++ /dev/null @@ -1,386 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static WhereSelectEnumerable WhereSelect( - this TList source, - TPredicate predicate, - TSelector selector, - int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => new(source, predicate, selector, offset, count); - - [GeneratorMapping("TSource", "TResult")] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct WhereSelectEnumerable - : IValueEnumerable.DisposableEnumerator> - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - { - internal readonly TList source; - internal readonly TPredicate predicate; - internal readonly TSelector selector; - internal readonly int offset; - internal readonly int count; - - internal WhereSelectEnumerable(TList source, TPredicate predicate, TSelector selector, int offset, int count) - => (this.source, this.offset, this.count, this.predicate, this.selector) = (source, offset, count, predicate, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() - => new(in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - { - readonly TList source; - TPredicate predicate; - TSelector selector; - readonly int end; - int index; - - internal Enumerator(in WhereSelectEnumerable enumerable) - { - source = enumerable.source; - predicate = enumerable.predicate; - selector = enumerable.selector; - index = enumerable.offset - 1; - end = index + enumerable.count; - } - - public TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(source[index]); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - while (++index <= end) - { - if (predicate.Invoke(source[index])) - return true; - } - return false; - } - } - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly TList source; - TPredicate predicate; - TSelector selector; - readonly int end; - int index; - - internal DisposableEnumerator(in WhereSelectEnumerable enumerable) - { - source = enumerable.source; - predicate = enumerable.predicate; - selector = enumerable.selector; - index = enumerable.offset - 1; - end = index + enumerable.count; - } - - public TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(source[index]); - } - TResult IEnumerator.Current - => selector.Invoke(source[index]); - object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(source[index]); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - while (++index <= end) - { - if (predicate.Invoke(source[index])) - return true; - } - return false; - } - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public readonly void Dispose() { } - } - - #region Aggregation - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count() - => source.Count(predicate, offset, count); - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All() - => source.All(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => this.All, DisposableEnumerator, TResult, TPredicate2>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => this.AllAt, DisposableEnumerator, TResult, TPredicate2>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => source.Any(predicate, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => this.Any, DisposableEnumerator, TResult, TPredicate2>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) - where TPredicate2 : struct, IFunction - => this.AnyAt, DisposableEnumerator, TResult, TPredicate2>(predicate); - - #endregion - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, DisposableEnumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, DisposableEnumerator, TResult>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, DisposableEnumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => this.Where, DisposableEnumerator, TResult, TPredicate2>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, DisposableEnumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, DisposableEnumerator, TResult>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, DisposableEnumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => this.WhereAt, DisposableEnumerator, TResult, TPredicate2>(predicate); - - #endregion - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereSelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereSelectEnumerable> Select(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector), offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, DisposableEnumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - - #endregion - #region Element - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option ElementAt(int index) - => source.ElementAt(index, predicate, selector, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option First() - => source.First(predicate, selector, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option Single() - => source.Single(predicate, selector, offset, count); - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TResult[] ToArray() - => source.ToArray(predicate, selector, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => source.ToArray(pool, clearOnDispose, predicate, selector, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.ToList(predicate, selector, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary(new FunctionWrapper(keySelector), comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - => source.ToDictionary(keySelector, comparer, predicate, selector, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => source.ToDictionary(keySelector, elementSelector, comparer, predicate, selector, offset, count); - - #endregion - - public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this WhereSelectEnumerable source) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.source.Sum(source.predicate, source.selector, source.offset, source.count); - } -} - diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyList.cs new file mode 100644 index 000000000..5128d3a26 --- /dev/null +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyList.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static SkipTakeEnumerable Skip(this TList source, int count) + where TList : struct, IReadOnlyList + => source.SkipTake(count, source.Count); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs index 40e719363..9fdeaec90 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs @@ -48,12 +48,12 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - if (Count is 0) return; + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + using var enumerator = source.GetEnumerator(); // skip @@ -75,51 +75,18 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); - - public bool Contains(TSource item) { if (Count is 0) - return false; + return; if (skipCount is 0 && Count == source.Count && source is ICollection collection) - return collection.Contains(item); - - using var enumerator = source.GetEnumerator(); - - // skip - for (var counter = 0; counter < skipCount; counter++) - { - if (!enumerator.MoveNext()) - Throw.InvalidOperationException(); - } - - // take - if (Utils.IsValueType()) - { - for (var counter = 0; counter < Count; counter++) - { - if (!enumerator.MoveNext()) - Throw.InvalidOperationException(); - - if (EqualityComparer.Default.Equals(enumerator.Current, item)) - return true; - } - } + collection.CopyTo(array, arrayIndex); else - { - var defaultComparer = EqualityComparer.Default; - for (var counter = 0; counter < Count; counter++) - { - if (!enumerator.MoveNext()) - Throw.InvalidOperationException(); - - if (defaultComparer.Equals(enumerator.Current, item)) - return true; - } - } - return false; + CopyTo(array.AsSpan().Slice(arrayIndex)); } + + public bool Contains(TSource item) + => Contains(item, EqualityComparer.Default); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -217,8 +184,7 @@ public bool Contains(TSource value, IEqualityComparer? comparer) if (skipCount is 0 && Count == source.Count && source is ICollection collection) return collection.Contains(value); - if (Utils.IsValueType()) - return DefaultContains(source, value, skipCount, Count); + return DefaultContains(source, value, skipCount, Count); } return ComparerContains(source, value, comparer, skipCount, Count); diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyList.cs new file mode 100644 index 000000000..56a597036 --- /dev/null +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyList.cs @@ -0,0 +1,240 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static SkipTakeEnumerable SkipTake(this TList source, int skipCount, int takeCount) + where TList : struct, IReadOnlyList + => new(in source, skipCount, takeCount); + + [StructLayout(LayoutKind.Auto)] + public readonly partial struct SkipTakeEnumerable + : IValueReadOnlyList.DisposableEnumerator> + , IList + where TList : struct, IReadOnlyList + { + readonly TList source; + readonly int offset; + + internal SkipTakeEnumerable(in TList source, int skipCount, int takeCount) + { + this.source = source; + (this.offset, Count) = Utils.SkipTake(source.Count, skipCount, takeCount); + } + + public int Count { get; } + + public TSource this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + if ((uint)index >= (uint)Count) Throw.ArgumentOutOfRangeException(nameof(index)); + + return source[index + offset]; + } + } + + TSource IReadOnlyList.this[int index] + => this[index]; + + TSource IList.this[int index] + { + get => this[index]; + + [ExcludeFromCodeCoverage] + // ReSharper disable once ValueParameterNotUsed + set => Throw.NotSupportedException(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() + => new(in this); + + DisposableEnumerator IValueEnumerable.GetEnumerator() + => new(in this); + + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(in this); + + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(in this); + + bool ICollection.IsReadOnly + => true; + + public void CopyTo(Span span) + { + if (Count is 0) + return; + + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + + if (offset is 0) + { + for(var index = 0; index < Count && index < span.Length; index++) + span[index] = source[index]; + } + else + { + for(var index = 0; index < Count && index < span.Length; index++) + span[index] = source[index + offset]; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TSource[] array, int arrayIndex) + { + if (Count is 0) + return; + + if (offset is 0 && Count == source.Count && source is ICollection collection) + collection.CopyTo(array, arrayIndex); + else + CopyTo(array.AsSpan().Slice(arrayIndex)); + } + + public bool Contains(TSource item) + => Contains(item, EqualityComparer.Default); + + public int IndexOf(TSource item) + => ValueReadOnlyListExtensions.IndexOf(source, item, offset, Count); + + [ExcludeFromCodeCoverage] + void ICollection.Add(TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void ICollection.Clear() + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + bool ICollection.Remove(TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void IList.Insert(int index, TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void IList.RemoveAt(int index) + => Throw.NotSupportedException(); + + [StructLayout(LayoutKind.Auto)] + public struct Enumerator + { + readonly TList source; + readonly int end; + int index; + + internal Enumerator(in SkipTakeEnumerable enumerable) + { + source = enumerable.source; + index = enumerable.offset - 1; + end = index + enumerable.Count; + } + + public readonly TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + public bool MoveNext() + => ++index <= end; + } + + [StructLayout(LayoutKind.Auto)] + public struct DisposableEnumerator + : IEnumerator + { + readonly TList source; + readonly int end; + int index; + + internal DisposableEnumerator(in SkipTakeEnumerable enumerable) + { + source = enumerable.source; + index = enumerable.offset - 1; + end = index + enumerable.Count; + } + + public readonly TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + readonly TSource IEnumerator.Current + => source[index]; + readonly object? IEnumerator.Current + // ReSharper disable once HeapView.PossibleBoxingAllocation + => source[index]; + + public bool MoveNext() + => ++index <= end; + + [ExcludeFromCodeCoverage] + public readonly void Reset() + => Throw.NotSupportedException(); + + public void Dispose() + { } + } + + public bool Contains(TSource value, IEqualityComparer? comparer) + { + if (source.Count is 0) + return false; + + if (Utils.UseDefault(comparer)) + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (offset is 0 && Count == source.Count && source is ICollection collection) + return collection.Contains(value); + + return DefaultContains(source, value, offset, Count); + } + + return ComparerContains(source, value, comparer, offset, Count); + + static bool DefaultContains(TList source, TSource value, int offset, int count) + { + var end = offset + count; + for(var index = offset; index < end; index++) + { + if (EqualityComparer.Default.Equals(source[index], value!)) + return true; + } + return false; + } + + static bool ComparerContains(TList source, TSource value, IEqualityComparer? comparer, int offset, int count) + { + comparer ??= EqualityComparer.Default; + var end = offset + count; + for(var index = offset; index < end; index++) + { + if (comparer.Equals(source[index], value!)) + return true; + } + return false; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SkipTakeEnumerable Take(int count) + => source.SkipTake(offset, Math.Min(Count, count)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this in SkipTakeEnumerable source) + where TList : struct, IReadOnlyList + => source.Count; + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyList.cs new file mode 100644 index 000000000..a9ad4d35e --- /dev/null +++ b/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyList.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static SkipTakeEnumerable Take(this TList source, int count) + where TList : struct, IReadOnlyList + => source.SkipTake(0, count); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 40fb756ee..4ed7a9c80 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -76,6 +76,9 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { + if (Count is 0) + return; + if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); @@ -174,17 +177,17 @@ public ArraySegmentSelectAtEnumerable source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector, 0, Count); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector, 0, Count); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index 883dcbd48..13f57503f 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -75,6 +75,9 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { + if (Count is 0) + return; + if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); @@ -170,17 +173,17 @@ public MemorySelectAtEnumerable source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => ValueReadOnlyListExtensions.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(this, selector, 0, Count); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => ValueReadOnlyListExtensions.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(this, selector, 0, Count); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index 46705f2f8..9d71609de 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -58,17 +58,17 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { + if (Count is 0) + return; + if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - if (source.Count is not 0) + checked { - checked - { - using var enumerator = source.GetEnumerator(); - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = selector.Invoke(enumerator.Current); - } + using var enumerator = source.GetEnumerator(); + for (var index = 0; enumerator.MoveNext(); index++) + span[index] = selector.Invoke(enumerator.Current); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs deleted file mode 100644 index 0711575b1..000000000 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs +++ /dev/null @@ -1,379 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SelectEnumerable> Select(this TList source, Func selector) - where TList : struct, IReadOnlyList - => source.Select(selector, 0, source.Count); - - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SelectEnumerable> Select(this TList source, Func selector, int offset, int count) - where TList : struct, IReadOnlyList - => source.Select>(new FunctionWrapper(selector), offset, count); - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SelectEnumerable Select(this TList source, TSelector selector = default) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.Select(selector, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SelectEnumerable Select(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => new(in source, selector, offset, count); - - [GeneratorMapping("TSource", "TResult")] - [StructLayout(LayoutKind.Auto)] - public partial struct SelectEnumerable - : IValueReadOnlyList.DisposableEnumerator> - , IList - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - internal int offset; - internal TList source; - internal TSelector selector; - - internal SelectEnumerable(in TList source, TSelector selector, int offset, int count) - => (this.source, this.offset, Count, this.selector) = (source, offset, count, selector); - - public readonly int Count { get; } - - public TResult this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); - - return selector.Invoke(source[index + offset]); - } - } - TResult IReadOnlyList.this[int index] - => this[index]; - TResult IList.this[int index] - { - get => this[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() - => new(in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() => - // ReSharper disable once HeapView.BoxingAllocation - new DisposableEnumerator(in this); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - Copy(source, offset, span, Count, selector); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TResult[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); - - public bool Contains(TResult item) - => source.Contains(item, default, selector, offset, Count); - - public int IndexOf(TResult item) - => IndexOf(source, item, selector, offset, Count); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TResult item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TResult item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TResult item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - { - readonly TList source; - TSelector selector; - readonly int end; - int index; - - internal Enumerator(in SelectEnumerable enumerable) - { - source = enumerable.source; - selector = enumerable.selector; - index = enumerable.offset - 1; - end = index + enumerable.Count; - } - - public TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(source[index]); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - } - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly TList source; - TSelector selector; - readonly int end; - int index; - - internal DisposableEnumerator(in SelectEnumerable enumerable) - { - source = enumerable.source; - selector = enumerable.selector; - index = enumerable.offset - 1; - end = index + enumerable.Count; - } - - public TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(source[index]); - } - TResult IEnumerator.Current - => selector.Invoke(source[index]); - object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(source[index]); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public readonly void Dispose() { } - } - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectEnumerable Skip(int count) - { - var (skipCount, takeCount) = Utils.Skip(Count, count); - return new SelectEnumerable(source, selector, offset + skipCount, takeCount); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectEnumerable Take(int count) - => new(source, selector, offset, Utils.Take(Count, count)); - - #endregion - #region Aggregation - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => Count is not 0; - - #endregion - #region Filtering - - #endregion - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectEnumerable> Select(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => source.Select>(new SelectorSelectorCombination(this.selector, selector), offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => SelectAt>(new FunctionWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable> SelectAt(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector), offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector, offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector, offset, Count); - - #endregion - #region Element - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option ElementAt(int index) - => source.ElementAt(index, selector, offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option First() - => source.First(selector, offset, Count); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option Single() - => source.Single(selector, offset, Count); - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TResult[] ToArray() - => source.ToArray(selector, offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => source.ToArray(pool, clearOnDispose, selector, offset, Count); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.ToList(selector, offset, Count); - - #endregion - - public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this SelectEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.Sum(source.selector, source.offset, source.Count); - } -} - diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 732fd4ea9..cf416bf81 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -169,17 +169,17 @@ public ArraySegmentSelectAtEnumerable source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector, 0, Count); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector, 0, Count); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index d4e00b16d..7532fcc27 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -164,17 +164,17 @@ public MemorySelectAtEnumerable source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector, 0, Count); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueReadOnlyListExtensions.SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector, 0, Count); + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); #endregion #region Element diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index 72d595b69..3b5da95a3 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -58,17 +58,17 @@ bool ICollection.IsReadOnly public void CopyTo(Span span) { + if (Count is 0) + return; + if (span.Length < Count) Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - if (source.Count is not 0) + checked { - checked - { - using var enumerator = source.GetEnumerator(); - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = selector.Invoke(enumerator.Current, index); - } + using var enumerator = source.GetEnumerator(); + for (var index = 0; enumerator.MoveNext(); index++) + span[index] = selector.Invoke(enumerator.Current, index); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs deleted file mode 100644 index 3c8d2c478..000000000 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs +++ /dev/null @@ -1,399 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SelectAtEnumerable> Select(this TList source, Func selector) - where TList : struct, IReadOnlyList - => source.Select(selector, 0, source.Count); - - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SelectAtEnumerable> Select(this TList source, Func selector, int offset, int count) - where TList : struct, IReadOnlyList - => source.SelectAt>(new FunctionWrapper(selector), offset, count); - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SelectAtEnumerable SelectAt(this TList source, TSelector selector = default) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.SelectAt(selector, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SelectAtEnumerable SelectAt(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => new(in source, selector, offset, count); - - [GeneratorMapping("TSource", "TResult")] - [StructLayout(LayoutKind.Auto)] - public partial struct SelectAtEnumerable - : IValueReadOnlyList.DisposableEnumerator> - , IList - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - internal readonly int offset; - internal readonly TList source; - internal TSelector selector; - - internal SelectAtEnumerable(in TList source, TSelector selector, int offset, int count) - => (this.source, this.offset, Count, this.selector) = (source, offset, count, selector); - - public readonly int Count { get; } - - public TResult this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); - - return selector.Invoke(source[index + offset], index); - } - } - TResult IReadOnlyList.this[int index] - => this[index]; - TResult IList.this[int index] - { - get => this[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() - => new (in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() - => new (in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() => - // ReSharper disable once HeapView.BoxingAllocation - new DisposableEnumerator(in this); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - var end = Count; - if (offset is 0) - { - for (var index = 0; index < end; index++) - { - var item = source[index]; - span[index] = selector.Invoke(item, index); - } - } - else - { - for (var index = 0; index < end; index++) - { - var item = source[index + offset]; - span[index] = selector.Invoke(item, index); - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TResult[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); - - public bool Contains(TResult item) - => source.ContainsAt(item, default, selector, offset, Count); - - public int IndexOf(TResult item) - => IndexOfAt(source, item, selector, offset, Count); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TResult item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TResult item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TResult item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - { - readonly TList source; - TSelector selector; - readonly int offset; - readonly int end; - int index; - - internal Enumerator(in SelectAtEnumerable enumerable) - { - source = enumerable.source; - selector = enumerable.selector; - offset = enumerable.offset; - index = -1; - end = index + enumerable.Count; - } - - public readonly TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(source[index + offset], index); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - } - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly TList source; - TSelector selector; - readonly int offset; - readonly int end; - int index; - - internal DisposableEnumerator(in SelectAtEnumerable enumerable) - { - source = enumerable.source; - selector = enumerable.selector; - offset = enumerable.offset; - index = -1; - end = index + enumerable.Count; - } - - public readonly TResult Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => selector.Invoke(source[index + offset], index); - } - readonly TResult IEnumerator.Current - => selector.Invoke(source[index + offset], index); - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => selector.Invoke(source[index + offset], index); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public readonly void Dispose() { } - } - - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable Skip(int count) - { - var (skipCount, takeCount) = Utils.Skip(Count, count); - return new SelectAtEnumerable(source, selector, offset + skipCount, takeCount); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable Take(int count) - => new(source, selector, offset, Utils.Take(Count, count)); - - #endregion - #region Aggregation - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => Count is not 0; - - #endregion - #region Filtering - - #endregion - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable> Select(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => source.SelectAt>(new SelectorAtSelectorCombination(this.selector, selector), offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => SelectAt>(new FunctionWrapper(selector)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable> SelectAt(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector), offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector, offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector, offset, Count); - - #endregion - #region Element - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option ElementAt(int index) - => source.ElementAtAt(index, selector, offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option First() - => source.FirstAt(selector, offset, Count); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option Single() - => source.SingleAt(selector, offset, Count); - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TResult[] ToArray() - => source.ToArrayAt(selector, offset, Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => source.ToArrayAt(pool, clearOnDispose, selector, offset, Count); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => source.ToListAt(selector, offset, Count); - - #endregion - - public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this SelectAtEnumerable source) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.source.SumAt(source.selector, source.offset, source.Count); - } -} - diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs deleted file mode 100644 index fd3ae3f6f..000000000 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs +++ /dev/null @@ -1,316 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(true)] - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SelectManyEnumerable> SelectMany(this TList source, Func selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => source.SelectMany>(new FunctionWrapper(selector), offset, count); - - [GeneratorIgnore(true)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static SelectManyEnumerable SelectMany(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => new(source, selector, offset, count); - - [GeneratorIgnore] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct SelectManyEnumerable - : IValueEnumerable.Enumerator> - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - { - readonly TList source; - readonly TSelector selector; - readonly int offset; - readonly int count; - - internal SelectManyEnumerable(TList source, TSelector selector, int offset, int count) - => (this.source, this.selector, this.offset, this.count) = (source, selector, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - : IEnumerator - { - readonly TList source; - TSelector selector; - readonly int end; - EnumeratorState state; - int sourceIndex; - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TSubEnumerator subEnumerator; // do not make readonly - - internal Enumerator(in SelectManyEnumerable enumerable) - { - source = enumerable.source; - selector = enumerable.selector; - state = EnumeratorState.Enumerating; - sourceIndex = enumerable.offset; - end = sourceIndex + enumerable.count; - subEnumerator = default; - } - - public readonly TResult Current - => subEnumerator.Current; - readonly TResult IEnumerator.Current - => subEnumerator.Current; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => subEnumerator.Current; - - public bool MoveNext() - { - switch (state) - { - case EnumeratorState.Enumerating: - if (++sourceIndex >= end) - { - state = EnumeratorState.Complete; - return false; - } - - var enumerable = selector.Invoke(source[sourceIndex]); - subEnumerator = enumerable.GetEnumerator(); - - state = EnumeratorState.EnumeratingSub; - goto case EnumeratorState.EnumeratingSub; - - case EnumeratorState.EnumeratingSub: - if (!subEnumerator.MoveNext()) - { - state = EnumeratorState.Enumerating; - goto case EnumeratorState.Enumerating; - } - return true; - - default: - return false; - } - } - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public void Dispose() => subEnumerator.Dispose(); - } - - - #region Aggregation - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() - => this.Count, Enumerator, TResult>(); - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => this.Any, Enumerator, TResult>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, Enumerator, TResult>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate predicate = default) - where TPredicate : struct, IFunction - => this.Any, Enumerator, TResult, TPredicate>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, Enumerator, TResult>(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate predicate = default) - where TPredicate : struct, IFunction - => this.AnyAt, Enumerator, TResult, TPredicate>(predicate); - - #endregion - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) - where TPredicate : struct, IFunction - => ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) - where TPredicate : struct, IFunction - => ValueEnumerableExtensions.Where, Enumerator, TResult, TPredicate>(this, predicate); - - #endregion - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2, TSelector2>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => ValueEnumerableExtensions.SelectAt, Enumerator, TResult, TResult2, TSelector2>(this, selector); - - #endregion - #region Element - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option ElementAt(int index) - => this.ElementAt, Enumerator, TResult>(index); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option First() - => this.First, Enumerator, TResult>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Option Single() - => this.Single, Enumerator, TResult>(); - - #endregion - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectManyEnumerable AsValueEnumerable() - => this; - - #endregion - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SkipEnumerable, Enumerator, TResult> Skip(int count) - => ValueEnumerableExtensions.Skip, Enumerator, TResult>(this, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.TakeEnumerable, Enumerator, TResult> Take(int count) - => ValueEnumerableExtensions.Take, Enumerator, TResult>(this, count); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this SelectManyEnumerable source) - where TList : struct, IReadOnlyList - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Sum, SelectManyEnumerable.Enumerator, decimal?, decimal>(); - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyList.cs deleted file mode 100644 index 381062ee4..000000000 --- a/NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyList.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool All(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.All(predicate, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool All(this TList source, Func predicate, int offset, int count) - where TList : struct, IReadOnlyList - => source.All>(new FunctionWrapper(predicate), offset, count); - - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool All(this TList source, TPredicate predicate) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.All(predicate, 0, source.Count); - - static bool All(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (!predicate.Invoke(item)) - return false; - } - return true; - } - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool All(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.All(predicate, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool All(this TList source, Func predicate, int offset, int count) - where TList : struct, IReadOnlyList - => source.AllAt>(new FunctionWrapper(predicate), offset, count); - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool AllAt(this TList source, TPredicate predicate) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.AllAt(predicate, 0, source.Count); - - static bool AllAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var item = source[index]; - if (!predicate.Invoke(item, index)) - return false; - } - } - else - { - for (var index = 0; index < count; index++) - { - var item = source[index + offset]; - if (!predicate.Invoke(item, index)) - return false; - } - } - return true; - } - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyList.cs deleted file mode 100644 index c1c3aa690..000000000 --- a/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyList.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool Any(this TList source) - where TList : struct, IReadOnlyList - => source.Any(0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool Any(this TList source, int offset, int count) - where TList : struct, IReadOnlyList - => count is not 0; - - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool Any(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.Any(predicate, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool Any(this TList source, Func predicate, int offset, int count) - where TList : struct, IReadOnlyList - => source.Any>(new FunctionWrapper(predicate), offset, count); - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool Any(this TList source, TPredicate predicate) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.Any(predicate, 0, source.Count); - - static bool Any(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - return true; - } - return false; - } - - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool Any(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.Any(predicate, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool Any(this TList source, Func predicate, int offset, int count) - where TList : struct, IReadOnlyList - => source.AnyAt>(new FunctionWrapper(predicate), offset, count); - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool AnyAt(this TList source, TPredicate predicate) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.AnyAt(predicate, 0, source.Count); - - static bool AnyAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var item = source[index]; - if (predicate.Invoke(item, index)) - return true; - } - } - else - { - for (var index = 0; index < count; index++) - { - var item = source[index + offset]; - if (predicate.Invoke(item, index)) - return true; - } - } - return false; - } - } -} - diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs index a8d28127d..ab05607e5 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs @@ -13,8 +13,7 @@ internal static bool Contains(this TEnumerable source, TSo if (source is ICollection collection) return collection.Contains(value); - if (Utils.IsValueType()) - return DefaultContains(source, value); + return DefaultContains(source, value); } return ComparerContains(source, value, comparer); @@ -54,8 +53,7 @@ internal static bool Contains collection) return collection.Contains(value); - if (Utils.IsValueType()) - return DefaultContains(source, value, getEnumerator); + return DefaultContains(source, value, getEnumerator); } return ComparerContains(source, value, comparer, getEnumerator); diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs index 60911f9ce..d50c3fdfa 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -14,8 +14,7 @@ public static bool Contains(this TEnumerable if (source is ICollection collection) return collection.Contains(value); - if (Utils.IsValueType()) - return DefaultContains(source, value); + return DefaultContains(source, value); } return ComparerContains(source, value, comparer); diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs deleted file mode 100644 index 53c5a247b..000000000 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyList.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool Contains(this TList source, TSource value, IEqualityComparer? comparer = default) - where TList : struct, IReadOnlyList - => source.Contains(value, comparer, 0, source.Count); - - static bool Contains(this TList source, TSource value, IEqualityComparer? comparer, int offset, int count) - where TList : struct, IReadOnlyList - { - if (count is 0) - return false; - - if (Utils.UseDefault(comparer)) - { - // ReSharper disable once HeapView.BoxingAllocation - if (offset is 0 && count == source.Count && source is ICollection collection) - return collection.Contains(value); - - if (Utils.IsValueType()) - return DefaultContains(source, value, offset, count); - } - - return ComparerContains(source, value, comparer, offset, count); - - static bool DefaultContains(TList source, TSource value, int offset, int count) - { - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (EqualityComparer.Default.Equals(item, value)) - return true; - } - return false; - } - - static bool ComparerContains(TList source, TSource value, IEqualityComparer? comparer, int offset, int count) - { - comparer ??= EqualityComparer.Default; - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (comparer.Equals(item, value)) - return true; - } - return false; - } - } - - static bool Contains(this TList source, TResult value, IEqualityComparer? comparer, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - return count switch - { - 0 => false, - _ => Utils.UseDefault(comparer) - ? ValueContains(source, value, selector, offset, count) - : ReferenceContains(source, value, comparer, selector, offset, count) - }; - - static bool ValueContains(TList source, TResult value, TSelector selector, int offset, int count) - { - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(item), value)) - return true; - } - return false; - } - - static bool ReferenceContains(TList source, TResult value, IEqualityComparer? comparer, TSelector selector, int offset, int count) - { - comparer ??= EqualityComparer.Default; - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (comparer.Equals(selector.Invoke(item), value)) - return true; - } - return false; - } - } - - - static bool ContainsAt(this TList source, TResult value, IEqualityComparer? comparer, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - return count switch - { - 0 => false, - _ => Utils.UseDefault(comparer) - ? ValueContains(source, value, selector, offset, count) - : ReferenceContains(source, value, comparer, selector, offset, count) - }; - - static bool ValueContains(TList source, TResult value, TSelector selector, int offset, int count) - { - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var item = source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(item, index), value)) - return true; - } - } - else - { - for (var index = 0; index < count; index++) - { - var item = source[index + offset]; - if (EqualityComparer.Default.Equals(selector.Invoke(item, index), value)) - return true; - } - } - return false; - } - - static bool ReferenceContains(TList source, TResult value, IEqualityComparer? comparer, TSelector selector, int offset, int count) - { - comparer ??= EqualityComparer.Default; - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var item = source[index]; - if (comparer.Equals(selector.Invoke(item, index), value)) - return true; - } - } - else - { - for (var index = 0; index < count; index++) - { - var item = source[index + offset]; - if (comparer.Equals(selector.Invoke(item, index), value)) - return true; - } - } - return false; - } - } - } -} - diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs deleted file mode 100644 index 53a7d55e2..000000000 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueReadOnlyList.cs +++ /dev/null @@ -1,227 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static DistinctEnumerable Distinct(this TList source, IEqualityComparer? comparer = default) - where TList : struct, IReadOnlyList - => source.Distinct(comparer, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static DistinctEnumerable Distinct(this TList source, IEqualityComparer? comparer, int offset, int count) - where TList : struct, IReadOnlyList - => new(source, comparer, offset, count); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct DistinctEnumerable - : IValueEnumerable.Enumerator> - where TList : struct, IReadOnlyList - { - readonly TList source; - readonly IEqualityComparer? comparer; - readonly int offset; - readonly int count; - - internal DistinctEnumerable(TList source, IEqualityComparer? comparer, int offset, int count) - => (this.source, this.comparer, this.offset, this.count) = (source, comparer, offset, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() - => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(in this); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - : IEnumerator - { - readonly TList source; - Set set; - readonly int end; - int index; - - internal Enumerator(in DistinctEnumerable enumerable) - { - source = enumerable.source; - set = new Set(enumerable.comparer); - index = enumerable.offset - 1; - end = index + enumerable.count; - } - - public readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - readonly TSource IEnumerator.Current - => source[index]; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source[index]; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - while (++index <= end) - { - if (set.Add(source[index])) - return true; - } - return false; - } - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public void Dispose() - => set.Dispose(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - readonly Set GetSet() - { - using var set = new Set(comparer); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - _ = set.Add(item); - } - return set; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public DistinctEnumerable Skip(int count) - { - var (skipCount, takeCount) = Utils.Skip(this.count, count); - return new DistinctEnumerable(source, comparer, offset + skipCount, takeCount); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public DistinctEnumerable Take(int count) - => new(source, comparer, offset, Utils.Take(this.count, count)); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() - => count switch - { - 0 => 0, - _ => GetSet().Count - }; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any() - => count is not 0; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TSource[] ToArray() - => count switch - { - 0 => Array.Empty(), - _ => GetSet().ToArray() - }; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => GetSet().ToArray(pool, clearOnDispose); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly List ToList() - => count switch - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - 0 => new List(), - _ => GetSet().ToList() - }; - - public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - using var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this DistinctEnumerable source) - where TList : struct, IReadOnlyList - => source.Sum, DistinctEnumerable.Enumerator, decimal?, decimal>(); - } -} - diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index 83f50c7e1..743706186 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -199,9 +199,10 @@ bool ICollection.IsReadOnly public readonly void CopyTo(Span span) { - if (slots is null) return; + if (Count is 0) + return; - var source = slots.AsSpan().Slice(0, Count); + var source = slots!.AsSpan().Slice(0, Count); for (var index = 0; index < source.Length && index < span.Length; index++) { ref readonly var slot = ref source[index]; diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs index 419cde6e2..f71eeca54 100644 --- a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs @@ -5,7 +5,6 @@ namespace NetFabric.Hyperlinq { static partial class ReadOnlyListExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOf(TList source, TSource item, int offset, int count) where TList : IReadOnlyList { diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs index 6f9dbc554..b9d7b5f19 100644 --- a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs @@ -5,7 +5,6 @@ namespace NetFabric.Hyperlinq { static partial class ValueReadOnlyListExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOf(TList source, TSource item, int offset, int count) where TList : struct, IReadOnlyList { @@ -40,7 +39,6 @@ public static int IndexOf(TList source, TSource item, int offset return -1; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOf(TList source, TResult item, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction @@ -73,7 +71,6 @@ public static int IndexOf(TList source, TRes } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOfAt(TList source, TResult item, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs b/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs index 51381796a..34d54d99d 100644 --- a/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs +++ b/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs @@ -7,10 +7,11 @@ static partial class Utils { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsValueType() - => default(T) is object; + => default(T) is {}; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool UseDefault(IEqualityComparer? comparer) - => IsValueType() && (comparer is null || ReferenceEquals(comparer, EqualityComparer.Default)); + => IsValueType() + && (comparer is null || ReferenceEquals(comparer, EqualityComparer.Default)); } } From 935fb60f59547030d240f58637df5d820ad67962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Tue, 18 May 2021 09:51:36 +0100 Subject: [PATCH 31/61] Refactor indexer bounds checking (#357) --- .../Generation/ValueEnumerable/Return.Tests.cs | 2 +- .../AsValueEnumerable/AsValueEnumerable.ArraySegment.cs | 2 +- NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs | 4 ++-- NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs | 2 +- NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj | 7 +------ .../Projection/Select/Select/Select.ArraySegment.cs | 2 +- .../Projection/Select/SelectAt/SelectAt.ArraySegment.cs | 2 +- NetFabric.Hyperlinq/Utils/Throw.cs | 8 -------- 8 files changed, 8 insertions(+), 21 deletions(-) diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Return.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Return.Tests.cs index a9d1dd025..6f4f2870f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Return.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Return.Tests.cs @@ -33,7 +33,7 @@ public void Indexer_With_IndexOutOfRange_Must_Throw(int value, int index) Func action = () => ValueEnumerable.Return(value)[index]; // Assert - _ = action.Must().Throw(); + _ = action.Must().Throw(); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index 24fd23352..9447f0251 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -39,7 +39,7 @@ public readonly TSource this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); + if ((uint)index >= (uint)Count) Throw.ArgumentOutOfRangeException(nameof(index)); return source.Array![source.Offset + index]; } diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs index fd5f6de8e..6e164d2c8 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs @@ -20,10 +20,10 @@ public int Count => 0; public TSource this[int index] - => Throw.IndexOutOfRangeException(); + => Throw.ArgumentOutOfRangeException(nameof(index)); TSource IList.this[int index] { - get => Throw.IndexOutOfRangeException(); + get => Throw.ArgumentOutOfRangeException(nameof(index)); [ExcludeFromCodeCoverage] // ReSharper disable once ValueParameterNotUsed diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs index 9aa6bfa2f..364b7b3a7 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs @@ -33,7 +33,7 @@ public readonly TSource this[int index] get => index switch { 0 => value, - _ => Throw.IndexOutOfRangeException() + _ => Throw.ArgumentOutOfRangeException(nameof(index)) }; } TSource IReadOnlyList.this[int index] diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 67c9f44fd..c250a4296 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -4,7 +4,7 @@ net461;netstandard2.0;netcoreapp3.1;net5.0;net6.0 NetFabric.Hyperlinq NetFabric.Hyperlinq - High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays, Memory and Span. + High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, Memory, and Span. 3.0.0-beta44 Icon.png LICENSE @@ -81,9 +81,4 @@ - - - - - diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 4ed7a9c80..c21894565 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -44,7 +44,7 @@ public TResult this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); + if ((uint)index >= (uint)Count) Throw.ArgumentOutOfRangeException(nameof(index)); return selector.Invoke(source.Array![index + source.Offset]); } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index cf416bf81..310dd73b3 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -47,7 +47,7 @@ public TResult this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (index < 0 || index >= Count) Throw.IndexOutOfRangeException(); + if ((uint)index >= (uint)Count) Throw.ArgumentOutOfRangeException(nameof(index)); return selector.Invoke(source.Array![index + source.Offset], index); } diff --git a/NetFabric.Hyperlinq/Utils/Throw.cs b/NetFabric.Hyperlinq/Utils/Throw.cs index 5a1610859..c71a9e110 100644 --- a/NetFabric.Hyperlinq/Utils/Throw.cs +++ b/NetFabric.Hyperlinq/Utils/Throw.cs @@ -38,14 +38,6 @@ public static T ArgumentOutOfRangeException(string? paramName) public static ref readonly T ArgumentOutOfRangeExceptionRef(string? paramName) => throw new ArgumentOutOfRangeException(paramName); - [DoesNotReturn] - public static void IndexOutOfRangeException() - => throw new IndexOutOfRangeException(); - - [DoesNotReturn] - public static T IndexOutOfRangeException() - => throw new IndexOutOfRangeException(); - [DoesNotReturn] public static void EmptySequence() => throw new InvalidOperationException(Resource.EmptySequence); From daab08e2b802032661677620983e7a5788d3fe37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Sun, 30 May 2021 15:53:34 +0100 Subject: [PATCH 32/61] Add array.ToArray() benchmarks (#358) --- Benchmarks/ArrayToArrayBenchmarks.md | 38 +++++++++++++++++++ .../Benchmarks/ArrayToArrayBenchmarks.cs | 36 ++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 Benchmarks/ArrayToArrayBenchmarks.md create mode 100644 NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs diff --git a/Benchmarks/ArrayToArrayBenchmarks.md b/Benchmarks/ArrayToArrayBenchmarks.md new file mode 100644 index 000000000..af4a033b1 --- /dev/null +++ b/Benchmarks/ArrayToArrayBenchmarks.md @@ -0,0 +1,38 @@ +## ArrayToArrayBenchmarks + +### Source +[ArrayToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs) + +### References: +- Linq: 6.0.0-preview.4.21253.7 +- System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) +- System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) +- System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) + +### Results: +``` ini + +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-ERYMHU : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + +Runtime=.NET 6.0 + +``` +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|----------------- |------ |-----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| **ArrayClone** | **10** | **83.162 ns** | **0.9078 ns** | **0.8491 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | +| SpanToArray | 10 | 7.645 ns | 0.0932 ns | 0.0872 ns | 0.09 | 0.00 | 0.0306 | - | - | 64 B | +| CollectionCopyTo | 10 | 15.119 ns | 0.3594 ns | 0.2806 ns | 0.18 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| **ArrayClone** | **100** | **91.453 ns** | **1.2853 ns** | **1.2023 ns** | **1.00** | **0.00** | **0.2021** | **-** | **-** | **424 B** | +| SpanToArray | 100 | 30.949 ns | 0.6774 ns | 0.6336 ns | 0.34 | 0.01 | 0.2027 | - | - | 424 B | +| CollectionCopyTo | 100 | 38.433 ns | 0.7989 ns | 0.8204 ns | 0.42 | 0.01 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | +| **ArrayClone** | **1000** | **243.403 ns** | **4.9315 ns** | **5.8706 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | +| SpanToArray | 1000 | 250.213 ns | 4.9555 ns | 5.5080 ns | 1.03 | 0.03 | 1.9226 | - | - | 4,024 B | +| CollectionCopyTo | 1000 | 242.564 ns | 3.3163 ns | 3.1020 ns | 1.00 | 0.02 | 1.9155 | - | - | 4,024 B | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs new file mode 100644 index 000000000..a2a54966e --- /dev/null +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs @@ -0,0 +1,36 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; +using System; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks +{ + public class ArrayToArrayBenchmarks + { + const int seed = 2982; + int[]? array; + + [Params(10, 100, 1000)] + public int Count { get; set; } + + [GlobalSetup] + public void GlobalSetup() + => array = Utils.GetRandomValues(seed, Count); + + [Benchmark(Baseline = true)] + public int[] ArrayClone() + => (int[])array!.Clone(); + + [Benchmark] + public int[] SpanToArray() + => array.AsSpan().ToArray(); + + [Benchmark] + public int[] CollectionCopyTo() + { + var result = GC.AllocateUninitializedArray(Count); + ((System.Collections.ICollection)array!).CopyTo(result, 0); + return result; + } + } +} From 8b57da1b30c21f60f0fb9a2e70f181f08333d6ef Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sun, 23 May 2021 23:03:45 +0100 Subject: [PATCH 33/61] Use enumerator instead of indexer --- Benchmarks/AggressiveInliningBenchmarks.md | 29 ++ Benchmarks/ArrayIterationBenchmarks.md | 32 +- Benchmarks/ListIterationBenchmarks.md | 33 ++ Benchmarks/ReadOnlyFieldsBenchmarks.md | 30 ++ .../AsyncFunctionWrapper.cs | 27 ++ .../FunctionInWrapper.cs | 6 + .../FunctionWrapper.cs | 30 ++ .../AggressiveInliningBenchmarks.cs | 82 ++++ .../Benchmarks/ArrayIterationBenchmarks.cs | 127 +++--- .../Benchmarks/ArrayToArrayBenchmarks.cs | 2 - .../Benchmarks/ListIterationBenchmarks.cs | 90 +++++ .../Benchmarks/ReadOnlyFieldsBenchmarks.cs | 121 ++++++ .../NetFabric.Hyperlinq.Benchmarks.csproj | 2 +- .../NetFabric.Hyperlinq.Immutable.csproj | 2 +- ...Hyperlinq.SourceGenerator.UnitTests.csproj | 6 +- .../TestData/Source/Dictionary.Bindings.cs | 16 +- .../TestData/Source/Distinct.ArraySegment.cs | 13 +- .../Source/Distinct.ValueEnumerable.cs | 13 +- .../TestData/Source/ExtensionMethods.cs | 1 - .../TestData/Source/Range.cs | 15 +- .../TestData/Source/Repeat.cs | 17 +- .../TestData/Source/Select.ArraySegment.cs | 20 +- .../TestData/Source/Select.ValueEnumerable.cs | 14 +- .../TestData/Source/Where.ArraySegment.cs | 15 +- .../TestData/Source/Where.ValueEnumerable.cs | 11 +- ...NetFabric.Hyperlinq.SourceGenerator.csproj | 2 +- .../OverloadsGenerator.cs | 24 +- ...lueEnumerable'1.ValueReadOnlyList.Tests.cs | 73 ++++ ...merable'6.ValueReadOnlyCollection.Tests.cs | 1 - ...lueEnumerable'6.ValueReadOnlyList.Tests.cs | 101 +++++ .../AsValueEnumerable.ReadOnlyList.Tests.cs | 156 -------- ...ValueEnumerable.ValueReadOnlyList.Tests.cs | 155 -------- .../ElementAt/ElementAt.ReadOnlyList.Tests.cs | 328 ++++++++++++++++ .../Element/First/First.ReadOnlyList.Tests.cs | 261 +++++++++++++ .../Single/Single.ReadOnlyList.Tests.cs | 368 ++++++++++++++++++ .../NetFabric.Hyperlinq.UnitTests.csproj | 6 +- .../Skip/Skip.ValueEnumerable.Tests.cs | 12 +- .../Skip.ValueReadOnlyCollection.Tests.cs | 49 ++- .../Skip/Skip.ValueReadOnlyList.Tests.cs | 77 ++++ .../Take/Take.AsyncValueEnumerable.Tests.cs | 24 ++ .../Take/Take.ValueEnumerable.Tests.cs | 32 +- .../Take.ValueReadOnlyCollection.Tests.cs | 46 +++ .../Take/Take.ValueReadOnlyList.Tests.cs | 77 ++++ .../Select/Select.ValueReadOnlyList.Tests.cs | 53 +++ .../SelectAt.ValueReadOnlyList.Tests.cs | 53 +++ .../Distinct.ValueEnumerable.Tests.cs | 20 +- .../TestData/TestData.Empty.cs | 28 ++ .../TestData/TestData.Multiple.cs | 13 + .../TestData/TestData.Single.cs | 11 + .../Wrappers/Wrap.AsAsyncValueEnumerable.cs | 8 +- .../Utils/Wrappers/Wrap.AsEnumerable.cs | 4 +- .../Utils/Wrappers/Wrap.AsValueCollection.cs | 14 +- .../Utils/Wrappers/Wrap.AsValueEnumerable.cs | 12 +- .../Utils/Wrappers/Wrap.AsValueList.cs | 28 +- .../Wrap.AsValueReadOnlyCollection.cs | 14 +- .../Wrappers/Wrap.AsValueReadOnlyList.cs | 28 +- .../Aggregation/Count/Count.ReadOnlySpan.cs | 3 +- .../Count/Count.ValueEnumerable.cs | 2 + .../Count/Count.ValueReadOnlyCollection.cs | 2 + .../Count/CountAsync.AsyncValueEnumerable.cs | 2 + .../Aggregation/Sum/Sum.Range.cs | 1 + .../Aggregation/Sum/Sum.ReadOnlySpan.cs | 9 +- .../Aggregation/Sum/Sum.ValueEnumerable.cs | 6 + .../Sum/Sum.ValueReadOnlyCollection.cs | 12 +- .../Sum/SumAsync.AsyncValueEnumerable.cs | 6 + ...sAsyncValueEnumerable'1.AsyncEnumerable.cs | 22 +- ...cValueEnumerable'1.AsyncValueEnumerable.cs | 4 +- ...sAsyncValueEnumerable'6.AsyncEnumerable.cs | 4 +- ...cValueEnumerable'6.AsyncValueEnumerable.cs | 4 +- .../AsValueEnumerable'1.Enumerable.cs | 4 +- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 39 +- .../AsValueEnumerable'1.ReadOnlyList.cs | 235 +++++++++++ .../AsValueEnumerable'1.ValueEnumerable.cs | 4 +- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 4 +- .../AsValueEnumerable'6.Enumerable.cs | 4 +- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 24 +- .../AsValueEnumerable'6.ValueEnumerable.cs | 4 +- ...lueEnumerable'6.ValueReadOnlyCollection.cs | 17 +- .../AsValueEnumerable'6.ValueReadOnlyList.cs | 306 +++++++++++++++ .../AsValueEnumerable.ArraySegment.cs | 25 +- .../AsValueEnumerable.ReadOnlyList.cs | 253 ------------ .../AsValueEnumerable.ReadOnlyMemory.cs | 44 +-- .../AsValueEnumerable.ReadOnlySpan.cs | 10 +- .../AsValueEnumerable/ValueEnumerator.cs | 2 - .../ToArray/ToArray.ReadOnlySpan.cs | 14 +- .../ToArray/ToArray.ValueEnumerable.cs | 15 +- .../ToArray.ValueReadOnlyCollection.cs | 27 +- .../ToArray/ToArray.ValueReadOnlyList.cs | 199 ---------- .../ToArrayAsync.AsyncValueEnumerable.cs | 10 + .../ToDictionary/ToDictionary.ReadOnlySpan.cs | 14 +- .../ToDictionary.ValueEnumerable.cs | 6 + .../ToDictionary.ValueReadOnlyCollection.cs | 6 + .../ToDictionary.ValueReadOnlyList.cs | 212 ---------- .../ToDictionaryAsync.AsyncValueEnumerable.cs | 6 + .../Conversion/ToList/ToList.ReadOnlySpan.cs | 7 +- .../ToList/ToList.ValueEnumerable.cs | 5 + .../ToList/ToList.ValueReadOnlyCollection.cs | 18 +- .../ToList/ToList.ValueReadOnlyList.cs | 57 --- .../ToListAsync.AsyncValueEnumerable.cs | 5 + .../ElementAt/ElementAt.ReadOnlyList.cs | 39 ++ .../ElementAt/ElementAt.ReadOnlySpan.cs | 6 +- .../ElementAt/ElementAt.ValueEnumerable.cs | 5 + .../ElementAt.ValueReadOnlyCollection.cs | 8 +- .../ElementAtAsync.AsyncValueEnumerable.cs | 5 + .../Element/First/First.ReadOnlyList.cs | 43 ++ .../Element/First/First.ReadOnlySpan.cs | 14 +- .../Element/First/First.ValueEnumerable.cs | 15 +- .../First/First.ValueReadOnlyCollection.cs | 9 +- .../First/FirstAsync.AsyncValueEnumerable.cs | 15 +- .../Element/Single/Single.ReadOnlyList.cs | 39 ++ .../Element/Single/Single.ReadOnlySpan.cs | 14 +- .../Element/Single/Single.ValueEnumerable.cs | 22 +- .../Single/Single.ValueReadOnlyCollection.cs | 7 +- .../SingleAsync.AsyncValueEnumerable.cs | 22 +- .../SequenceEqual.ReadOnlySpan.cs | 3 +- .../Where/Where/Where.ArraySegment.cs | 15 +- .../Where/Where/Where.AsyncValueEnumerable.cs | 9 +- .../Where/Where/Where.ReadOnlyMemory.cs | 37 +- .../Where/Where/Where.ReadOnlySpan.cs | 4 +- .../Where/Where/Where.ValueEnumerable.cs | 15 +- .../Where/Where.ValueReadOnlyCollection.cs | 9 +- .../Where/WhereAt/WhereAt.ArraySegment.cs | 13 +- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 7 +- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 37 +- .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 2 +- .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 9 +- .../WhereAt.ValueReadOnlyCollection.cs | 9 +- .../WhereSelect/WhereSelect.ArraySegment.cs | 28 +- .../WhereSelect.AsyncValueEnumerable.cs | 14 +- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 50 +-- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 3 +- .../WhereSelect.ValueEnumerable.cs | 16 +- .../WhereSelect.ValueReadOnlyCollection.cs | 12 +- .../Generation/AsyncValueEnumerable/Empty.cs | 13 +- .../Generation/AsyncValueEnumerable/Range.cs | 12 +- .../Generation/AsyncValueEnumerable/Repeat.cs | 15 +- .../Generation/AsyncValueEnumerable/Return.cs | 12 +- .../ValueEnumerable/CreateValueEnumerable.cs | 8 +- .../Generation/ValueEnumerable/Empty.cs | 16 +- .../Generation/ValueEnumerable/Range.cs | 68 +++- .../Generation/ValueEnumerable/Repeat.cs | 18 +- .../Generation/ValueEnumerable/Return.cs | 22 +- .../NetFabric.Hyperlinq.csproj | 6 +- NetFabric.Hyperlinq/Option/Option.cs | 66 ++-- .../Skip/Skip.AsyncValueEnumerable.cs | 21 +- ...ueReadOnlyList.cs => Skip.ReadOnlyList.cs} | 8 +- .../Partitioning/Skip/Skip.ValueEnumerable.cs | 25 +- .../Skip/Skip.ValueReadOnlyCollection.cs | 2 +- .../SkipTake/SkipTake.AsyncValueEnumerable.cs | 42 +- ...adOnlyList.cs => SkipTake.ReadOnlyList.cs} | 96 +++-- .../SkipTake/SkipTake.ValueEnumerable.cs | 43 +- .../SkipTake.ValueReadOnlyCollection.cs | 67 ++-- .../Take/Take.AsyncValueEnumerable.cs | 8 +- ...ueReadOnlyList.cs => Take.ReadOnlyList.cs} | 5 +- .../Partitioning/Take/Take.ValueEnumerable.cs | 17 +- .../Take/Take.ValueReadOnlyCollection.cs | 2 +- .../Select/Select/Select.ArraySegment.cs | 8 +- .../Select/Select.AsyncValueEnumerable.cs | 5 +- .../Select/Select/Select.ReadOnlyMemory.cs | 29 +- .../Select/Select/Select.ReadOnlySpan.cs | 2 - .../Select/Select/Select.ValueEnumerable.cs | 15 +- .../Select/Select.ValueReadOnlyCollection.cs | 3 +- .../Select/Select/Select.ValueReadOnlyList.cs | 311 +++++++++++++++ .../Select/SelectAt/SelectAt.ArraySegment.cs | 30 +- .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 5 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 29 +- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 2 - .../SelectAt/SelectAt.ValueEnumerable.cs | 15 +- .../SelectAt.ValueReadOnlyCollection.cs | 5 +- .../SelectAt/SelectAt.ValueReadOnlyList.cs | 326 ++++++++++++++++ .../SelectVector/SelectVector.ReadOnlySpan.cs | 1 - .../SelectMany/SelectMany.ArraySegment.cs | 37 +- .../SelectMany/SelectMany.ReadOnlyMemory.cs | 37 +- .../SelectMany/SelectMany.ReadOnlySpan.cs | 2 +- .../SelectMany/SelectMany.ValueEnumerable.cs | 41 +- .../Quantifier/All/All.ReadOnlySpan.cs | 4 - .../Quantifier/Any/Any.ReadOnlySpan.cs | 5 - .../Contains/Contains.Enumerable.cs | 2 + .../Contains/Contains.ReadOnlySpan.cs | 3 +- .../Contains/Contains.ValueEnumerable.cs | 2 + .../Contains.ValueReadOnlyCollection.cs | 4 +- .../ContainsAsync.AsyncValueEnumerable.cs | 25 +- .../ContainsVector.ReadOnlySpan.cs | 5 +- .../Set/Distinct/Distinct.ArraySegment.cs | 38 +- .../Distinct/Distinct.AsyncValueEnumerable.cs | 37 +- .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 61 ++- .../Set/Distinct/Distinct.ReadOnlySpan.cs | 15 +- .../Set/Distinct/Distinct.ValueEnumerable.cs | 19 +- NetFabric.Hyperlinq/Set/Distinct/Set.cs | 12 +- .../ToArrayBuilder.AsyncValueEnumerable.cs | 160 -------- ...List.cs => ToArrayBuilder.ReadOnlyList.cs} | 5 +- .../ToArrayBuilder.ReadOnlySpan.cs | 3 + .../ToArrayBuilder.ValueEnumerable.cs | 6 + ...oArrayBuilderAsync.AsyncValueEnumerable.cs | 219 ++--------- .../Utils/Copy/Copy.ValueReadOnlyList.cs | 75 ---- .../Utils/IndexOf/IndexOf.ReadOnlyList.cs | 42 -- .../Utils/IndexOf/IndexOf.ReadOnlySpan.cs | 6 +- .../IndexOf.ValueReadOnlyCollection.cs | 103 +++++ .../IndexOf/IndexOf.ValueReadOnlyList.cs | 128 ------ NetFabric.Hyperlinq/Utils/Throw.cs | 40 +- NetFabric.Hyperlinq/Utils/ThrowIfArgument.cs | 26 ++ .../Utils/Utils.AllocateUninitializedArray.cs | 3 +- NuGet.config | 3 +- 203 files changed, 4875 insertions(+), 2711 deletions(-) create mode 100644 Benchmarks/AggressiveInliningBenchmarks.md create mode 100644 Benchmarks/ListIterationBenchmarks.md create mode 100644 Benchmarks/ReadOnlyFieldsBenchmarks.md create mode 100644 NetFabric.Hyperlinq.Benchmarks/Benchmarks/AggressiveInliningBenchmarks.cs create mode 100644 NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs create mode 100644 NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReadOnlyFieldsBenchmarks.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyList.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs delete mode 100644 NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyList.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyList.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyList.Tests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyList.Tests.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs rename NetFabric.Hyperlinq/Partitioning/Skip/{Skip.ValueReadOnlyList.cs => Skip.ReadOnlyList.cs} (68%) rename NetFabric.Hyperlinq/Partitioning/SkipTake/{SkipTake.ValueReadOnlyList.cs => SkipTake.ReadOnlyList.cs} (67%) rename NetFabric.Hyperlinq/Partitioning/Take/{Take.ValueReadOnlyList.cs => Take.ReadOnlyList.cs} (70%) create mode 100644 NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs rename NetFabric.Hyperlinq/Utils/ArrayBuilder/{ToArrayBuilder.ValueReadOnlyList.cs => ToArrayBuilder.ReadOnlyList.cs} (95%) delete mode 100644 NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Utils/ThrowIfArgument.cs diff --git a/Benchmarks/AggressiveInliningBenchmarks.md b/Benchmarks/AggressiveInliningBenchmarks.md new file mode 100644 index 000000000..59c7c15fc --- /dev/null +++ b/Benchmarks/AggressiveInliningBenchmarks.md @@ -0,0 +1,29 @@ +## AggressiveInliningBenchmarks + +### Source +[AggressiveInliningBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AggressiveInliningBenchmarks.cs) + +### References: +- Linq: 6.0.0-preview.4.21253.7 +- System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) +- System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) +- System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) + +### Results: +``` ini + +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-HOBYXY : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + +Runtime=.NET 6.0 + +``` +| Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------- |------ |---------:|--------:|--------:|------:|------:|------:|------:|----------:| +| Baseline | 1000 | 609.3 ns | 5.50 ns | 5.14 ns | 1.00 | - | - | - | - | +| AggressiveInlining | 1000 | 611.9 ns | 4.64 ns | 4.34 ns | 1.00 | - | - | - | - | diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index a4488722b..6ba38545a 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -4,11 +4,11 @@ [ArrayIterationBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: @@ -16,22 +16,20 @@ BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-CGYYAC : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|----------------------------- |--------- |----------:|----------:|----------:|------:|--------:|------:|------:|------:|----------:| -| Foreach | 10000000 | 5.083 ms | 0.0922 ms | 0.1133 ms | 1.00 | 0.00 | - | - | - | 1 B | -| For | 10000000 | 5.022 ms | 0.0300 ms | 0.0266 ms | 0.98 | 0.02 | - | - | - | 2 B | -| For_Unsafe | 10000000 | 5.226 ms | 0.0301 ms | 0.0267 ms | 1.02 | 0.02 | - | - | - | 2 B | -| ForAdamczewski | 10000000 | 4.805 ms | 0.0371 ms | 0.0310 ms | 0.94 | 0.02 | - | - | - | 2 B | -| ForAdamczewskiUnsafe | 10000000 | 4.343 ms | 0.0677 ms | 0.0633 ms | 0.85 | 0.03 | - | - | - | 1 B | -| Span | 10000000 | 5.173 ms | 0.1025 ms | 0.1220 ms | 1.02 | 0.04 | - | - | - | 1 B | -| Memory | 10000000 | 5.072 ms | 0.0736 ms | 0.0723 ms | 0.99 | 0.02 | - | - | - | 1 B | -| ArraySegment_Foreach | 10000000 | 28.831 ms | 0.1434 ms | 0.1271 ms | 5.63 | 0.14 | - | - | - | 6 B | -| ArraySegment_For | 10000000 | 8.883 ms | 0.0334 ms | 0.0296 ms | 1.73 | 0.04 | - | - | - | 2 B | -| ArraySegment_Wrapper_Foreach | 10000000 | 15.390 ms | 0.0593 ms | 0.0496 ms | 3.00 | 0.08 | - | - | - | 3 B | +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|----------------------------- |-------- |-----------:|---------:|---------:|------:|--------:|------:|------:|------:|----------:| +| Foreach | 1000000 | 454.5 μs | 3.61 μs | 3.37 μs | 1.00 | 0.00 | - | - | - | - | +| For | 1000000 | 452.5 μs | 3.69 μs | 3.27 μs | 1.00 | 0.01 | - | - | - | - | +| For_Unsafe | 1000000 | 450.1 μs | 2.38 μs | 1.98 μs | 0.99 | 0.01 | - | - | - | - | +| Span | 1000000 | 452.9 μs | 2.16 μs | 1.91 μs | 1.00 | 0.01 | - | - | - | - | +| ArraySegment_Foreach | 1000000 | 2,882.3 μs | 18.69 μs | 16.57 μs | 6.34 | 0.05 | - | - | - | 1 B | +| ArraySegment_For | 1000000 | 835.7 μs | 6.87 μs | 6.43 μs | 1.84 | 0.01 | - | - | - | - | +| ArraySegment_Expanded_For | 1000000 | 1,346.8 μs | 7.64 μs | 6.77 μs | 2.96 | 0.03 | - | - | - | - | +| ArraySegment_Wrapper_Foreach | 1000000 | 1,492.8 μs | 8.99 μs | 7.51 μs | 3.29 | 0.03 | - | - | - | - | diff --git a/Benchmarks/ListIterationBenchmarks.md b/Benchmarks/ListIterationBenchmarks.md new file mode 100644 index 000000000..bfcaf687b --- /dev/null +++ b/Benchmarks/ListIterationBenchmarks.md @@ -0,0 +1,33 @@ +## ListIterationBenchmarks + +### Source +[ListIterationBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs) + +### References: +- Linq: 6.0.0-preview.4.21222.10 +- System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) +- System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) +- System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) + +### Results: +``` ini + +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.4.21227.6 + [Host] : .NET 6.0.0 (6.0.21.22210), X64 RyuJIT + Job-QJGPYZ : .NET 6.0.0 (6.0.21.22210), X64 RyuJIT + +Runtime=.NET 6.0 + +``` +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------- |-------------- |-------- |------------:|------------:|------------:|------:|--------:|------:|------:|------:|----------:| +| List_numerable | List | 1000000 | 1,987.8 μs | 113.79 μs | 335.50 μs | 1.00 | 0.00 | - | - | - | 1 B | +| List_Indexer | List | 1000000 | 1,332.8 μs | 34.49 μs | 101.71 μs | 0.69 | 0.13 | - | - | - | - | +| List_Span | List | 1000000 | 625.0 μs | 24.47 μs | 72.15 μs | 0.32 | 0.07 | - | - | - | - | +| | | | | | | | | | | | | +| ImmutableList_Enumerable | ImmutableList | 1000000 | 45,007.3 μs | 1,574.97 μs | 4,643.83 μs | 1.00 | 0.00 | - | - | - | 12 B | +| ImmutableList_Indexer | ImmutableList | 1000000 | 65,105.0 μs | 1,295.17 μs | 3,343.25 μs | 1.46 | 0.17 | - | - | - | 18 B | diff --git a/Benchmarks/ReadOnlyFieldsBenchmarks.md b/Benchmarks/ReadOnlyFieldsBenchmarks.md new file mode 100644 index 000000000..41e55ff73 --- /dev/null +++ b/Benchmarks/ReadOnlyFieldsBenchmarks.md @@ -0,0 +1,30 @@ +## ReadOnlyFieldsBenchmarks + +### Source +[ReadOnlyFieldsBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReadOnlyFieldsBenchmarks.cs) + +### References: +- Linq: 6.0.0-preview.4.21253.7 +- System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) +- System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) +- System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) +- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) + +### Results: +``` ini + +BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-NLALVJ : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + +Runtime=.NET 6.0 + +``` +| Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------ |---------:|--------:|--------:|------:|------:|------:|------:|----------:| +| Baseline | 1000 | 607.9 ns | 5.01 ns | 4.68 ns | 1.00 | - | - | - | - | +| ReadOnlyCurrent | 1000 | 610.8 ns | 6.02 ns | 5.64 ns | 1.00 | - | - | - | - | +| ReadOnlyField | 1000 | 611.9 ns | 4.35 ns | 4.07 ns | 1.01 | - | - | - | - | diff --git a/NetFabric.Hyperlinq.Abstractions/AsyncFunctionWrapper.cs b/NetFabric.Hyperlinq.Abstractions/AsyncFunctionWrapper.cs index 9ab29614a..866062a99 100644 --- a/NetFabric.Hyperlinq.Abstractions/AsyncFunctionWrapper.cs +++ b/NetFabric.Hyperlinq.Abstractions/AsyncFunctionWrapper.cs @@ -16,6 +16,9 @@ public AsyncFunctionWrapper(Func> funct [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T arg, CancellationToken cancellationToken) => function(arg, cancellationToken); + + public static implicit operator AsyncFunctionWrapper(Func> func) + => new(func); } public readonly struct AsyncFunctionWrapper @@ -29,6 +32,9 @@ public AsyncFunctionWrapper(Func> [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask InvokeAsync(T1 arg1, T2 arg2, CancellationToken cancellationToken) => function(arg1, arg2, cancellationToken); + + public static implicit operator AsyncFunctionWrapper(Func> func) + => new(func); } public readonly struct AsyncFunctionWrapper @@ -42,6 +48,9 @@ public AsyncFunctionWrapper(Func InvokeAsync(T1 arg1, T2 arg2, T3 arg3, CancellationToken cancellationToken) => function(arg1, arg2, arg3, cancellationToken); + + public static implicit operator AsyncFunctionWrapper(Func> func) + => new(func); } public readonly struct AsyncFunctionWrapper @@ -55,6 +64,9 @@ public AsyncFunctionWrapper(Func InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, cancellationToken); + + public static implicit operator AsyncFunctionWrapper(Func> func) + => new(func); } public readonly struct AsyncFunctionWrapper @@ -68,6 +80,9 @@ public AsyncFunctionWrapper(Func InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, cancellationToken); + + public static implicit operator AsyncFunctionWrapper(Func> func) + => new(func); } public readonly struct AsyncFunctionWrapper @@ -81,6 +96,9 @@ public AsyncFunctionWrapper(Func InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, arg6, cancellationToken); + + public static implicit operator AsyncFunctionWrapper(Func> func) + => new(func); } public readonly struct AsyncFunctionWrapper @@ -94,6 +112,9 @@ public AsyncFunctionWrapper(Func InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, cancellationToken); + + public static implicit operator AsyncFunctionWrapper(Func> func) + => new(func); } public readonly struct AsyncFunctionWrapper @@ -107,6 +128,9 @@ public AsyncFunctionWrapper(Func InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, cancellationToken); + + public static implicit operator AsyncFunctionWrapper(Func> func) + => new(func); } public readonly struct AsyncFunctionWrapper @@ -120,5 +144,8 @@ public AsyncFunctionWrapper(Func InvokeAsync(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, CancellationToken cancellationToken) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, cancellationToken); + + public static implicit operator AsyncFunctionWrapper(Func> func) + => new(func); } } diff --git a/NetFabric.Hyperlinq.Abstractions/FunctionInWrapper.cs b/NetFabric.Hyperlinq.Abstractions/FunctionInWrapper.cs index 3e8122c43..e91f77875 100644 --- a/NetFabric.Hyperlinq.Abstractions/FunctionInWrapper.cs +++ b/NetFabric.Hyperlinq.Abstractions/FunctionInWrapper.cs @@ -14,6 +14,9 @@ public FunctionInWrapper(FunctionIn function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(in T arg) => function(arg); + + public static implicit operator FunctionInWrapper(FunctionIn func) + => new(func); } public readonly struct FunctionInWrapper @@ -27,5 +30,8 @@ public FunctionInWrapper(FunctionIn function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(in T1 arg1, T2 arg2) => function(arg1, arg2); + + public static implicit operator FunctionInWrapper(FunctionIn func) + => new(func); } } diff --git a/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs b/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs index 3ede4fad7..7cd133f9f 100644 --- a/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs +++ b/NetFabric.Hyperlinq.Abstractions/FunctionWrapper.cs @@ -14,6 +14,9 @@ public FunctionWrapper(Func function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke() => function(); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } public readonly struct FunctionWrapper @@ -27,6 +30,9 @@ public FunctionWrapper(Func function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T arg) => function(arg); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } public readonly struct FunctionWrapper @@ -40,6 +46,9 @@ public FunctionWrapper(Func function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2) => function(arg1, arg2); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } public readonly struct FunctionWrapper @@ -53,6 +62,9 @@ public FunctionWrapper(Func function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3) => function(arg1, arg2, arg3); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } public readonly struct FunctionWrapper @@ -66,6 +78,9 @@ public FunctionWrapper(Func function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4) => function(arg1, arg2, arg3, arg4); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } public readonly struct FunctionWrapper @@ -79,6 +94,9 @@ public FunctionWrapper(Func function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) => function(arg1, arg2, arg3, arg4, arg5); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } public readonly struct FunctionWrapper @@ -92,6 +110,9 @@ public FunctionWrapper(Func function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) => function(arg1, arg2, arg3, arg4, arg5, arg6); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } public readonly struct FunctionWrapper @@ -105,6 +126,9 @@ public FunctionWrapper(Func function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } public readonly struct FunctionWrapper @@ -118,6 +142,9 @@ public FunctionWrapper(Func function) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } public readonly struct FunctionWrapper @@ -131,5 +158,8 @@ public FunctionWrapper(Func functio [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) => function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + + public static implicit operator FunctionWrapper(Func func) + => new(func); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AggressiveInliningBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AggressiveInliningBenchmarks.cs new file mode 100644 index 000000000..d33ec4e09 --- /dev/null +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AggressiveInliningBenchmarks.cs @@ -0,0 +1,82 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks +{ + public class AggressiveInliningBenchmarks + { + const int seed = 2982; + int[]? array; + + [Params(1_000)] + public int Count { get; set; } + + [GlobalSetup] + public void GlobalSetup() + => array = Utils.GetRandomValues(seed, Count); + + [Benchmark(Baseline = true)] + public int Baseline() + { + var enumerator = new Enumerator(array!); + var sum = 0; + while (enumerator.MoveNext()) + sum += enumerator.Current; + return sum; + } + + [Benchmark] + public int AggressiveInlining() + { + var enumerator = new AggressiveInliningEnumerator(array!); + var sum = 0; + while (enumerator.MoveNext()) + sum += enumerator.Current; + return sum; + } + + [StructLayout(LayoutKind.Auto)] + public struct Enumerator + { + readonly TSource[] source; + int index; + + public Enumerator(TSource[] source) + { + this.source = source; + index = -1; + } + + public readonly TSource Current + => source[index]; + + public bool MoveNext() + => ++index < source.Length; + } + + [StructLayout(LayoutKind.Auto)] + public struct AggressiveInliningEnumerator + { + readonly TSource[] source; + int index; + + public AggressiveInliningEnumerator(TSource[] source) + { + this.source = source; + index = -1; + } + + public readonly TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index < source.Length; + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs index 945c58932..d5f674ea1 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs @@ -9,17 +9,15 @@ public class ArrayIterationBenchmarks { const int seed = 2982; int[]? array; - ReadOnlyMemory memory; ArraySegment segment; - [Params(10_000_000)] + [Params(1_000_000)] public int Count { get; set; } [GlobalSetup] public void GlobalSetup() { array = Utils.GetRandomValues(seed, Count); - memory = Utils.GetRandomValues(seed, Count).AsMemory(); segment = new ArraySegment(Utils.GetRandomValues(seed, Count)); } @@ -27,6 +25,7 @@ public void GlobalSetup() public int Foreach() { var sum = 0; + // ReSharper disable once LoopCanBeConvertedToQuery foreach (var item in array!) sum += item; return sum; @@ -37,6 +36,8 @@ public int For() { var source = array!; var sum = 0; + // ReSharper disable once ForCanBeConvertedToForeach + // ReSharper disable once LoopCanBeConvertedToQuery for (var index = 0; index < source.Length; index++) { var item = source[index]; @@ -61,93 +62,91 @@ public unsafe int For_Unsafe() return sum; } - [Benchmark] - public int ForAdamczewski() - { - var source = array!; - var len = source.Length; - var sum1 = 0; - var sum2 = 0; - for (var index = 0; index < len; index += 2) - { - long i1 = index + 0; - long i2 = index + 1; - var c = source[i1]; - var d = source[i2]; - - sum1 += c; - sum2 += d; - } - return sum1 + sum2; - } - - [Benchmark] - public unsafe int ForAdamczewskiUnsafe() - { - fixed (int* source = array) - { - var len = array!.Length; - var sum1 = 0; - var sum2 = 0; - for (var index = 0; index < len; index += 2) - { - long i1 = index + 0; - long i2 = index + 1; - var c = source[i1]; - var d = source[i2]; - - sum1 += c; - sum2 += d; - } - return sum1 + sum2; - } - } + // [Benchmark] + // public int ForAdamczewski() + // { + // var source = array!; + // var len = source.Length; + // var sum1 = 0; + // var sum2 = 0; + // for (var index = 0; index < len; index += 2) + // { + // long i1 = index + 0; + // long i2 = index + 1; + // var c = source[i1]; + // var d = source[i2]; + // + // sum1 += c; + // sum2 += d; + // } + // return sum1 + sum2; + // } + // + // [Benchmark] + // public unsafe int ForAdamczewskiUnsafe() + // { + // fixed (int* source = array) + // { + // var len = array!.Length; + // var sum1 = 0; + // var sum2 = 0; + // for (var index = 0; index < len; index += 2) + // { + // long i1 = index + 0; + // long i2 = index + 1; + // var c = source[i1]; + // var d = source[i2]; + // + // sum1 += c; + // sum2 += d; + // } + // return sum1 + sum2; + // } + // } [Benchmark] public int Span() { var source = array!.AsSpan(); var sum = 0; - for (var index = 0; index < source.Length; index++) - { - var item = source[index]; + foreach (var item in source) sum += item; - } return sum; } [Benchmark] - public int Memory() + public int ArraySegment_Foreach() { - var source = memory.Span; var sum = 0; - for (var index = 0; index < source.Length; index++) - { - var item = source[index]; + // ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator + foreach (var item in segment) sum += item; - } return sum; } [Benchmark] - public int ArraySegment_Foreach() + public int ArraySegment_For() { + var source = segment; var sum = 0; - foreach (var item in segment) + for (var index = 0; index < source!.Count; index++) + { + var item = source![index]; sum += item; + } return sum; } [Benchmark] - public int ArraySegment_For() + public int ArraySegment_Expanded_For() { - var source = segment.Array; + var source = segment.Array!; var start = segment.Offset; var end = start + segment.Count; var sum = 0; - for (var index = start; index < end; index++) + for (var index = start; index < end && index < source.Length; index++) { - var item = source![index]; + var item = source[index]; sum += item; } return sum; @@ -171,7 +170,7 @@ public ArraySegmentWrapper(in ArraySegment source) => this.source = source; public Enumerator GetEnumerator() - => new(source); + => new(source.Array.AsSpan().Slice(source.Offset, source.Count)); public ref struct Enumerator { @@ -179,11 +178,11 @@ public ref struct Enumerator readonly int end; int index; - public Enumerator(in ArraySegment source) + public Enumerator(ReadOnlySpan source) { - this.source = source.Array.AsSpan().Slice(source.Offset, source.Count); + this.source = source; index = -1; - end = index + source.Count; + end = index + source.Length; } public readonly TSource Current diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs index a2a54966e..5cc87c188 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs @@ -1,7 +1,5 @@ using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; using System; -using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks { diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs new file mode 100644 index 000000000..0b1112e3a --- /dev/null +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs @@ -0,0 +1,90 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Jobs; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks +{ + [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] + [CategoriesColumn] + public class ListIterationBenchmarks + { + const int seed = 2982; + List list; + ImmutableList immutableList; + + [Params(1_000_000)] + public int Count { get; set; } + + [GlobalSetup] + public void GlobalSetup() + { + var source = Utils.GetRandomValues(seed, Count); + list = new List(source); + immutableList = ImmutableList.Create(source); + } + + [BenchmarkCategory("List")] + [Benchmark(Baseline = true)] + public int List_Enumerable() + { + var sum = 0; + foreach (var item in list) + sum += item; + return sum; + } + + [BenchmarkCategory("List")] + [Benchmark] + public int List_Indexer() + { + var source = list; + var sum = 0; + for (var index = 0; index < source.Count; index++) + { + var item = source[index]; + sum += item; + } + return sum; + } + + [BenchmarkCategory("List")] + [Benchmark] + public int List_Span() + { + var sum = 0; + foreach (var item in CollectionsMarshal.AsSpan(list)) + sum += item; + return sum; + } + + + [BenchmarkCategory("ImmutableList")] + [Benchmark(Baseline = true)] + public int ImmutableList_Enumerable() + { + var sum = 0; + foreach (var item in immutableList) + sum += item; + return sum; + } + + [BenchmarkCategory("ImmutableList")] + [Benchmark] + public int ImmutableList_Indexer() + { + var source = immutableList; + var sum = 0; + for (var index = 0; index < source.Count; index++) + { + var item = source[index]; + sum += item; + } + return sum; + } + } +} diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReadOnlyFieldsBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReadOnlyFieldsBenchmarks.cs new file mode 100644 index 000000000..7cdac5588 --- /dev/null +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReadOnlyFieldsBenchmarks.cs @@ -0,0 +1,121 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks +{ + public class ReadOnlyFieldsBenchmarks + { + const int seed = 2982; + int[]? array; + + [Params(1_000)] + public int Count { get; set; } + + [GlobalSetup] + public void GlobalSetup() + => array = Utils.GetRandomValues(seed, Count); + + [Benchmark(Baseline = true)] + public int Baseline() + { + var enumerator = new Enumerator(array!); + var sum = 0; + while (enumerator.MoveNext()) + sum += enumerator.Current; + return sum; + } + + [Benchmark] + public int ReadOnlyCurrent() + { + var enumerator = new ReadOnlyCurrentEnumerator(array!); + var sum = 0; + while (enumerator.MoveNext()) + sum += enumerator.Current; + return sum; + } + + [Benchmark] + public int ReadOnlyField() + { + var enumerator = new ReadOnlyFieldEnumerator(array!); + var sum = 0; + while (enumerator.MoveNext()) + sum += enumerator.Current; + return sum; + } + + [StructLayout(LayoutKind.Auto)] + public struct Enumerator + { + // ReSharper disable once FieldCanBeMadeReadOnly.Local + TSource[] source; + int index; + + public Enumerator(TSource[] source) + { + this.source = source; + index = -1; + } + + public TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index < source.Length; + } + + [StructLayout(LayoutKind.Auto)] + public struct ReadOnlyCurrentEnumerator + { + // ReSharper disable once FieldCanBeMadeReadOnly.Local + TSource[] source; + int index; + + public ReadOnlyCurrentEnumerator(TSource[] source) + { + this.source = source; + index = -1; + } + + public readonly TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index < source.Length; + } + + [StructLayout(LayoutKind.Auto)] + public struct ReadOnlyFieldEnumerator + { + readonly TSource[] source; + int index; + + public ReadOnlyFieldEnumerator(TSource[] source) + { + this.source = source; + index = -1; + } + + public readonly TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index < source.Length; + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index cee2d5647..d8b1e4e01 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -18,7 +18,7 @@ - + diff --git a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj index 6900f3537..c3beabc44 100644 --- a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj +++ b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj @@ -36,7 +36,7 @@ all runtime; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj index f4c4fe6cb..da6cbd6b3 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj @@ -7,9 +7,9 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs index bda5fd24c..68137e488 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs @@ -18,18 +18,22 @@ public readonly partial struct ValueWrapper public ValueWrapper(Dictionary source) => this.source = source; - public readonly int Count + public int Count => source.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Dictionary.Enumerator GetEnumerator() - => source.GetEnumerator(); - readonly IEnumerator> IEnumerable>.GetEnumerator() - => source.GetEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + public Dictionary.Enumerator GetEnumerator() => source.GetEnumerator(); + IEnumerator> IEnumerable>.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => GetEnumerator(); + bool ICollection>.IsReadOnly => true; diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs index 2e62b0118..a950046e1 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs @@ -17,13 +17,18 @@ public readonly partial struct ArraySegmentDistinctEnumerable internal ArraySegmentDistinctEnumerable(in ArraySegment source) => this.source = source; - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(); - readonly DisposableEnumerator IValueEnumerable.DisposableEnumerator>.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); public struct Enumerator diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs index c4991b161..493f1a6f3 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs @@ -21,13 +21,18 @@ public readonly partial struct DistinctEnumerable this.source = source; - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(); - readonly DisposableEnumerator IValueEnumerable.DisposableEnumerator>.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); public struct Enumerator diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs index 1f4fdfdab..629a8d4f2 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs @@ -7,7 +7,6 @@ public static class ExtensionMethods { public static void NotConstrainedExtensionMethod(this ArraySegment _) { } - [GeneratorIgnore(false)] static void NotIgnoredExtensionMethod(this TEnumerable _) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs index f7be13ddb..c2659d429 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs @@ -24,16 +24,21 @@ internal RangeEnumerable(int start, int count) end = checked(start + count); } - public readonly int Count { get; } + public int Count { get; } - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); bool ICollection.IsReadOnly diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs index e89ca1727..4a343102c 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs @@ -32,18 +32,21 @@ internal RepeatEnumerable(TSource value, int count) this.count = count; } - public readonly int Count + public int Count => count; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); @@ -92,7 +95,7 @@ internal Enumerator(in RepeatEnumerable enumerable) end = counter + enumerable.Count; } - public readonly TSource Current { get; } + public TSource Current { get; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() @@ -113,7 +116,7 @@ internal DisposableEnumerator(in RepeatEnumerable enumerable) end = counter + enumerable.Count; } - public readonly TSource Current { get; } + public TSource Current { get; } readonly TSource IEnumerator.Current => Current; readonly object? IEnumerator.Current diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs index 1bf08457f..b943fa420 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs @@ -7,12 +7,10 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] static ArraySegmentSelectEnumerable> Select(this in ArraySegment source, Func selector) => Select>(source, new FunctionWrapper(selector)); - [GeneratorIgnore(false)] static ArraySegmentSelectEnumerable Select(this in ArraySegment source, TSelector selector = default) where TSelector : struct, IFunction => new(source, selector); @@ -29,7 +27,7 @@ public readonly partial struct ArraySegmentSelectEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); - public readonly int Count + public int Count => 0; bool ICollection.IsReadOnly @@ -52,7 +50,7 @@ void IList.Insert(int index, TResult item) void IList.RemoveAt(int index) => throw new NotSupportedException(); - public readonly TResult this[int index] + public TResult this[int index] => default!; TResult IReadOnlyList.this[int index] => this[index]; @@ -62,13 +60,18 @@ TResult IList.this[int index] set => throw new NotSupportedException(); } - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(); - readonly DisposableEnumerator IValueEnumerable.DisposableEnumerator>.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); public struct Enumerator @@ -79,7 +82,6 @@ public struct DisposableEnumerator : IEnumerator { public readonly TResult Current => default!; - readonly TResult IEnumerator.Current => default!; readonly object IEnumerator.Current => default!; public bool MoveNext() diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs index eedd76337..022d483f3 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs @@ -31,13 +31,18 @@ public readonly partial struct SelectEnumerable (this.source, this.selector) = (source, selector); - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(); - readonly DisposableEnumerator IValueEnumerable.DisposableEnumerator>.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); public struct Enumerator @@ -48,7 +53,6 @@ public struct DisposableEnumerator : IEnumerator { public readonly TResult Current => default!; - readonly TResult IEnumerator.Current => default!; readonly object IEnumerator.Current => default!; public bool MoveNext() diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs index db226e601..9b5686549 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs @@ -6,12 +6,10 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) => Where(source, new FunctionWrapper(predicate)); - [GeneratorIgnore(false)] static ArraySegmentWhereEnumerable Where(this in ArraySegment source, TPredicate predicate = default) where TPredicate : struct, IFunction => new(source, predicate); @@ -26,13 +24,18 @@ public readonly partial struct ArraySegmentWhereEnumerable internal ArraySegmentWhereEnumerable(in ArraySegment source, TPredicate predicate) => (this.source, this.predicate) = (source, predicate); - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(); - readonly DisposableEnumerator IValueEnumerable.DisposableEnumerator>.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); public struct Enumerator diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs index 2db759a15..6d5a8dcc0 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs @@ -30,14 +30,17 @@ public readonly partial struct WhereEnumerable (this.source, this.predicate) = (source, predicate); - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(); - readonly DisposableEnumerator IValueEnumerable.DisposableEnumerator>.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(); diff --git a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj index 991562703..e6b2bb746 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj @@ -10,7 +10,7 @@ - + all diff --git a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs index d3b2ddc0f..0e66284c7 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs @@ -52,16 +52,6 @@ public void Execute(GeneratorExecutionContext context) } } - bool ConsiderExtensionMethod(IMethodSymbol symbol, CompilationContext context) - { - var attribute = symbol.GetIgnoreAttribute(context); - return attribute switch - { - null => symbol.IsPublic(), - _ => !attribute.Value - }; - } - /// /// Collects all the extension methods defined /// @@ -76,15 +66,19 @@ internal DictionarySet CollectExtensionMethods(CompilationCo .GetAllTypes() .Where(typeSymbol => typeSymbol.IsStatic - && typeSymbol.IsPublic()) + && typeSymbol.IsPublic() + ) .SelectMany(typeSymbol => typeSymbol.GetMembers() .OfType() .Where(methodSymbol => - methodSymbol.IsExtensionMethod - && ConsiderExtensionMethod(methodSymbol, context))); + methodSymbol.IsExtensionMethod + //&& methodSymbol.IsPublic() + && !methodSymbol.ShouldIgnore(context) + ) + ); - // go through all extension methods and store the ones where the extended type is a constrained generic parameter + // go through all extension methods foreach (var extensionMethod in extensionMethods) { var extensionType = extensionMethod.Parameters[0].Type; @@ -106,12 +100,14 @@ internal DictionarySet CollectExtensionMethods(CompilationCo } else { + // the extended type is a constrained generic parameter var extendingType = generic.ConstraintTypes[0]; var name = extendingType.OriginalDefinition.MetadataName; switch (name) { case "IValueEnumerable`2": case "IValueReadOnlyCollection`2": + case "IValueReadOnlyList`2": case "IReadOnlyList`1": case "IAsyncValueEnumerable`2": collectedExtensionMethods.Add(name, extensionMethod.GetInfo(context, 1)); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyList.Tests.cs new file mode 100644 index 000000000..0b443cb83 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyList.Tests.cs @@ -0,0 +1,73 @@ +using System.Linq; +using NetFabric.Assertive; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ValueReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueReadOnlyList1_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + + // Act + var result = wrapped + .AsValueEnumerable(); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueReadOnlyList1_Count_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Count(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueReadOnlyList1_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Sum(); + + // Act + var result = wrapped + .AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs index fd662cde5..36089a9a5 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs @@ -1,6 +1,5 @@ using System.Linq; using NetFabric.Assertive; -using System.Collections.Generic; using Xunit; namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.Tests.cs new file mode 100644 index 000000000..55b702568 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.Tests.cs @@ -0,0 +1,101 @@ +using System.Linq; +using NetFabric.Assertive; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable +{ + public partial class ValueReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(source); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Count_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Count(); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()) + .Count(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void AsValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Sum(); + + // Act + var result = ValueEnumerableExtensions + .AsValueEnumerable, Wrap.Enumerator, int>( + wrapped, + enumerable => enumerable.GetEnumerator()) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs deleted file mode 100644 index 73cd22e55..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.Tests.cs +++ /dev/null @@ -1,156 +0,0 @@ -using NetFabric.Assertive; -using Xunit; -using System.Collections.Generic; -using System.Linq; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable -{ - public class ReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - - // Act - var result = wrapped - .AsValueEnumerable(); - - // Assert - _ = result.Must() - .BeOfType, int>>() - .BeEnumerableOf() - .BeEqualTo(wrapped); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .ToArray(); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] - public void AsValueEnumerable_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(count0) - .Skip(count1); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(count0) - .Skip(count1); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Take(count0) - .Take(count1); - - // Act - var result = wrapped - .AsValueEnumerable() - .Take(count0) - .Take(count1); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Count(); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap - .AsReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Sum(); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs deleted file mode 100644 index aa5fb3631..000000000 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ValueReadOnlyList.Tests.cs +++ /dev/null @@ -1,155 +0,0 @@ -using NetFabric.Assertive; -using Xunit; -using System.Linq; - -namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable -{ - public class ValueReadOnlyListTests - { - [Theory] - [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ValidData_Must_Succeed(int[] source) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - - // Act - var result = wrapped - .AsValueEnumerable(); - - // Assert - _ = result.Must() - .BeOfType, int>>() - .BeEnumerableOf() - .BeEqualTo(wrapped); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable_With_ToArray_Must_Succeed(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .ToArray(); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .ToArray(); - - // Assert - _ = result.Must() - .BeArrayOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] - public void AsValueEnumerable_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Skip(count0) - .Skip(count1); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(count0) - .Skip(count1); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Take(count0) - .Take(count1); - - // Act - var result = wrapped - .AsValueEnumerable() - .Take(count0) - .Take(count1); - - // Assert - _ = result.Must() - .BeEnumerableOf() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Count_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Count(); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Count(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - - [Theory] - [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] - [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] - public void AsValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount) - { - // Arrange - var wrapped = Wrap - .AsValueReadOnlyList(source); - var expected = source - .Skip(skipCount) - .Take(takeCount) - .Sum(); - - // Act - var result = wrapped - .AsValueEnumerable() - .Skip(skipCount) - .Take(takeCount) - .Sum(); - - // Assert - _ = result.Must() - .BeEqualTo(expected); - } - } -} diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs new file mode 100644 index 000000000..799899e46 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs @@ -0,0 +1,328 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Element.ElementAt +{ + public class ReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void ElementAt_With_OutOfRange_Must_Return_None(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var optionNegative = wrapped.AsValueEnumerable() + .ElementAt(-1); + var optionTooLarge = wrapped.AsValueEnumerable() + .ElementAt(source.Length); + + // Assert + _ = optionNegative.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + _ = optionTooLarge.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void ElementAt_With_ValidData_Must_Return_Some(int[] source) + { + for (var index = 0; index < source.Length; index++) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .ElementAt(index); + + // Act + var result = wrapped.AsValueEnumerable() + .ElementAt(index); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var optionNegative = wrapped.AsValueEnumerable() + .Where(predicate) + .ElementAt(-1); + var optionTooLarge = wrapped.AsValueEnumerable() + .Where(predicate) + .ElementAt(source.Length); + + // Assert + _ = optionNegative.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + _ = optionTooLarge.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void ElementAt_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Where(predicate) + .ToList(); + + for (var index = 0; index < expected.Count; index++) + { + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .ElementAt(index); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected[index]), + () => throw new Exception()); + } + } + + [Theory] + [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] + public void ElementAt_PredicateAt_With_OutOfRange_Must_Return_None(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var optionNegative = wrapped.AsValueEnumerable() + .Where(predicate) + .ElementAt(-1); + var optionTooLarge = wrapped.AsValueEnumerable() + .Where(predicate) + .ElementAt(source.Length); + + // Assert + _ = optionNegative.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + _ = optionTooLarge.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] + public void ElementAt_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Where(predicate) + .ToList(); + + for (var index = 0; index < expected.Count; index++) + { + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .ElementAt(index); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected[index]), + () => throw new Exception()); + } + } + + [Theory] + [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] + public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var optionNegative = wrapped.AsValueEnumerable() + .Select(selector) + .ElementAt(-1); + var optionTooLarge = wrapped.AsValueEnumerable() + .Select(selector) + .ElementAt(source.Length); + + // Assert + _ = optionNegative.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + _ = optionTooLarge.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] + public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Select(selector) + .ToList(); + + for (var index = 0; index < source.Length; index++) + { + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .ElementAt(index); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected[index]), + () => throw new Exception()); + } + } + + [Theory] + [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] + public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var optionNegative = wrapped.AsValueEnumerable() + .Select(selector) + .ElementAt(-1); + var optionTooLarge = wrapped.AsValueEnumerable() + .Select(selector) + .ElementAt(source.Length); + + // Assert + _ = optionNegative.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + _ = optionTooLarge.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] + public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Select(selector) + .ToList(); + + for (var index = 0; index < source.Length; index++) + { + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .ElementAt(index); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected[index]), + () => throw new Exception()); + } + } + + [Theory] + [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] + public void ElementAt_Predicate_Selector_With_OutOfRange_Must_Return_None(int[] source, Func predicate, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var optionNegative = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(selector) + .ElementAt(-1); + var optionTooLarge = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(selector) + .ElementAt(source.Length); + + // Assert + _ = optionNegative.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + _ = optionTooLarge.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] + public void ElementAt_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Where(predicate) + .Select(selector) + .ToList(); + + for (var index = 0; index < expected.Count; index++) + { + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(selector) + .ElementAt(index); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected[index]), + () => throw new Exception()); + } + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs new file mode 100644 index 000000000..8e497a8ab --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs @@ -0,0 +1,261 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Element.First +{ + public class ReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + public void First_With_Empty_Must_Return_None(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .First(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void First_With_ValidData_Must_Return_Some(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .First(); + + // Act + var result = wrapped.AsValueEnumerable() + .First(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + public void First_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .First(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .First(predicate); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .First(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] + public void First_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .First(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] + public void First_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Where(predicate) + .First(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .First(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] + public void First_Selector_With_Empty_Must_Return_None(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .First(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] + public void First_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Select(selector) + .First(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .First(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] + public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .First(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] + public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Select(selector) + .First(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .First(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] + public void First_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(selector) + .First(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] + public void First_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Where(predicate) + .Select(selector) + .First(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(selector) + .First(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs new file mode 100644 index 000000000..0350e1693 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs @@ -0,0 +1,368 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Element.Single +{ + public class ReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + public void Single_With_Empty_Must_Return_None(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + public void Single_With_Single_Must_Return_Some(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Single(); + + // Act + var result = wrapped.AsValueEnumerable() + .Single(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Single_With_Multiple_Must_Return_None(int[] source) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] + public void Single_Predicate_With_Empty_Must_Return_None(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] + public void Single_Predicate_With_Single_Must_Return_Some(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Single(predicate); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Single(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] + public void Single_Predicate_With_Multiple_Must_Return_None(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] + public void Single_PredicateAt_With_Empty_Must_Return_None(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] + public void Single_PredicateAt_With_Single_Must_Return_Some(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Where(predicate) + .Single(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Single(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] + public void Single_PredicateAt_With_Multiple_Must_Return_None(int[] source, Func predicate) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] + public void Single_Selector_With_Empty_Must_Return_None(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] + public void Single_Selector_With_Single_Must_Return_Some(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = + source.Select(selector).Single(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .Single(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] + public void Single_Selector_With_Multiple_Must_Return_None(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] + public void Single_SelectorAt_With_Empty_Must_Return_None(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] + public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Select(selector) + .Single(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .Single(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] + public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] + public void Single_Predicate_Selector_With_Empty_Must_Return_None(int[] source, Func predicate, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(selector) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + + [Theory] + [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] + public void Single_Predicate_Selector_With_Single_Must_Return_Some(int[] source, Func predicate, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + var expected = source + .Where(predicate) + .Select(selector) + .Single(); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(selector) + .Single(); + + // Assert + _ = result.Match( + value => value.Must().BeEqualTo(expected), + () => throw new Exception()); + } + + [Theory] + [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] + public void Single_Predicate_Selector_With_Multiple_Must_Return_None(int[] source, Func predicate, Func selector) + { + // Arrange + var wrapped = Wrap + .AsValueList(source); + + // Act + var result = wrapped.AsValueEnumerable() + .Where(predicate) + .Select(selector) + .Single(); + + // Assert + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsNone); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj index 3c4481d54..ee0d1d49e 100644 --- a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj +++ b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj @@ -10,9 +10,9 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs index 763235721..3bebb91c3 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs @@ -19,8 +19,8 @@ public void Skip_With_ValidData_Must_Succeed(int[] source, int count) .Skip(count); // Act - var result = wrapped - .Skip, Wrap.Enumerator, int>(count); + var result = wrapped.AsValueEnumerable() + .Skip(count); // Assert _ = result.Must() @@ -40,8 +40,8 @@ public void Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int .Skip( count1); // Act - var result = wrapped - .Skip, Wrap.Enumerator, int>(count0) + var result = wrapped.AsValueEnumerable() + .Skip(count0) .Skip(count1); // Assert @@ -64,8 +64,8 @@ public void Skip_Take_With_ValidData_Must_Succeed(int[] source, int skip, int ta .Take(take); // Act - var result = wrapped - .Skip, Wrap.Enumerator, int>(skip) + var result = wrapped.AsValueEnumerable() + .Skip(skip) .Take(take); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs index 826e183e3..f1057fcf8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs @@ -19,7 +19,54 @@ public void Skip_With_ValidData_Must_Succeed(int[] source, int count) .Skip(count); // Act - var result = wrapped.AsValueEnumerable().Skip(count); + var result = wrapped.AsValueEnumerable() + .Skip(count); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] + public void Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Skip(count0) + .Skip(count1); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(count0) + .Skip(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void Skip_Take_With_ValidData_Must_Succeed(int[] source, int skip, int take) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Skip(skip) + .Take(take); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(skip) + .Take(take); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyList.Tests.cs new file mode 100644 index 000000000..fd830e303 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyList.Tests.cs @@ -0,0 +1,77 @@ +using NetFabric.Assertive; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Skip +{ + public class ValueReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.SkipEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipMultiple), MemberType = typeof(TestData))] + public void Skip_With_ValidData_Must_Succeed(int[] source, int count) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(count); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(count); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Skip_Skip), MemberType = typeof(TestData))] + public void Skip_Skip_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(count0) + .Skip(count1); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(count0) + .Skip(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SkipTakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SkipTakeMultiple), MemberType = typeof(TestData))] + public void Skip_Take_With_ValidData_Must_Succeed(int[] source, int skip, int take) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Skip(skip) + .Take(take); + + // Act + var result = wrapped.AsValueEnumerable() + .Skip(skip) + .Take(take); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs index cb28579cb..872fea42b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs @@ -49,5 +49,29 @@ public void Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int .BeAsyncEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.TakeSkipEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSkipSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSkipMultiple), MemberType = typeof(TestData))] + public void Take_Skip_With_ValidData_Must_Succeed(int[] source, int take, int skip) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Take(take) + .Skip(skip); + + // Act + var result = wrapped.AsValueEnumerable() + .Take(take) + .Skip(skip); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs index 7ebaa007f..af583f1b7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs @@ -19,8 +19,8 @@ public void Take_With_ValidData_Must_Succeed(int[] source, int count) .Take(count); // Act - var result = wrapped - .Take, Wrap.Enumerator, int>(count); + var result = wrapped.AsValueEnumerable() + .Take(count); // Assert _ = result.Must() @@ -39,8 +39,8 @@ public void Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int .Take(count1); // Act - var result = wrapped - .Take, Wrap.Enumerator, int>(count0) + var result = wrapped.AsValueEnumerable() + .Take(count0) .Take(count1); // Assert @@ -48,5 +48,29 @@ public void Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.TakeSkipEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSkipSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSkipMultiple), MemberType = typeof(TestData))] + public void Take_Skip_With_ValidData_Must_Succeed(int[] source, int take, int skip) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Take(take) + .Skip(skip); + + // Act + var result = wrapped.AsValueEnumerable() + .Take(take) + .Skip(skip); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs index e9053f0b8..022a8c5ea 100644 --- a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs @@ -27,5 +27,51 @@ public void Take_With_ValidData_Must_Succeed(int[] source, int count) .BeEnumerableOf() .BeEqualTo(expected); } + + [Theory] + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyCollection(source); + var expected = source + .Take(count0) + .Take(count1); + + // Act + var result = wrapped.AsValueEnumerable() + .Take(count0) + .Take(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.TakeSkipEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSkipSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSkipMultiple), MemberType = typeof(TestData))] + public void Take_Skip_With_ValidData_Must_Succeed(int[] source, int take, int skip) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Take(take) + .Skip(skip); + + // Act + var result = wrapped.AsValueEnumerable() + .Take(take) + .Skip(skip); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyList.Tests.cs new file mode 100644 index 000000000..3d55a108a --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyList.Tests.cs @@ -0,0 +1,77 @@ +using NetFabric.Assertive; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Partitioning.Take +{ + public class ValueReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.TakeEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeMultiple), MemberType = typeof(TestData))] + public void Take_With_ValidData_Must_Succeed(int[] source, int count) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Take(count); + + // Act + var result = wrapped.AsValueEnumerable() + .Take(count); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Take_Take), MemberType = typeof(TestData))] + public void Take_Take_With_ValidData_Must_Succeed(int[] source, int count0, int count1) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Take(count0) + .Take(count1); + + // Act + var result = wrapped.AsValueEnumerable() + .Take(count0) + .Take(count1); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.TakeSkipEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSkipSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.TakeSkipMultiple), MemberType = typeof(TestData))] + public void Take_Skip_With_ValidData_Must_Succeed(int[] source, int take, int skip) + { + // Arrange + var wrapped = Wrap + .AsValueReadOnlyList(source); + var expected = source + .Take(take) + .Skip(skip); + + // Act + var result = wrapped.AsValueEnumerable() + .Take(take) + .Skip(skip); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyList.Tests.cs new file mode 100644 index 000000000..8de01e3b1 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyList.Tests.cs @@ -0,0 +1,53 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Projection.Select +{ + public class ValueReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] + public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyList(source); + var expected = source + .Select(selector); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyList(source); + var expected = source + .Select(item => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(item => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyList.Tests.cs new file mode 100644 index 000000000..32643b3d1 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyList.Tests.cs @@ -0,0 +1,53 @@ +using NetFabric.Assertive; +using System; +using System.Linq; +using Xunit; + +namespace NetFabric.Hyperlinq.UnitTests.Projection.SelectAt +{ + public class ValueReadOnlyListTests + { + [Theory] + [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] + public void Select_With_ValidData_Must_Succeed(int[] source, Func selector) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyList(source); + var expected = source + .Select(selector); + + // Act + var result = wrapped.AsValueEnumerable() + .Select(selector); + + // Assert + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] + [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] + public void Select_Sum_With_ValidData_Must_Succeed(int[] source) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyList(source); + var expected = source + .Select((item, _) => item) + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Select((item, _) => item) + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs index 5066776eb..78ebb3e45 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs @@ -19,8 +19,8 @@ public void Distinct_With_ValidData_Must_Succeed(int[] source) .Distinct(); // Act - var result = wrapped - .Distinct, Wrap.Enumerator, int>(); + var result = wrapped.AsValueEnumerable() + .Distinct(); // Assert _ = result.Must() @@ -41,8 +41,8 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source) .ToArray(); // Act - var result = wrapped - .Distinct, Wrap.Enumerator, int>() + var result = wrapped.AsValueEnumerable() + .Distinct() .ToArray(); // Assert @@ -65,8 +65,8 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source .ToArray(); // Act - using var result = wrapped - .Distinct, Wrap.Enumerator, int>() + using var result = wrapped.AsValueEnumerable() + .Distinct() .ToArray(pool); // Assert @@ -87,8 +87,8 @@ public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source) .ToList(); // Act - var result = wrapped - .Distinct, Wrap.Enumerator, int>() + var result = wrapped.AsValueEnumerable() + .Distinct() .ToList(); // Assert @@ -110,8 +110,8 @@ public void Distinct_Sum_With_ValidData_Must_Succeed(int[] source) .Sum(); // Act - var result = wrapped - .Distinct, Wrap.Enumerator, int>() + var result = wrapped.AsValueEnumerable() + .Distinct() .Sum(); // Assert diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs index 6edd1e225..b9cab86e8 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs @@ -69,6 +69,34 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 9, 9 } }; + public static TheoryData TakeSkipEmpty => + new() + { + { Array.Empty(), -1, -1 }, + { Array.Empty(), -1, 0 }, + { Array.Empty(), 0, -1 }, + { Array.Empty(), 0, 0 }, + { Array.Empty(), 9, 0 }, + { Array.Empty(), 0, 1 }, + { Array.Empty(), 9, 1 }, + + { new[] { 1 }, -1, -1 }, + { new[] { 1 }, -1, 0 }, + { new[] { 1 }, 0, -1 }, + { new[] { 1 }, 0, 0 }, + { new[] { 1 }, 0, 1 }, + { new[] { 1 }, 9, 1 }, + + { new[] { 1, 2, 3, 4, 5 }, -1, -1 }, + { new[] { 1, 2, 3, 4, 5 }, -1, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 0, -1 }, + { new[] { 1, 2, 3, 4, 5 }, -1, 2 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 2 }, + { new[] { 1, 2, 3, 4, 5 }, 0, 9 }, + { new[] { 1, 2, 3, 4, 5 }, 9, 9 } + }; + public static TheoryData> PredicateEmpty => new() { diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs index 84bb7075a..ffc15736a 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs @@ -43,6 +43,19 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 2, 9 } }; + public static TheoryData TakeSkipMultiple => + new() + { + { new[] { 1, 2, 3, 4, 5 }, 2, -1 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 5, -1 }, + { new[] { 1, 2, 3, 4, 5 }, 5, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 5, 2 }, + { new[] { 1, 2, 3, 4, 5 }, 9, -1 }, + { new[] { 1, 2, 3, 4, 5 }, 9, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 9, 2 } + }; + public static TheoryData> PredicateMultiple => new() { diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs index d316e93cc..dc39352e7 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs @@ -42,6 +42,17 @@ public static partial class TestData { new[] { 1, 2, 3, 4, 5 }, 4, 1 } }; + public static TheoryData TakeSkipSingle => + new() + { + { new[] { 1 }, 1, -1 }, + { new[] { 1 }, 1, 0 }, + + { new[] { 1, 2, 3, 4, 5 }, 1, -1 }, + { new[] { 1, 2, 3, 4, 5 }, 1, 0 }, + { new[] { 1, 2, 3, 4, 5 }, 2, 1 }, + }; + public static TheoryData> PredicateSingle => new() { diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs index 94b2302bd..cd44977d7 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs @@ -22,11 +22,13 @@ public readonly struct AsyncValueEnumerableWrapper internal AsyncValueEnumerableWrapper(T[] source) => this.source = source; - public readonly AsyncEnumerator GetAsyncEnumerator() + public AsyncEnumerator GetAsyncEnumerator() => new(source); - readonly AsyncEnumerator IAsyncValueEnumerable>.GetAsyncEnumerator(CancellationToken _) + + AsyncEnumerator IAsyncValueEnumerable>.GetAsyncEnumerator(CancellationToken _) => new(source); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source); diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs index 0f0c10a67..088e62d28 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs @@ -27,10 +27,10 @@ public Enumerator GetEnumerator() => new(source); IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); + => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); + => GetEnumerator(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public EnumerableExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs index 3de26eaf1..d09834452 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs @@ -23,17 +23,19 @@ public readonly struct ValueCollectionWrapper internal ValueCollectionWrapper(T[] source) => this.source = source; - public readonly int Count + public int Count => source.Length; - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() + => GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); + => GetEnumerator(); public bool IsReadOnly => true; diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs index 9abf009dd..efa262bde 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs @@ -22,14 +22,16 @@ public readonly struct ValueEnumerableWrapper internal ValueEnumerableWrapper(T[] source) => this.source = source; - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() + => GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); + => GetEnumerator(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs index af4e509cd..ef1f3889b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs @@ -23,10 +23,10 @@ public readonly struct ValueListWrapper internal ValueListWrapper(T[] source) => this.source = source; - public readonly int Count + public int Count => source.Length; - public readonly T this[int index] + public T this[int index] => source[index]; T IList.this[int index] @@ -35,14 +35,16 @@ T IList.this[int index] set => throw new NotSupportedException(); } - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() + => GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); + => GetEnumerator(); public bool IsReadOnly => true; @@ -68,8 +70,16 @@ void IList.RemoveAt(int index) => throw new NotSupportedException(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() - => this.AsValueEnumerable, T>(); + public ValueReadOnlyListExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() + => ValueReadOnlyListExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); + + public readonly struct GetEnumeratorFunction + : IFunction, Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator Invoke(ValueListWrapper enumerable) + => enumerable.GetEnumerator(); + } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs index 82830591f..26ff0ffbc 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs @@ -22,17 +22,19 @@ public readonly struct ValueReadOnlyCollectionWrapper internal ValueReadOnlyCollectionWrapper(T[] source) => this.source = source; - public readonly int Count + public int Count => source.Length; - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() + => GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); + => GetEnumerator(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReadOnlyCollectionExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs index c525dc088..8882b862e 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs @@ -22,24 +22,34 @@ public readonly struct ValueReadOnlyListWrapper internal ValueReadOnlyListWrapper(T[] source) => this.source = source; - public readonly int Count + public int Count => source.Length; - public readonly T this[int index] + public T this[int index] => source[index]; - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() + => GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation - => new Enumerator(source); + => GetEnumerator(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() - => this.AsValueEnumerable, T>(); + public ValueReadOnlyListExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() + => ValueReadOnlyListExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); + + public readonly struct GetEnumeratorFunction + : IFunction, Enumerator> + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator Invoke(ValueReadOnlyListWrapper enumerable) + => enumerable.GetEnumerator(); + } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs index 0d3687419..f73369e65 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs @@ -5,11 +5,11 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static int Count(this ReadOnlySpan source) => source.Length; + [GeneratorIgnore] static int Count(this ReadOnlySpan source, TPredicate predicate) where TPredicate: struct, IFunction { @@ -21,6 +21,7 @@ static int Count(this ReadOnlySpan source, TPredic return counter; } + [GeneratorIgnore] static int CountAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate: struct, IFunction { diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs index 85159bc7d..f68b1c0b9 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs @@ -18,6 +18,7 @@ public static int Count(this TEnumerable sour return counter; } + [GeneratorIgnore] internal static int Count(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -33,6 +34,7 @@ internal static int Count(this TE return counter; } + [GeneratorIgnore] internal static int CountAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs index d8bcbaf2b..18c918af3 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs @@ -9,6 +9,7 @@ public static int Count(this TEnumerable sour where TEnumerator : struct, IEnumerator => source.Count; + [GeneratorIgnore] static int Count(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -19,6 +20,7 @@ static int Count(this TEnumerable _ => ValueEnumerableExtensions.Count(source, predicate) }; + [GeneratorIgnore] static int CountAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs index a76cd224a..debe9ac3d 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs @@ -27,6 +27,7 @@ public static async ValueTask CountAsync return counter; } + [GeneratorIgnore] static async ValueTask CountAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -52,6 +53,7 @@ static async ValueTask CountAsync CountAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs index 03bf9f08f..a84a82a13 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs @@ -9,6 +9,7 @@ public static partial class ValueEnumerable static int SumRange(int start, int count) => count * (start + start + count) / 2; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static unsafe TResult SumRange(int start, int count, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs index a64ae75b8..d20c6b794 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs @@ -6,7 +6,8 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - + + [GeneratorIgnore] static TSource Sum(this ReadOnlySpan source) where TSource : struct { @@ -38,6 +39,7 @@ static TSource Sum(this ReadOnlySpan source) return sum; } + [GeneratorIgnore] static TResult Sum(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction @@ -82,6 +84,7 @@ static TSum Sum(this ReadOnlySpan source) return sum; } + [GeneratorIgnore] static TSum Sum(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction where TSum : struct @@ -95,6 +98,7 @@ static TSum Sum(this ReadOnlySpan source, TP return sum; } + [GeneratorIgnore] static TSum SumAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction where TSum : struct @@ -109,6 +113,7 @@ static TSum SumAt(this ReadOnlySpan source, return sum; } + [GeneratorIgnore] static TSum Sum(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction where TSum : struct @@ -119,6 +124,7 @@ static TSum Sum(this ReadOnlySpan so return sum; } + [GeneratorIgnore] static TSum SumAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction where TSum : struct @@ -132,6 +138,7 @@ static TSum SumAt(this ReadOnlySpan return sum; } + [GeneratorIgnore] static TSum Sum(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs index e12e9aec3..8f1326fce 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs @@ -4,6 +4,7 @@ namespace NetFabric.Hyperlinq { public static partial class ValueEnumerableExtensions { + [GeneratorIgnore] internal static TSum Sum(this TEnumerable source) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -16,6 +17,7 @@ internal static TSum Sum(this TEnumerab return sum; } + [GeneratorIgnore] internal static TSum Sum(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -33,6 +35,7 @@ internal static TSum Sum(th return sum; } + [GeneratorIgnore] internal static TSum SumAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -50,6 +53,7 @@ internal static TSum SumAt( return sum; } + [GeneratorIgnore] internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -66,6 +70,7 @@ internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -82,6 +87,7 @@ internal static TSum SumAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs index c4612eb8f..be0c80100 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs @@ -4,7 +4,8 @@ namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyCollectionExtensions { - static TSum Sum(this TEnumerable source) + [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSum : struct @@ -14,6 +15,7 @@ static TSum Sum(this TEnumerable source _ => ValueEnumerableExtensions.Sum(source) }; + [GeneratorIgnore] static TSum Sum(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -25,6 +27,7 @@ static TSum Sum(this TEnume _ => ValueEnumerableExtensions.Sum(source, predicate) }; + [GeneratorIgnore] static TSum SumAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -36,7 +39,8 @@ static TSum SumAt(this TEnu _ => ValueEnumerableExtensions.SumAt(source, predicate) }; - static TSum Sum(this TEnumerable source, TSelector selector) + [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector: struct, IFunction @@ -47,7 +51,8 @@ static TSum Sum(thi _ => ValueEnumerableExtensions.Sum(source, selector) }; - static TSum SumAt(this TEnumerable source, TSelector selector) + [GeneratorIgnore] + internal static TSum SumAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -58,6 +63,7 @@ static TSum SumAt(t _ => ValueEnumerableExtensions.SumAt(source, selector) }; + [GeneratorIgnore] static TSum Sum(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs index 9bea87bfb..f7d9adc73 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs @@ -6,6 +6,7 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { + [GeneratorIgnore] public static async ValueTask SumAsync(this TEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -25,6 +26,7 @@ public static async ValueTask SumAsync SumAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -49,6 +51,7 @@ internal static async ValueTask SumAsync SumAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -73,6 +76,7 @@ internal static async ValueTask SumAtAsync SumAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -96,6 +100,7 @@ internal static async ValueTask SumAsync SumAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -119,6 +124,7 @@ internal static async ValueTask SumAtAsync SumAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs index 73b942c0c..c44392bcc 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs @@ -23,41 +23,43 @@ internal AsyncValueEnumerable(IAsyncEnumerable source) => this.source = source; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly AsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public AsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(source, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source, cancellationToken); - public struct AsyncEnumerator + public readonly struct AsyncEnumerator : IAsyncEnumerator { - IAsyncEnumerator enumerator; + readonly IAsyncEnumerator enumerator; internal AsyncEnumerator(IAsyncEnumerable enumerable, CancellationToken cancellationToken) => enumerator = enumerable.GetAsyncEnumerator(cancellationToken); - public readonly TSource Current + public TSource Current => enumerator.Current; - readonly TSource IAsyncEnumerator.Current + + TSource IAsyncEnumerator.Current => enumerator.Current; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask MoveNextAsync() + public ValueTask MoveNextAsync() => enumerator.MoveNextAsync(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask DisposeAsync() + public ValueTask DisposeAsync() => enumerator.DisposeAsync(); } #region Conversion - AsyncValueEnumerable AsAsyncValueEnumerable() + public AsyncValueEnumerable AsAsyncValueEnumerable() => this; - IAsyncEnumerable AsAsyncEnumerable() + public IAsyncEnumerable AsAsyncEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs index 91c1d5160..c3c15f577 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs @@ -35,10 +35,10 @@ IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(Cancellat #region Conversion - AsyncValueEnumerable AsAsyncValueEnumerable() + public AsyncValueEnumerable AsAsyncValueEnumerable() => this; - IAsyncEnumerable AsAsyncEnumerable() + public IAsyncEnumerable AsAsyncEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs index 8fd889ac8..71aab5bad 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs @@ -71,10 +71,10 @@ IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(Cancellat #region Conversion - AsyncValueEnumerable AsAsyncValueEnumerable() + public AsyncValueEnumerable AsAsyncValueEnumerable() => this; - TEnumerable AsAsyncEnumerable() + public TEnumerable AsAsyncEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs index 81bbe0e49..9dc82a023 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs @@ -72,10 +72,10 @@ IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(Cancellat #region Conversion - AsyncValueEnumerable AsAsyncValueEnumerable() + public AsyncValueEnumerable AsAsyncValueEnumerable() => this; - TEnumerable AsAsyncEnumerable() + public TEnumerable AsAsyncEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs index f6a1ef92d..c82f69c6e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs @@ -33,10 +33,10 @@ IEnumerator IEnumerable.GetEnumerator() #region Conversion - ValueEnumerable AsValueEnumerable() + public ValueEnumerable AsValueEnumerable() => this; - IEnumerable AsEnumerable() + public IEnumerable AsEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index e5a315368..f9e4f945a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -58,9 +58,18 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); - - + { + switch (source) + { + case ICollection collection: + collection.CopyTo(array, arrayIndex); + break; + default: + CopyTo(array.AsSpan().Slice(arrayIndex)); + break; + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) => Count is not 0 && source.Contains(item); @@ -77,10 +86,10 @@ bool ICollection.Remove(TSource item) #region Conversion - ValueEnumerable AsValueEnumerable() + public ValueEnumerable AsValueEnumerable() => this; - IReadOnlyCollection AsEnumerable() + public IReadOnlyCollection AsEnumerable() => source; #endregion @@ -99,42 +108,42 @@ public static int Count(this ValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, int, int>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int, int>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, int?, int>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int?, int>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, long, long>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long, long>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, long?, long>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long?, long>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, float, float>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float, float>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, float?, float>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float?, float>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, double, double>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double, double>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, double?, double>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double?, double>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, decimal, decimal>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal, decimal>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, decimal?, decimal>(); + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal?, decimal>(source); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs new file mode 100644 index 000000000..fffaa7c49 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs @@ -0,0 +1,235 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ReadOnlyListExtensions + { + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable, TSource> AsValueEnumerable(this IReadOnlyList source) + => new(source); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TList source) + where TList : IReadOnlyList + => new(source); + + [StructLayout(LayoutKind.Auto)] + public readonly partial struct ValueEnumerable + : IValueReadOnlyList> + , IList + where TList : IReadOnlyList + { + readonly TList source; + + internal ValueEnumerable(TList source) + => this.source = source; + + public TSource this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + TSource IList.this[int index] + { + get => source[index]; + [DoesNotReturn] + // ReSharper disable once ValueParameterNotUsed + set => Throw.NotSupportedException(); + } + + public int Count + => source.Count; + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() + => new(source.GetEnumerator()); + IEnumerator IEnumerable.GetEnumerator() + => source.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + => source.GetEnumerator(); + + bool ICollection.IsReadOnly + => true; + + public void CopyTo(Span span) + { + if (Count is 0) + return; + + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + + using var enumerator = GetEnumerator(); + checked + { + for (var index = 0; enumerator.MoveNext(); index++) + span[index] = enumerator.Current; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TSource[] array, int arrayIndex) + { + switch (source) + { + case ICollection collection: + collection.CopyTo(array, arrayIndex); + break; + default: + CopyTo(array.AsSpan().Slice(arrayIndex)); + break; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TSource item) + => Count is not 0 && source.Contains(item); + + public int IndexOf(TSource item) + { + return source switch + { + IList list => list.IndexOf(item), + _ => IndexOfEnumerable(this, item), + }; + + static int IndexOfEnumerable(ValueEnumerable source, TSource item) + { + using var enumerator = source.GetEnumerator(); + for (var index = 0; enumerator.MoveNext(); index++) + { + if (EqualityComparer.Default.Equals(enumerator.Current, item)) + return index; + } + return -1; + } + } + + [ExcludeFromCodeCoverage] + void ICollection.Add(TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void ICollection.Clear() + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + bool ICollection.Remove(TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void IList.Insert(int index, TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void IList.RemoveAt(int index) + => Throw.NotSupportedException(); + + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SkipTakeEnumerable, TSource> Skip(int count) + => this.Skip, TSource>(count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SkipTakeEnumerable, TSource> Take(int count) + => this.Take, TSource>(count); + + #endregion + + #region Conversion + + public ValueEnumerable AsValueEnumerable() + => this; + + public IReadOnlyCollection AsEnumerable() + => source; + + #endregion + + #region Projection + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.SelectEnumerable, ValueEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) + => ValueReadOnlyListExtensions.Select, ValueEnumerator, TSource, TResult>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.SelectEnumerable, ValueEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) + where TSelector : struct, IFunction + => ValueReadOnlyListExtensions.Select, ValueEnumerator, TSource, TResult, TSelector>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.SelectAtEnumerable, ValueEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) + => ValueReadOnlyListExtensions.Select, ValueEnumerator, TSource, TResult>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.SelectAtEnumerable, ValueEnumerator, TSource, TResult, TSelector> SelectAt(TSelector selector = default) + where TSelector : struct, IFunction + => ValueReadOnlyListExtensions.SelectAt, ValueEnumerator, TSource, TResult, TSelector>(this, selector); + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source) + where TList : IReadOnlyList + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int, int>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int?, int>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long, long>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long?, long>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float, float>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float?, float>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double, double>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double?, double>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal, decimal>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal?, decimal>(source); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs index 6ac9098a4..95a858484 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs @@ -38,10 +38,10 @@ IEnumerator IEnumerable.GetEnumerator() #region Conversion - ValueEnumerable AsValueEnumerable() + public ValueEnumerable AsValueEnumerable() => this; - IEnumerable AsEnumerable() + public IEnumerable AsEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index af5cc0269..a8a384767 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -82,10 +82,10 @@ bool ICollection.Remove(TSource item) #region Conversion - ValueEnumerable AsValueEnumerable() + public ValueEnumerable AsValueEnumerable() => this; - IReadOnlyCollection AsEnumerable() + public IReadOnlyCollection AsEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs index e1a65477d..6d0e27e72 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -71,10 +71,10 @@ IEnumerator IEnumerable.GetEnumerator() #region Conversion - ValueEnumerable AsValueEnumerable() + public ValueEnumerable AsValueEnumerable() => this; - TEnumerable AsEnumerable() + public TEnumerable AsEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index fdb935fd6..84a0f3439 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -117,10 +117,10 @@ bool ICollection.Remove(TSource item) #region Conversion - ValueEnumerable AsValueEnumerable() + public ValueEnumerable AsValueEnumerable() => this; - TEnumerable AsEnumerable() + public TEnumerable AsEnumerable() => source; #endregion @@ -142,7 +142,7 @@ public static int Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, int, int>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int, int>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) @@ -151,7 +151,7 @@ public static int Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, int?, int>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int?, int>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) @@ -160,7 +160,7 @@ public static long Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, long, long>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long, long>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) @@ -169,7 +169,7 @@ public static long Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, long?, long>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long?, long>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) @@ -178,7 +178,7 @@ public static float Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, float, float>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float, float>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ValueEnumerable source) @@ -187,7 +187,7 @@ public static float Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, float?, float>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float?, float>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) @@ -196,7 +196,7 @@ public static double Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, double, double>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double, double>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ValueEnumerable source) @@ -205,7 +205,7 @@ public static double Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, double?, double>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double?, double>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) @@ -214,7 +214,7 @@ public static decimal Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, decimal, decimal>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal, decimal>(source); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ValueEnumerable source) @@ -223,6 +223,6 @@ public static decimal Sum where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, decimal?, decimal>(); + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal?, decimal>(source); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs index 11501b987..599754b5a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs @@ -74,10 +74,10 @@ IEnumerator IEnumerable.GetEnumerator() #region Conversion - ValueEnumerable AsValueEnumerable() + public ValueEnumerable AsValueEnumerable() => this; - TEnumerable AsEnumerable() + public TEnumerable AsEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index d61b4fee3..eb029adc3 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -98,8 +98,17 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); - + { + switch (source) + { + case ICollection collection: + collection.CopyTo(array, arrayIndex); + break; + default: + CopyTo(array.AsSpan().Slice(arrayIndex)); + break; + } + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) @@ -117,10 +126,10 @@ bool ICollection.Remove(TSource item) #region Conversion - ValueEnumerable AsValueEnumerable() + public ValueEnumerable AsValueEnumerable() => this; - TEnumerable AsEnumerable() + public TEnumerable AsEnumerable() => source; #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs new file mode 100644 index 000000000..59f909aa8 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs @@ -0,0 +1,306 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TGetEnumerator : struct, IFunction + => new(source, getEnumerator, getEnumerator); + + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => new(source, getEnumerator, getEnumerator2); + + [GeneratorBindings(source: "source", sourceImplements: "IValueReadOnlyList`2,IValueEnumerable`2")] + [StructLayout(LayoutKind.Auto)] + public partial struct ValueEnumerable + : IValueReadOnlyList + , IList + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + { + readonly TEnumerable source; + TGetEnumerator getEnumerator; + TGetEnumerator2 getEnumerator2; + + internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) + => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); + + public TSource this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + TSource IList.this[int index] + { + get => source[index]; + set => Throw.NotSupportedException(); + } + + public readonly int Count + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TEnumerator2 GetEnumerator() + => getEnumerator2.Invoke(source); + TEnumerator IValueEnumerable.GetEnumerator() + => getEnumerator.Invoke(source); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => source.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => source.GetEnumerator(); + + bool ICollection.IsReadOnly + => true; + + public void CopyTo(Span span) + { + if (Count is 0) + return; + + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + + using var enumerator = getEnumerator.Invoke(source); + checked + { + for (var index = 0; enumerator.MoveNext(); index++) + span[index] = enumerator.Current; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TSource[] array, int arrayIndex) + { + switch (source) + { + // ReSharper disable once SuspiciousTypeConversion.Global + case ICollection collection: + collection.CopyTo(array, arrayIndex); + break; + default: + CopyTo(array.AsSpan().Slice(arrayIndex)); + break; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly bool Contains(TSource item) + => Count is not 0 && EnumerableExtensions.Contains(source, item); + + public readonly int IndexOf(TSource item) + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is IList list) + return list.IndexOf(item); + + using var enumerator = getEnumerator.Invoke(source); + for (var index = 0; enumerator.MoveNext(); index++) + { + if (EqualityComparer.Default.Equals(enumerator.Current, item)) + return index; + } + return -1; + } + + [ExcludeFromCodeCoverage] + readonly void ICollection.Add(TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + readonly void ICollection.Clear() + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + readonly bool ICollection.Remove(TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + readonly void IList.Insert(int index, TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + readonly void IList.RemoveAt(int index) + => Throw.NotSupportedException(); + + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ReadOnlyListExtensions.SkipTakeEnumerable, TSource> Skip(int count) + => this.Skip, TSource>(count); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ReadOnlyListExtensions.SkipTakeEnumerable, TSource> Take(int count) + => this.Take, TSource>(count); + + #endregion + + #region Conversion + + public readonly ValueEnumerable AsValueEnumerable() + => this; + + public readonly TEnumerable AsEnumerable() + => source; + + #endregion + + #region Projection + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly SelectEnumerable, TEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) + => Select, TEnumerator, TSource, TResult>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly SelectEnumerable, TEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) + where TSelector : struct, IFunction + => Select, TEnumerator, TSource, TResult, TSelector>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly SelectAtEnumerable, TEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) + => Select, TEnumerator, TSource, TResult>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly SelectAtEnumerable, TEnumerator, TSource, TResult, TSelector> SelectAt(TSelector selector = default) + where TSelector : struct, IFunction + => SelectAt, TEnumerator, TSource, TResult, TSelector>(this, selector); + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int, int>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int?, int>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long, long>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long?, long>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float, float>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float?, float>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double, double>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double?, double>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal, decimal>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal?, decimal>(source); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index 9447f0251..5c827f0f9 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -28,24 +28,22 @@ public readonly partial struct ArraySegmentValueEnumerable internal ArraySegmentValueEnumerable(ArraySegment source) => this.source = source; - public readonly int Count + public int Count { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => source.Count; } - public readonly TSource this[int index] + public TSource this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if ((uint)index >= (uint)Count) Throw.ArgumentOutOfRangeException(nameof(index)); - + ThrowIfArgument.OutOfRange(index, Count, nameof(index)); return source.Array![source.Offset + index]; } } - TSource IReadOnlyList.this[int index] - => this[index]; + TSource IList.this[int index] { get => this[index]; @@ -56,14 +54,17 @@ TSource IList.this[int index] } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SpanEnumerator GetEnumerator() + public SpanEnumerator GetEnumerator() => new(source); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(source); @@ -227,8 +228,8 @@ public ArraySegmentWhereAtEnumerable WhereAt(TP [MethodImpl(MethodImplOptions.AggressiveInlining)] public ArraySegmentValueEnumerable Skip(int count) { - var (skipCount, takeCount) = Utils.Skip(source.Count, count); - return new ArraySegmentValueEnumerable(new ArraySegment(source.Array!, source.Offset + skipCount, takeCount)); + var (newOffset, newCount) = Utils.Skip(source.Count, count); + return new ArraySegmentValueEnumerable(new ArraySegment(source.Array!, source.Offset + newOffset, newCount)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs deleted file mode 100644 index 448817a06..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyList.cs +++ /dev/null @@ -1,253 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ReadOnlyListExtensions - { - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, TSource> AsValueEnumerable(this IReadOnlyList source) - => AsValueEnumerable, TSource>(source); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TList source) - where TList : IReadOnlyList - => new(source); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueReadOnlyList.DisposableEnumerator> - , IList - where TList : IReadOnlyList - { - internal readonly TList source; - - internal ValueEnumerable(TList source) - => this.source = source; - - public readonly int Count - => source.Count; - - public readonly TSource this[int index] - => source[index]; - - TSource IReadOnlyList.this[int index] - => this[index]; - - TSource IList.this[int index] - { - get => this[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() - => new(in this); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (Count is 0) - return; - - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - for (var index = 0; index < Count && index < span.Length; index++) - span[index] = source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => Count is not 0 && source.Contains(item); - - public int IndexOf(TSource item) - => ReadOnlyListExtensions.IndexOf(source, item, 0, Count); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct Enumerator - { - readonly TList source; - readonly int end; - int index; - - internal Enumerator(in ValueEnumerable enumerable) - { - source = enumerable.source; - index = -1; - end = index + enumerable.Count; - } - - public TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - } - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly TList source; - readonly int end; - int index; - - internal DisposableEnumerator(in ValueEnumerable enumerable) - { - source = enumerable.source; - index = -1; - end = index + enumerable.Count; - } - - public TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - TSource IEnumerator.Current - => source[index]; - object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source[index]; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => Throw.NotSupportedException(); - - public readonly void Dispose() { } - } - - #region Conversion - - ValueEnumerable AsValueEnumerable() - => this; - - ValueEnumerable AsEnumerable() - => this; - - #endregion - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SkipTakeEnumerable, TSource> Skip(int count) - => ValueReadOnlyListExtensions.Skip, TSource>(this, count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SkipTakeEnumerable, TSource> Take(int count) - => ValueReadOnlyListExtensions.Take, TSource>(this, count); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in ValueEnumerable source) - where TList : IReadOnlyList - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, float, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Sum, ValueEnumerable.DisposableEnumerator, decimal?, decimal>(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index b486fffd3..e1a420e74 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -27,19 +27,18 @@ public readonly partial struct MemoryValueEnumerable internal MemoryValueEnumerable(ReadOnlyMemory source) => this.source = source; - public readonly int Count + public int Count { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => source.Length; } - public readonly TSource this[int index] + public TSource this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => source.Span[index]; } - TSource IReadOnlyList.this[int index] - => source.Span[index]; + TSource IList.this[int index] { get => source.Span[index]; @@ -50,14 +49,17 @@ TSource IList.this[int index] } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SpanEnumerator GetEnumerator() + public SpanEnumerator GetEnumerator() => new(source.Span); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(source); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(source); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(source); @@ -180,8 +182,8 @@ public MemoryWhereAtEnumerable WhereAt(TPredica [MethodImpl(MethodImplOptions.AggressiveInlining)] public MemoryValueEnumerable Skip(int count) { - var (skipCount, takeCount) = Utils.Skip(source.Length, count); - return new MemoryValueEnumerable(source.Slice(skipCount, takeCount)); + var (newOffset, newCount) = Utils.Skip(source.Length, count); + return new MemoryValueEnumerable(source.Slice(newOffset, newCount)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -236,28 +238,6 @@ public MemoryDistinctEnumerable Distinct(IEqualityComparer? co => source.Distinct(comparer); #endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index 7b33b3122..cde9e5fcb 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -24,20 +24,20 @@ public readonly ref partial struct SpanValueEnumerable internal SpanValueEnumerable(ReadOnlySpan source) => this.source = source; - public readonly int Count + public int Count { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => source.Length; } - public readonly TSource this[int index] + public TSource this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => source[index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SpanEnumerator GetEnumerator() + public SpanEnumerator GetEnumerator() => new(source); #region Aggregation @@ -87,8 +87,8 @@ public SpanWhereAtEnumerable WhereAt(TPredicate [MethodImpl(MethodImplOptions.AggressiveInlining)] public SpanValueEnumerable Skip(int count) { - var (skipCount, takeCount) = Utils.Skip(source.Length, count); - return new SpanValueEnumerable(source.Slice(skipCount, takeCount)); + var (newOffset, newCount) = Utils.Skip(source.Length, count); + return new SpanValueEnumerable(source.Slice(newOffset, newCount)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/ValueEnumerator.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/ValueEnumerator.cs index 4b2f8d605..4a63dbf91 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/ValueEnumerator.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/ValueEnumerator.cs @@ -20,8 +20,6 @@ public TSource Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => enumerator.Current; } - TSource IEnumerator.Current - => enumerator.Current; object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => enumerator.Current; diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index 6a7b9a4aa..af038d46f 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -7,12 +7,10 @@ namespace NetFabric.Hyperlinq { static partial class ArrayExtensions { - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static TSource[] ToArray(this ReadOnlySpan source) => source.ToArray(); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose = default) { @@ -23,6 +21,7 @@ public static ValueMemoryOwner ToArray(this ReadOnlySpan(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction @@ -40,6 +39,7 @@ static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction @@ -51,6 +51,7 @@ static ValueMemoryOwner ToArray(this ReadOnlySpan< ////////////////////////////////////////////////////////////////////////////////////////////////// + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static TSource[] ToArrayAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction @@ -68,6 +69,7 @@ static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction @@ -79,6 +81,7 @@ static ValueMemoryOwner ToArrayAt(this ReadOnlySpa ////////////////////////////////////////////////////////////////////////////////////////////////// + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static TResult[] ToArray(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -97,6 +100,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static TResult[] ToArrayVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> @@ -118,6 +122,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TVectorSelector vector } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArrayVector(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> @@ -130,6 +135,7 @@ static ValueMemoryOwner ToArrayVector ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction @@ -141,6 +147,7 @@ static ValueMemoryOwner ToArray(this ReadO ////////////////////////////////////////////////////////////////////////////////////////////////// + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static TResult[] ToArrayAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -159,6 +166,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction @@ -171,6 +179,7 @@ static ValueMemoryOwner ToArrayAt(this Rea ////////////////////////////////////////////////////////////////////////////////////////////////// + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static TResult[] ToArray(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction @@ -189,6 +198,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TPredicate predicate, } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index 974a61bd1..2fa65963a 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -1,4 +1,5 @@ using System.Buffers; +using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -13,11 +14,11 @@ public static TSource[] ToArray(this TEnumera { return source switch { - ICollection collection => BuildArrayFromCollection(collection), + ICollection collection => BuildArrayFromCollection(collection), _ => BuildArray(source) }; - static TSource[] BuildArrayFromCollection(ICollection collection) + static TSource[] BuildArrayFromCollection(ICollection collection) { var result = Utils.AllocateUninitializedArray(collection.Count); collection.CopyTo(result, 0); @@ -43,6 +44,7 @@ public static ValueMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -53,6 +55,7 @@ internal static TSource[] ToArray return arrayBuilder.ToArray(); } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -66,6 +69,7 @@ internal static ValueMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -76,6 +80,7 @@ internal static TSource[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -89,6 +94,7 @@ internal static ValueMemoryOwner ToArrayAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -99,6 +105,7 @@ static TResult[] ToArray( return arrayBuilder.ToArray(); } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable @@ -111,6 +118,7 @@ static ValueMemoryOwner ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -121,6 +129,7 @@ static TResult[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable @@ -134,6 +143,7 @@ static ValueMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable @@ -145,6 +155,7 @@ internal static TResult[] ToArray ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index 152c39639..f9891b6f6 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -1,5 +1,6 @@ using System; using System.Buffers; +using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -16,11 +17,15 @@ public static TSource[] ToArray(this TEnumera return source switch { { Count: 0 } => Array.Empty(), - ICollection collection => BuildArrayFromCollection(collection), + + // ReSharper disable once HeapView.PossibleBoxingAllocation + // ReSharper disable once SuspiciousTypeConversion.Global + ICollection collection => BuildArrayFromCollection(collection), + _ => BuildArray(source) }; - static TSource[] BuildArrayFromCollection(ICollection collection) + static TSource[] BuildArrayFromCollection(ICollection collection) { var result = Utils.AllocateUninitializedArray(collection.Count); collection.CopyTo(result, 0); @@ -47,6 +52,7 @@ public static ValueMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -58,6 +64,7 @@ static TSource[] ToArray(this TEn _ => ValueEnumerableExtensions.ToArray(source, predicate) }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -67,6 +74,7 @@ static ValueMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -78,6 +86,7 @@ static TSource[] ToArrayAt(this T _ => ValueEnumerableExtensions.ToArrayAt(source, predicate) }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -87,8 +96,9 @@ static ValueMemoryOwner ToArrayAt(this TEnumerable source, TSelector selector) + internal static TResult[] ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -108,8 +118,9 @@ static TResult[] BuildArray(TEnumerable source, TSelector selector) } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + internal static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -122,8 +133,9 @@ static ValueMemoryOwner ToArray(this TEnumerable source, TSelector selector) + internal static TResult[] ToArrayAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -143,8 +155,9 @@ static TResult[] BuildArray(TEnumerable source, TSelector selector) } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + internal static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -156,6 +169,7 @@ static ValueMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -168,6 +182,7 @@ static TResult[] ToArray ValueEnumerableExtensions.ToArray(source, predicate, selector) }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs deleted file mode 100644 index 2940afcb0..000000000 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyList.cs +++ /dev/null @@ -1,199 +0,0 @@ -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static TSource[] ToArray(this TList source) - where TList : struct, IReadOnlyList - => source.ToArray(0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TSource[] ToArray(this TList source, int offset, int count) - where TList : struct, IReadOnlyList - { - return count switch - { - 0 => Array.Empty(), - _ => BuildArray(source, offset, count) - }; - - static TSource[] BuildArray(TList source, int offset, int count) - { - var result = Utils.AllocateUninitializedArray(count); - Copy(source, offset, result.AsSpan(), count); - return result; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this TList source, ArrayPool pool, bool clearOnDispose, int offset, int count) - where TList : struct, IReadOnlyList - { - var result = pool.RentSliced(count, clearOnDispose); - Copy(source, offset, result.Memory.Span, count); - return result; - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TSource[] ToArray(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - return count switch - { - 0 => Array.Empty(), - _ => BuildArray(source, predicate, offset, count) - }; - - static TSource[] BuildArray(TList source, TPredicate predicate, int offset, int count) - { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate, offset, count); - return arrayBuilder.ToArray(); - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate, offset, count); - return arrayBuilder.ToArray(pool, clearOnDispose); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TSource[] ToArrayAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - return count switch - { - 0 => Array.Empty(), - _ => BuildArray(source, predicate, offset, count) - }; - - static TSource[] BuildArray(TList source, TPredicate predicate, int offset, int count) - { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, false, predicate, offset, count); - return arrayBuilder.ToArray(); - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArrayAt(this TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - { - using var arrayBuilder = ToArrayBuilderAt(source, pool, clearOnDispose, predicate, offset, count); - return arrayBuilder.ToArray(pool, clearOnDispose); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TResult[] ToArray(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - return count switch - { - 0 => Array.Empty(), - _ => BuildArray(source, selector, offset, count) - }; - - static TResult[] BuildArray(TList source, TSelector selector, int offset, int count) - { - var result = Utils.AllocateUninitializedArray(count); - Copy(source, offset, result.AsSpan(), count, selector); - return result; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this TList source, ArrayPool pool, bool clearOnDispose, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - var result = pool.RentSliced(count, clearOnDispose); - Copy(source, offset, result.Memory.Span, count, selector); - return result; - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TResult[] ToArrayAt(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - return count switch - { - 0 => Array.Empty(), - _ => BuildArray(source, selector, offset, count) - }; - - static TResult[] BuildArray(TList source, TSelector selector, int offset, int count) - { - var result = Utils.AllocateUninitializedArray(count); - CopyAt(source, offset, result.AsSpan(), count, selector); - return result; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArrayAt(this TList source, ArrayPool pool, bool clearOnDispose, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - var result = pool.RentSliced(count, clearOnDispose); - CopyAt(source, offset, result.Memory.Span, count, selector); - return result; - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TResult[] ToArray(this TList source, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - { - return count switch - { - 0 => Array.Empty(), - _ => BuildArray(source, predicate, selector, offset, count) - }; - - static TResult[] BuildArray(TList source, TPredicate predicate, TSelector selector, int offset, int count) - { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate, selector, offset, count); - return arrayBuilder.ToArray(); - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - { - using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate, selector, offset, count); - return arrayBuilder.ToArray(pool, clearOnDispose); - } - } -} - diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs index 4f4840312..d4e826a31 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs @@ -23,6 +23,7 @@ public static async ValueTask> ToArrayAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -30,6 +31,7 @@ static async ValueTask ToArrayAsync => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -39,6 +41,7 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -46,6 +49,7 @@ static async ValueTask ToArrayAtAsync => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, false, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -55,6 +59,7 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -62,6 +67,7 @@ static async ValueTask ToArrayAsync => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, selector).ConfigureAwait(false)).ToArray(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -71,6 +77,7 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -78,6 +85,7 @@ static async ValueTask ToArrayAtAsync => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, false, cancellationToken, selector).ConfigureAwait(false)).ToArray(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -87,6 +95,7 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -95,6 +104,7 @@ static async ValueTask ToArrayAsync => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, predicate, selector).ConfigureAwait(false)).ToArray(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs index 98d15e5ba..5631d82a0 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs @@ -6,13 +6,13 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Dictionary ToDictionary(this ReadOnlySpan source, Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull => source.ToDictionary(new FunctionWrapper(keySelector), comparer); - [GeneratorIgnore(false)] + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction @@ -24,6 +24,7 @@ static Dictionary ToDictionary(this return dictionary; } + [GeneratorIgnore] static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TKey : notnull where TKeySelector : struct, IFunction @@ -39,6 +40,7 @@ static Dictionary ToDictionary ToDictionaryAt(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TKey : notnull where TKeySelector : struct, IFunction @@ -55,6 +57,7 @@ static Dictionary ToDictionaryAt ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TKey : notnull where TKeySelector : struct, IFunction @@ -76,13 +79,13 @@ static Dictionary ToDictionary ToDictionary(this ReadOnlySpan source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) where TKey : notnull => source.ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - [GeneratorIgnore(false)] + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction @@ -95,6 +98,7 @@ static Dictionary ToDictionary ToDictionary( this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, @@ -114,6 +118,7 @@ static Dictionary return dictionary; } + [GeneratorIgnore] static Dictionary ToDictionaryAt( this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, @@ -135,6 +140,7 @@ static Dictionary return dictionary; } + [GeneratorIgnore] static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TKey : notnull where TKeySelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs index c2415a224..7bdd23b00 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs @@ -31,6 +31,7 @@ public static Dictionary ToDictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -50,6 +51,7 @@ internal static Dictionary ToDictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -71,6 +73,7 @@ internal static Dictionary ToDictionaryAt ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -121,6 +124,7 @@ public static Dictionary ToDictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -140,6 +144,7 @@ internal static Dictionary ToDictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -162,6 +167,7 @@ internal static Dictionary ToDictionaryAt ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs index ed7c55c97..6d3eb4e85 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs @@ -24,6 +24,7 @@ public static Dictionary ToDictionary() : ValueEnumerableExtensions.ToDictionary(source, keySelector, comparer); + [GeneratorIgnore] static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -36,6 +37,7 @@ static Dictionary ToDictionary(source, keySelector, comparer, predicate); + [GeneratorIgnore] static Dictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -47,6 +49,7 @@ static Dictionary ToDictionaryAt() : ValueEnumerableExtensions.ToDictionaryAt(source, keySelector, comparer, predicate); + [GeneratorIgnore] static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -81,6 +84,7 @@ public static Dictionary ToDictionary(source, keySelector, elementSelector, comparer); + [GeneratorIgnore] static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -94,6 +98,7 @@ static Dictionary ToDictionary(source, keySelector, elementSelector, comparer, predicate); + [GeneratorIgnore] static Dictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -106,6 +111,7 @@ static Dictionary ToDictionaryAt() : ValueEnumerableExtensions.ToDictionaryAt(source, keySelector, elementSelector, comparer, predicate); + [GeneratorIgnore] static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs deleted file mode 100644 index 527c011fe..000000000 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs +++ /dev/null @@ -1,212 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static Dictionary ToDictionary(this TList source, Func keySelector, IEqualityComparer? comparer = default) - where TList : struct, IReadOnlyList - where TKey : notnull - => source.ToDictionary(keySelector, comparer, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static Dictionary ToDictionary(this TList source, Func keySelector, IEqualityComparer? comparer, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - => source.ToDictionary>(new FunctionWrapper(keySelector), comparer, offset, count); - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static Dictionary ToDictionary(this TList source, TKeySelector keySelector = default, IEqualityComparer? comparer = default) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - => source.ToDictionary(keySelector, comparer, 0, source.Count); - - static Dictionary ToDictionary(this TList source, TKeySelector keySelector, IEqualityComparer? comparer, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Count, comparer); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - dictionary.Add(keySelector.Invoke(item), item); - } - - return dictionary; - } - - static Dictionary ToDictionary(this TList source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - where TPredicate : struct, IFunction - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Count, comparer); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - dictionary.Add(keySelector.Invoke(item), item); - } - return dictionary; - } - - - static Dictionary ToDictionaryAt(this TList source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - where TPredicate : struct, IFunction - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Count, comparer); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item, index)) - dictionary.Add(keySelector.Invoke(item), item); - } - return dictionary; - } - - static Dictionary ToDictionary(this TList source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Count, comparer); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - { - var result = selector.Invoke(item); - dictionary.Add(keySelector.Invoke(result), result); - } - } - return dictionary; - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static Dictionary ToDictionary(this TList source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TList : struct, IReadOnlyList - where TKey : notnull - => source.ToDictionary(keySelector, elementSelector, comparer, 0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static Dictionary ToDictionary(this TList source, Func keySelector, Func elementSelector, IEqualityComparer? comparer, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - => source.ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer, offset, count); - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static Dictionary ToDictionary(this TList source, TKeySelector keySelector = default, TElementSelector elementSelector = default, IEqualityComparer? comparer = default) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => source.ToDictionary(keySelector, elementSelector, comparer, 0, source.Count); - - static Dictionary ToDictionary(this TList source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Count, comparer); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - dictionary.Add(keySelector.Invoke(item), elementSelector.Invoke(item)); - } - - return dictionary; - } - - static Dictionary ToDictionary(this TList source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - where TPredicate : struct, IFunction - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Count, comparer); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - dictionary.Add(keySelector.Invoke(item), elementSelector.Invoke(item)); - } - return dictionary; - } - - static Dictionary ToDictionaryAt(this TList source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - where TPredicate : struct, IFunction - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Count, comparer); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item, index)) - dictionary.Add(keySelector.Invoke(item), elementSelector.Invoke(item)); - } - return dictionary; - } - - static Dictionary ToDictionary(this TList source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var dictionary = new Dictionary(source.Count, comparer); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - { - var result = selector.Invoke(item); - dictionary.Add(keySelector.Invoke(result), elementSelector.Invoke(result)); - } - } - return dictionary; - } - - } -} - diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs index a63b0ea6b..8dd683283 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs @@ -58,6 +58,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } + [GeneratorIgnore] static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -92,6 +93,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } + [GeneratorIgnore] static async ValueTask> ToDictionaryAtAsync( this TEnumerable source, TKeySelector keySelector, @@ -129,6 +131,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } } + [GeneratorIgnore] static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -220,6 +223,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } + [GeneratorIgnore] static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -256,6 +260,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } + [GeneratorIgnore] static async ValueTask> ToDictionaryAtAsync( this TEnumerable source, TKeySelector keySelector, @@ -295,6 +300,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } + [GeneratorIgnore] static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs index 2d5c55a15..ab86e865f 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs @@ -9,26 +9,29 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source) => source.ToArray().AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction => source.ToArray(predicate).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction => source.ToArrayAt(predicate).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source.ToArray(selector).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> @@ -37,11 +40,13 @@ static List ToListVector( where TResult : struct => source.ToArrayVector(vectorSelector, selector).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source.ToArrayAt(selector).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs index 95da0dea1..9a42620e6 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs @@ -14,6 +14,7 @@ public static List ToList(this TEnum => source.ToArray().AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -22,6 +23,7 @@ static List ToList(this => source.ToArray(predicate).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -30,6 +32,7 @@ static List ToListAt(thi => source.ToArrayAt(predicate).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -38,6 +41,7 @@ static List ToList source.ToArray(selector).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -45,6 +49,7 @@ static List ToListAt => source.ToArrayAt(selector).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs index 90f843bc8..73e8947a8 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs @@ -14,15 +14,10 @@ public static List ToList(this TEnum => source switch { { Count: 0 } => new List(), - _ => source switch - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - ICollection collection => new List(collection), - - _ => ToArray(source).AsList(), - } + _ => ToArray(source).AsList(), }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -30,6 +25,7 @@ static List ToList(this where TPredicate : struct, IFunction => ToArray(source, predicate).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -37,21 +33,23 @@ static List ToListAt(thi where TPredicate : struct, IFunction => ToArrayAt(source, predicate).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToList(this TEnumerable source, - TSelector selector) + internal static List ToList(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => ToArray(source, selector).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToListAt(this TEnumerable source, TSelector selector) + internal static List ToListAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => ToArrayAt(source, selector).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs deleted file mode 100644 index e907e8233..000000000 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyList.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -// ReSharper disable HeapView.ObjectAllocation.Evident - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore(false)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static List ToList(this TList source) - where TList : struct, IReadOnlyList - => source.ToList(0, source.Count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToList(this TList source, int offset, int count) - where TList : struct, IReadOnlyList - => source.ToArray(offset, count).AsList(); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToList(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.ToArray(predicate, offset, count).AsList(); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToListAt(this TList source, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.ToArrayAt(predicate, offset, count).AsList(); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToList(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.ToArray(selector, offset, count).AsList(); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToListAt(this TList source, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - => source.ToArrayAt(selector, offset, count).AsList(); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static List ToList(this TList source, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - where TSelector : struct, IFunction - => source.ToArray(predicate, selector, offset, count).AsList(); - } -} diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs index 69a678254..465d62854 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs @@ -16,6 +16,7 @@ public static async ValueTask> ToListAsync (await source.ToArrayAsync(cancellationToken).ConfigureAwait(false)).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -24,6 +25,7 @@ static async ValueTask> ToListAsync (await source.ToArrayAsync(cancellationToken, predicate).ConfigureAwait(false)).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -32,6 +34,7 @@ static async ValueTask> ToListAtAsync (await source.ToArrayAtAsync(cancellationToken, predicate).ConfigureAwait(false)).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -40,6 +43,7 @@ static async ValueTask> ToListAsync (await source.ToArrayAsync(cancellationToken, selector).ConfigureAwait(false)).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -48,6 +52,7 @@ static async ValueTask> ToListAtAsync (await source.ToArrayAtAsync(cancellationToken, selector).ConfigureAwait(false)).AsList(); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs new file mode 100644 index 000000000..9a77a2622 --- /dev/null +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Net.Sockets; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ReadOnlyListExtensions + { + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static Option ElementAt(this TList source, int index) + where TList : struct, IReadOnlyList + => index < 0 || index >= source.Count + ? Option.None + : Option.Some(source[index]); + + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static Option ElementAt(this TList source, int index, TSelector selector) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => index < 0 || index >= source.Count + ? Option.None + : Option.Some(selector.Invoke(source[index])); + + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static Option ElementAtAt(this TList source, int index, TSelector selector) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => index < 0 || index >= source.Count + ? Option.None + : Option.Some(selector.Invoke(source[index], index)); + } +} diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs index df7963c4a..60e1dad20 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs @@ -6,7 +6,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this ReadOnlySpan source, int index) => index < 0 || index >= source.Length @@ -14,6 +13,7 @@ static Option ElementAt(this ReadOnlySpan source, int : Option.Some(source[index]); + [GeneratorIgnore] static Option ElementAt(this ReadOnlySpan source, int index, TPredicate predicate) where TPredicate : struct, IFunction { @@ -29,6 +29,7 @@ static Option ElementAt(this ReadOnlySpan } + [GeneratorIgnore] static Option ElementAtAt(this ReadOnlySpan source, int index, TPredicate predicate) where TPredicate : struct, IFunction { @@ -45,6 +46,7 @@ static Option ElementAtAt(this ReadOnlySpan ElementAt(this ReadOnlySpan source, int index, TSelector selector) where TSelector : struct, IFunction => index < 0 || index >= source.Length @@ -52,6 +54,7 @@ static Option ElementAt(this ReadOnlySpan< : Option.Some(selector.Invoke(source[index])); + [GeneratorIgnore] static Option ElementAtAt(this ReadOnlySpan source, int index, TSelector selector) where TSelector : struct, IFunction => index < 0 || index >= source.Length @@ -59,6 +62,7 @@ static Option ElementAtAt(this ReadOnlySpa : Option.Some(selector.Invoke(source[index], index)); + [GeneratorIgnore] static Option ElementAt(this ReadOnlySpan source, int index, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs index 530aa2181..914a38426 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs @@ -23,6 +23,7 @@ public static Option ElementAt(this } + [GeneratorIgnore] internal static Option ElementAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -41,6 +42,7 @@ internal static Option ElementAt ElementAtAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -62,6 +64,7 @@ internal static Option ElementAtAt ElementAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -81,6 +84,7 @@ internal static Option ElementAt ElementAtAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -102,6 +106,7 @@ internal static Option ElementAtAt ElementAt(this TEnumerable source, int index, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs index 91f5cd2f4..68cac0e57 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs @@ -18,6 +18,7 @@ public static Option ElementAt(this : Option.None }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -29,9 +30,9 @@ static Option ElementAt( _ => ValueEnumerableExtensions.ElementAt(source, index, predicate) }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static Option ElementAtAt(this TEnumerable source, - int index, TPredicate predicate) + static Option ElementAtAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction @@ -41,6 +42,7 @@ static Option ElementAtAt ValueEnumerableExtensions.ElementAtAt(source, index, predicate) }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -55,6 +57,7 @@ static Option ElementAt ElementAtAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -68,6 +71,7 @@ static Option ElementAtAt ElementAt(this TEnumerable source, int index, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs index 5567464d1..c9c3f5aca 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs @@ -35,6 +35,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } + [GeneratorIgnore] static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -64,6 +65,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } + [GeneratorIgnore] static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -96,6 +98,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } + [GeneratorIgnore] static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -125,6 +128,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } + [GeneratorIgnore] static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -157,6 +161,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } + [GeneratorIgnore] static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs new file mode 100644 index 000000000..7b9af035e --- /dev/null +++ b/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ReadOnlyListExtensions + { + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static Option First(this TList source) + where TList : struct, IReadOnlyList + => source switch + { + { Count: 0 } => Option.None, + _ => Option.Some(source[0]) + }; + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static Option First(this TList source, TSelector selector) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source switch + { + { Count: 0 } => Option.None, + _ => Option.Some(selector.Invoke(source[0])), + }; + + + [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static Option FirstAt(this TList source, TSelector selector) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source switch + { + { Count: 0 } => Option.None, + _ => Option.Some(selector.Invoke(source[0], 0)), + }; + } +} diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs index 7794746f9..2e34346c1 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs @@ -6,7 +6,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this ReadOnlySpan source) => source switch @@ -15,6 +14,7 @@ static Option First(this ReadOnlySpan source) _ => Option.Some(source[0]) }; + [GeneratorIgnore] static Option First(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -27,7 +27,8 @@ static Option First(this ReadOnlySpan sou return Option.None; } - + + [GeneratorIgnore] static Option FirstAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -40,7 +41,8 @@ static Option FirstAt(this ReadOnlySpan s return Option.None; } - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -50,7 +52,8 @@ static Option First(this ReadOnlySpan Option.Some(selector.Invoke(source[0])), }; - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option FirstAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -60,7 +63,8 @@ static Option FirstAt(this ReadOnlySpan Option.Some(selector.Invoke(source[0], 0)), }; - + + [GeneratorIgnore] static Option First(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs b/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs index e5d220577..50251b11b 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs @@ -17,7 +17,8 @@ public static Option First(this TEnu }; } - + + [GeneratorIgnore] internal static Option First(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -34,7 +35,8 @@ internal static Option First FirstAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -53,7 +55,8 @@ internal static Option FirstAt First(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -67,7 +70,8 @@ internal static Option First FirstAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -81,7 +85,8 @@ internal static Option FirstAt First(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs index 9dfb7ee6a..2f01ff17e 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs @@ -25,6 +25,7 @@ static Option GetFirst(TEnumerable source) } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -36,6 +37,7 @@ static Option First(this _ => ValueEnumerableExtensions.First(source, predicate) }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option FirstAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -47,6 +49,7 @@ static Option FirstAt(th _ => ValueEnumerableExtensions.FirstAt(source, predicate) }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -67,7 +70,8 @@ static Option GetFirst(TEnumerable source, TSelector selector) } } - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option FirstAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -87,8 +91,9 @@ static Option GetFirst(TEnumerable source, TSelector selector) return Option.Some(selector.Invoke(enumerator.Current, 0)); } } - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs index bd7a36a8b..4ac0040c0 100644 --- a/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs @@ -27,7 +27,8 @@ public static async ValueTask> FirstAsync> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -50,7 +51,8 @@ static async ValueTask> FirstAsync> FirstAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -76,7 +78,8 @@ static async ValueTask> FirstAtAsync> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -98,7 +101,8 @@ static async ValueTask> FirstAsync> FirstAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -120,7 +124,8 @@ static async ValueTask> FirstAtAsync> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs new file mode 100644 index 000000000..b121eaf53 --- /dev/null +++ b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + +namespace NetFabric.Hyperlinq +{ + public static partial class ReadOnlyListExtensions + { + + [GeneratorIgnore] + static Option Single(this TList source) + where TList : struct, IReadOnlyList + => source switch + { + { Count: 1 } => Option.Some(source[0]), + _ => Option.None, + }; + + [GeneratorIgnore] + internal static Option Single(this TList source, TSelector selector) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source switch + { + { Count: 1 } => Option.Some(selector.Invoke(source[0])), + _ => Option.None, + }; + + + [GeneratorIgnore] + internal static Option SingleAt(this TList source, TSelector selector) + where TList : struct, IReadOnlyList + where TSelector : struct, IFunction + => source switch + { + { Count: 1 } => Option.Some(selector.Invoke(source[0], 0)), + _ => Option.None, + }; + } +} diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs index 5ac9e144a..56f05ceee 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs @@ -5,7 +5,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] static Option Single(this ReadOnlySpan source) => source switch { @@ -13,6 +12,7 @@ static Option Single(this ReadOnlySpan source) _ => Option.None, }; + [GeneratorIgnore] static Option Single(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -34,7 +34,8 @@ static Option Single(this ReadOnlySpan so return Option.None; } - + + [GeneratorIgnore] static Option SingleAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -56,7 +57,8 @@ static Option SingleAt(this ReadOnlySpan return Option.None; } - + + [GeneratorIgnore] static Option Single(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source switch @@ -65,7 +67,8 @@ static Option Single(this ReadOnlySpan Option.None, }; - + + [GeneratorIgnore] static Option SingleAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source switch @@ -74,7 +77,8 @@ static Option SingleAt(this ReadOnlySpan Option.None, }; - + + [GeneratorIgnore] static Option Single(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs b/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs index d5324063b..9ab5eeb54 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs @@ -12,7 +12,8 @@ public static Option Single(this TEn where TEnumerator : struct, IEnumerator => source.GetSingle(); - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option Single(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -20,7 +21,8 @@ internal static Option Single => source.GetSingle(predicate); - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option SingleAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -28,7 +30,8 @@ internal static Option SingleAt => source.GetSingleAt(predicate); - + + [GeneratorIgnore] static Option Single(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -37,7 +40,8 @@ static Option Single() .Select(selector); - + + [GeneratorIgnore] static Option SingleAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -59,6 +63,7 @@ public TResult Invoke(TSource item) => selector.Invoke(item, 0); } + [GeneratorIgnore] internal static Option Single(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -69,7 +74,8 @@ internal static Option Single GetSingle(this TEnumerable source) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -86,7 +92,8 @@ static Option GetSingle(this TEnumer return Option.None; } - + + [GeneratorIgnore] static Option GetSingle(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -112,7 +119,8 @@ static Option GetSingle( return Option.None; } - + + [GeneratorIgnore] static Option GetSingleAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs index e42091551..e0a00e1ce 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs @@ -25,6 +25,7 @@ static Option GetSingle(TEnumerable source) } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option Single(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -36,6 +37,7 @@ static Option Single(thi _ => ValueEnumerableExtensions.Single(source, predicate) }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option SingleAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -47,6 +49,7 @@ static Option SingleAt(t _ => ValueEnumerableExtensions.SingleAt(source, predicate) }; + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option Single(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -67,6 +70,7 @@ static Option GetSingle(TEnumerable source, TSelector selector) } } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option SingleAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -86,8 +90,9 @@ static Option GetSingle(TEnumerable source, TSelector selector) return Option.Some(selector.Invoke(enumerator.Current, 0)); } } - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option Single(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs index 1c11e84d5..e50bfbc0c 100644 --- a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs @@ -14,7 +14,8 @@ public static ValueTask> SingleAsync => source.GetSingleAsync(cancellationToken); - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable @@ -22,7 +23,8 @@ static ValueTask> SingleAsync => source.GetSingleAsync(cancellationToken, predicate); - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueTask> SingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable @@ -30,7 +32,8 @@ static ValueTask> SingleAtAsync => source.GetSingleAtAsync(cancellationToken, predicate); - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -41,7 +44,8 @@ static async ValueTask> SingleAsync(selector, cancellationToken).ConfigureAwait(false); } - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> SingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -65,6 +69,7 @@ public ValueTask InvokeAsync(TSource item, CancellationToken cancellati => selector.InvokeAsync(item, 0, cancellationToken); } + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -79,7 +84,8 @@ static async ValueTask> SingleAsync> GetSingleAsync(this TEnumerable source, CancellationToken cancellationToken) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -99,7 +105,8 @@ static async ValueTask> GetSingleAsync> GetSingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -133,7 +140,8 @@ static async ValueTask> GetSingleAsync> GetSingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs index d3e204471..a8ff05a86 100644 --- a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs @@ -5,6 +5,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore] static bool SequenceEqual(this ReadOnlySpan first, TEnumerable second, IEqualityComparer? comparer = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -23,7 +24,7 @@ static bool SequenceEqual(this ReadOnlySpan")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) => source.Where(new FunctionWrapper(predicate)); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereEnumerable Where(this in ArraySegment source, TPredicate predicate = default) where TPredicate : struct, IFunction @@ -33,14 +31,17 @@ public readonly partial struct ArraySegmentWhereEnumerable internal ArraySegmentWhereEnumerable(in ArraySegment source, TPredicate predicate) => (this.source, this.predicate) = (source, predicate); - public readonly WhereEnumerator GetEnumerator() + public WhereEnumerator GetEnumerator() => new(source.AsSpan(), predicate); - readonly Enumerator IValueEnumerable.GetEnumerator() + + Enumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -87,7 +88,7 @@ public bool MoveNext() public readonly void Reset() => throw new NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index b7b90705c..03f044881 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -44,9 +44,10 @@ internal WhereEnumerable(in TEnumerable source, TPredicate predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this, cancellationToken); @@ -105,7 +106,7 @@ public ValueTask MoveNextAsync() return builder.Task; } - public ValueTask DisposeAsync() + public readonly ValueTask DisposeAsync() => enumerator.DisposeAsync(); void IAsyncStateMachine.MoveNext() @@ -192,7 +193,7 @@ void IAsyncStateMachine.MoveNext() builder.SetResult(result); } - void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) + readonly void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) { } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index 5588a7dbb..0601701c9 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -10,13 +10,11 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.Where(new FunctionWrapper(predicate)); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereEnumerable Where(this ReadOnlyMemory source, TPredicate predicate = default) where TPredicate : struct, IFunction @@ -33,14 +31,17 @@ public readonly partial struct MemoryWhereEnumerable internal MemoryWhereEnumerable(ReadOnlyMemory source, TPredicate predicate) => (this.source, this.predicate) = (source, predicate); - public readonly WhereEnumerator GetEnumerator() + public WhereEnumerator GetEnumerator() => new(source.Span, predicate); - readonly Enumerator IValueEnumerable.GetEnumerator() + + Enumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -87,7 +88,7 @@ public bool MoveNext() public readonly void Reset() => throw new NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation @@ -224,28 +225,6 @@ public Dictionary ToDictionary source.Span.ToDictionary(keySelector, elementSelector, comparer, predicate); #endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index 8391b6c00..9bffafc63 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -9,13 +9,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereEnumerable> Where(this ReadOnlySpan source, Func predicate) => source.Where(new FunctionWrapper(predicate)); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereEnumerable Where(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction @@ -34,7 +32,7 @@ internal SpanWhereEnumerable(ReadOnlySpan source, TPredicate predicate) this.predicate = predicate; } - public readonly WhereEnumerator GetEnumerator() + public WhereEnumerator GetEnumerator() => new(source, predicate); #region Aggregation diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index 9e5d8d967..659422f39 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -40,12 +40,14 @@ internal WhereEnumerable(in TEnumerable source, TPredicate predicate) => (this.source, this.predicate) = (source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -86,10 +88,11 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); - public void Dispose() + public void Dispose() => enumerator.Dispose(); } @@ -102,10 +105,10 @@ public int Count() #endregion #region Conversion - WhereEnumerable AsValueEnumerable() + public WhereEnumerable AsValueEnumerable() => this; - WhereEnumerable AsEnumerable() + public WhereEnumerable AsEnumerable() => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index 36d31acc7..5bab7b510 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -39,12 +39,14 @@ internal WhereEnumerable(in TEnumerable source, TPredicate predicate) => (this.source, this.predicate) = (source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -85,6 +87,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index 444c345d0..67371a77d 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -35,14 +35,17 @@ internal ArraySegmentWhereAtEnumerable(in ArraySegment source, TPredica } - public readonly WhereAtEnumerator GetEnumerator() + public WhereAtEnumerator GetEnumerator() => new(source.AsSpan(), predicate); - readonly Enumerator IValueEnumerable.GetEnumerator() + + Enumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -91,7 +94,7 @@ public bool MoveNext() public readonly void Reset() => throw new NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index 559126eff..bb5bc9fba 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -44,9 +44,10 @@ internal WhereAtEnumerable(in TEnumerable source, TPredicate predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this, cancellationToken); @@ -194,7 +195,7 @@ void IAsyncStateMachine.MoveNext() builder.SetResult(result); } - void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) + readonly void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) { } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index 7e8966b5a..ee604e9aa 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -11,13 +11,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereAtEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereAtEnumerable WhereAt(this ReadOnlyMemory source, TPredicate predicate = default) where TPredicate : struct, IFunction @@ -34,14 +32,17 @@ public readonly partial struct MemoryWhereAtEnumerable internal MemoryWhereAtEnumerable(ReadOnlyMemory source, TPredicate predicate) => (this.source, this.predicate) = (source, predicate); - public readonly WhereAtEnumerator GetEnumerator() + public WhereAtEnumerator GetEnumerator() => new(source.Span, predicate); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); @@ -88,7 +89,7 @@ public bool MoveNext() public readonly void Reset() => throw new NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation @@ -215,28 +216,6 @@ public Dictionary ToDictionaryAt source.Span.ToDictionaryAt(keySelector, elementSelector, comparer, predicate); #endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current, otherEnumerator.Current)) - return false; - } - } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index 0420632e2..3a4d811d3 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -32,7 +32,7 @@ internal SpanWhereAtEnumerable(ReadOnlySpan source, TPredicate predicat this.predicate = predicate; } - public readonly WhereAtEnumerator GetEnumerator() + public WhereAtEnumerator GetEnumerator() => new(source, predicate); #region Aggregation diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index bdc940d7b..7191605a4 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -39,12 +39,14 @@ internal WhereAtEnumerable(in TEnumerable source, TPredicate predicate) => (this.source, this.predicate) = (source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -90,6 +92,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index 87488c274..d42a6acea 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -39,12 +39,14 @@ internal WhereAtEnumerable(in TEnumerable source, TPredicate predicate) => (this.source, this.predicate) = (source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -90,6 +92,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index 6be400e83..ccfefcde7 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -10,6 +10,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereSelectEnumerable WhereSelect( this in ArraySegment source, @@ -34,14 +35,17 @@ internal ArraySegmentWhereSelectEnumerable(in ArraySegment source, TPre => (this.source, this.predicate, this.selector) = (source, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereSelectEnumerator GetEnumerator() + public WhereSelectEnumerator GetEnumerator() => new(source.AsSpan(), predicate, selector); - readonly Enumerator IValueEnumerable.GetEnumerator() + + Enumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -66,8 +70,6 @@ internal Enumerator(in ArraySegmentWhereSelectEnumerable selector.Invoke(source![index]); - TResult IEnumerator.Current - => selector.Invoke(source![index]); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source![index]); @@ -87,7 +89,7 @@ public bool MoveNext() public readonly void Reset() => throw new NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation @@ -148,20 +150,20 @@ public bool AnyAt(TPredicate2 predicate) #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) + public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Where, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) + public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.WhereAt, Enumerator, TResult, TPredicate2>(predicate); @@ -178,13 +180,13 @@ public ArraySegmentWhereSelectEnumerable source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index d7a989050..568cfc4fc 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -11,6 +11,7 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TEnumerable source, @@ -39,9 +40,10 @@ internal WhereSelectEnumerable(in TEnumerable source, TPredicate predicate, TSel => (this.source, this.predicate, this.selector) = (source, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this, cancellationToken); @@ -280,20 +282,20 @@ public ValueTask AnyAtAsync(TPredicate2 predicate, Cancellati #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereEnumerable, Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) + public WhereEnumerable, Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) + public WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IAsyncFunction => this.Where, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereAtEnumerable, Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) + public WhereAtEnumerable, Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) + public WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IAsyncFunction => this.WhereAt, Enumerator, TResult, TPredicate2>(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index 5ab16fad2..b502b0bbe 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -11,6 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereSelectEnumerable WhereSelect( this ReadOnlyMemory source, @@ -36,14 +37,17 @@ internal MemoryWhereSelectEnumerable(ReadOnlyMemory source, TPredicate [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereSelectEnumerator GetEnumerator() + public WhereSelectEnumerator GetEnumerator() => new(source.Span, predicate, selector); - readonly Enumerator IValueEnumerable.GetEnumerator() + + Enumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -69,8 +73,6 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(source.Span[index]); } - TResult IEnumerator.Current - => selector.Invoke(source.Span[index]); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source.Span[index]); @@ -92,7 +94,7 @@ public bool MoveNext() public readonly void Reset() => throw new NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation @@ -152,20 +154,20 @@ public bool AnyAt(TPredicate2 predicate) #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) + public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Where, Enumerator, TResult, TPredicate2>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => this.Where, Enumerator, TResult>(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) + public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.WhereAt, Enumerator, TResult, TPredicate2>(predicate); @@ -182,13 +184,13 @@ public MemoryWhereSelectEnumerable source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction @@ -248,28 +250,6 @@ public Dictionary ToDictionary source.Span.ToDictionary(keySelector, elementSelector, comparer, predicate, selector); #endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index ad8ece9a3..d2e03ac7a 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -9,6 +9,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereSelectEnumerable WhereSelect( this ReadOnlySpan source, @@ -35,7 +36,7 @@ internal SpanWhereSelectEnumerable(ReadOnlySpan source, TPredicate pred this.selector = selector; } - public readonly WhereSelectEnumerator GetEnumerator() + public WhereSelectEnumerator GetEnumerator() => new(source, predicate, selector); #region Aggregation diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index 03e4038f2..f87b3e290 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -11,6 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TEnumerable source, @@ -44,12 +45,14 @@ internal WhereSelectEnumerable(in TEnumerable source, TPredicate predicate, TSel [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() => + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -74,8 +77,6 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(enumerator.Current); } - TResult IEnumerator.Current - => selector.Invoke(enumerator.Current); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(enumerator.Current); @@ -92,6 +93,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); @@ -186,13 +188,13 @@ public WhereSelectEnumerable source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index 57b4c6d6f..a8814ffaa 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -11,6 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TEnumerable source, @@ -44,12 +45,14 @@ internal WhereSelectEnumerable(in TEnumerable source, TPredicate predicate, TSel [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() => + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -74,8 +77,6 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(enumerator.Current); } - TResult IEnumerator.Current - => selector.Invoke(enumerator.Current); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(enumerator.Current); @@ -92,6 +93,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs index abc5e18f4..bcab7773f 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs @@ -27,25 +27,26 @@ IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(Cancellat public readonly struct Enumerator { - public readonly TSource Current + public TSource Current => default!; - public readonly ValueTask MoveNextAsync() + public ValueTask MoveNextAsync() => default; } public readonly struct DisposableEnumerator : IAsyncEnumerator { - public readonly TSource Current + public TSource Current => default!; - readonly TSource IAsyncEnumerator.Current + + TSource IAsyncEnumerator.Current => default!; - public readonly ValueTask MoveNextAsync() + public ValueTask MoveNextAsync() => default; - public readonly ValueTask DisposeAsync() + public ValueTask DisposeAsync() => default; } } diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs index 9aedd0d55..4f3b71058 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs @@ -46,11 +46,13 @@ internal RangeEnumerable(int start, int count, int end) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly DisposableEnumerator IAsyncValueEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + DisposableEnumerator IAsyncValueEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this, cancellationToken); @@ -133,8 +135,8 @@ public ValueTask AnyAsync(CancellationToken cancellationToken = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] public RangeEnumerable Skip(int count) { - var (skipCount, takeCount) = Utils.Skip(this.count, count); - return Range(start + skipCount, takeCount); + var (newOffset, newCount) = Utils.Skip(this.count, count); + return Range(start + newOffset, newCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs index 9fac293e5..ba6b650aa 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs @@ -31,11 +31,13 @@ internal RepeatEnumerable(TSource value, int count) => (this.value, this.count) = (value, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly AsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public AsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly DisposableAsyncEnumerator IAsyncValueEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + DisposableAsyncEnumerator IAsyncValueEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) // ReSharper disable once HeapView.BoxingAllocation => new DisposableAsyncEnumerator(in this, cancellationToken); @@ -54,7 +56,7 @@ internal AsyncEnumerator(in RepeatEnumerable enumerable, CancellationTo this.cancellationToken = cancellationToken; } - public readonly TSource Current { get; } + public TSource Current { get; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask MoveNextAsync() @@ -80,7 +82,7 @@ internal DisposableAsyncEnumerator(in RepeatEnumerable enumerable, Canc this.cancellationToken = cancellationToken; } - public readonly TSource Current { get; } + public TSource Current { get; } readonly TSource IAsyncEnumerator.Current => Current; @@ -109,7 +111,7 @@ internal DisposableEnumerator(in RepeatEnumerable enumerable) end = counter + enumerable.count; } - public readonly TSource Current { get; } + public TSource Current { get; } readonly TSource IEnumerator.Current => Current; readonly object? IEnumerator.Current @@ -121,6 +123,7 @@ public bool MoveNext() => ++counter <= end; [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs index 8b946828b..f9887481d 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs @@ -23,11 +23,13 @@ internal ReturnEnumerable(TSource value) => this.value = value; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetAsyncEnumerator() + public Enumerator GetAsyncEnumerator() => new(in this); - readonly DisposableEnumerator IAsyncValueEnumerable.GetAsyncEnumerator(CancellationToken _) + + DisposableEnumerator IAsyncValueEnumerable.GetAsyncEnumerator(CancellationToken _) => new(in this); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); @@ -42,7 +44,7 @@ internal Enumerator(in ReturnEnumerable enumerable) moveNext = true; } - public readonly TSource Current { get; } + public TSource Current { get; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask MoveNextAsync() @@ -65,7 +67,7 @@ internal DisposableEnumerator(in ReturnEnumerable enumerable) moveNext = true; } - public readonly TSource Current { get; } + public TSource Current { get; } readonly TSource IAsyncEnumerator.Current => Current; diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs index a211ed2b3..9fac65d71 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs @@ -24,12 +24,14 @@ internal CreateValueEnumerable(Func getEnumerator) => this.getEnumerator = getEnumerator; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerator GetEnumerator() + public TEnumerator GetEnumerator() => getEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => getEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => getEnumerator(); } diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs index 6e164d2c8..e1c1a6521 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs @@ -82,32 +82,32 @@ void IList.RemoveAt(int index) public readonly struct Enumerator { - public readonly TSource Current + public TSource Current => default!; - public readonly bool MoveNext() + public bool MoveNext() => default; } public readonly struct DisposableEnumerator : IEnumerator { - public readonly TSource Current + public TSource Current => default!; - readonly TSource IEnumerator.Current + TSource IEnumerator.Current => default!; - readonly object? IEnumerator.Current + object? IEnumerator.Current => default; - public readonly bool MoveNext() + public bool MoveNext() => default; [ExcludeFromCodeCoverage] - public readonly void Reset() { } + public void Reset() { } - public readonly void Dispose() { } + public void Dispose() { } } } } diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs index b89e34708..2dfe9894d 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs @@ -17,46 +17,61 @@ public static RangeEnumerable Range(int start, int count) if (count < 0) Throw.ArgumentOutOfRangeException(nameof(count)); - var end = 0; try { - end = checked(start + count); + _ = checked(start + count); } catch (OverflowException) { Throw.ArgumentOutOfRangeException(nameof(count)); } - return new RangeEnumerable(start, end); + return new RangeEnumerable(start, count); } [GeneratorMapping("TSource", "int", true)] [StructLayout(LayoutKind.Auto)] public readonly partial struct RangeEnumerable - : IValueReadOnlyCollection - , ICollection + : IValueReadOnlyList + , IList { readonly int start; - readonly int end; - internal RangeEnumerable(int start, int end) - => (this.start, this.end) = (start, end); + internal RangeEnumerable(int start, int count) + => (this.start, Count) = (start, count); - public readonly int Count + public int this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => end - start; + get + { + ThrowIfArgument.OutOfRange(index, Count, nameof(index)); + return index + start; + } + } + + int IList.this[int index] + { + get => this[index]; + [DoesNotReturn] + // ReSharper disable once ValueParameterNotUsed + set => Throw.NotSupportedException(); } + + public int Count { get; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); @@ -78,7 +93,15 @@ public void CopyTo(int[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(int value) - => value >= start && value < end; + => value >= start && value < start + Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int IndexOf(int value) + { + if (value < start || value >= start + Count) + return -1; + return value - start; + } [ExcludeFromCodeCoverage] void ICollection.Add(int item) @@ -89,6 +112,12 @@ void ICollection.Clear() [ExcludeFromCodeCoverage] bool ICollection.Remove(int item) => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void IList.Insert(int index, int item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void IList.RemoveAt(int index) + => Throw.NotSupportedException(); [StructLayout(LayoutKind.Auto)] public struct Enumerator @@ -140,6 +169,7 @@ public bool MoveNext() => ++current <= end; [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); @@ -151,8 +181,8 @@ public readonly void Dispose() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public RangeEnumerable Skip(int count) { - var (skipCount, takeCount) = Utils.Skip(Count, count); - return Range(start + skipCount, takeCount); + var (newOffset, newCount) = Utils.Skip(Count, count); + return Range(start + newOffset, newCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -177,7 +207,9 @@ public bool Contains(int value, IEqualityComparer? comparer) if (Count is 0) return false; - if (comparer is null || ReferenceEquals(comparer, EqualityComparer.Default)) + var end = start + Count; + + if (Utils.UseDefault(comparer)) return value >= start && value < end; for (var item = start; item < end; item++) diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs index 90af0e24f..e65b2e982 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs @@ -33,18 +33,21 @@ internal RepeatEnumerable(TSource value, int count) this.count = count; } - public readonly int Count + public int Count => count; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); @@ -96,7 +99,7 @@ internal Enumerator(in RepeatEnumerable enumerable) end = counter + enumerable.Count; } - public readonly TSource Current { get; } + public TSource Current { get; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() @@ -117,7 +120,7 @@ internal DisposableEnumerator(in RepeatEnumerable enumerable) end = counter + enumerable.Count; } - public readonly TSource Current { get; } + public TSource Current { get; } readonly TSource IEnumerator.Current => Current; readonly object? IEnumerator.Current @@ -129,6 +132,7 @@ public bool MoveNext() => ++counter <= end; [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs index 364b7b3a7..a0489b573 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs @@ -23,11 +23,11 @@ public readonly partial struct ReturnEnumerable internal ReturnEnumerable(TSource value) => this.value = value; - public readonly int Count + public int Count => 1; - public readonly TSource this[int index] + public TSource this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => index switch @@ -36,8 +36,7 @@ public readonly TSource this[int index] _ => Throw.ArgumentOutOfRangeException(nameof(index)) }; } - TSource IReadOnlyList.this[int index] - => this[index]; + TSource IList.this[int index] { get => this[index]; @@ -48,14 +47,17 @@ TSource IList.this[int index] } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly DisposableEnumerator IValueEnumerable.GetEnumerator() + + DisposableEnumerator IValueEnumerable.GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); @@ -113,7 +115,7 @@ internal Enumerator(in ReturnEnumerable enumerable) => (Current, moveNext) = (enumerable.value, true); - public readonly TSource Current { get; } + public TSource Current { get; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() @@ -137,7 +139,7 @@ internal DisposableEnumerator(in ReturnEnumerable enumerable) } - public readonly TSource Current { get; } + public TSource Current { get; } readonly TSource IEnumerator.Current => Current; readonly object? IEnumerator.Current diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index c250a4296..0dfb8a746 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -60,10 +60,14 @@ all runtime; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/NetFabric.Hyperlinq/Option/Option.cs b/NetFabric.Hyperlinq/Option/Option.cs index fac41907c..5ab29bc49 100644 --- a/NetFabric.Hyperlinq/Option/Option.cs +++ b/NetFabric.Hyperlinq/Option/Option.cs @@ -40,7 +40,7 @@ public bool IsNone public TValue Value { get; } - public readonly void Deconstruct(out bool hasValue, out TValue value) + public void Deconstruct(out bool hasValue, out TValue value) { hasValue = IsSome; value = Value; @@ -53,7 +53,7 @@ public static implicit operator Option(NoneOption _) [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TOut Match(Func some, Func none) + public TOut Match(Func some, Func none) => IsSome switch { true => some(Value), @@ -61,7 +61,7 @@ public readonly TOut Match(Func some, Func none) }; - public readonly ValueTask MatchAsync(Func> some, Func> none, CancellationToken cancellationToken = default) + public ValueTask MatchAsync(Func> some, Func> none, CancellationToken cancellationToken = default) => IsSome switch { true => some(Value, cancellationToken), @@ -69,7 +69,7 @@ public readonly ValueTask MatchAsync(Func some, Action none) + public void Match(Action some, Action none) { if (IsSome) some(Value); @@ -78,7 +78,7 @@ public readonly void Match(Action some, Action none) } - public readonly ValueTask MatchAsync(Func some, Func none, CancellationToken cancellationToken = default) + public ValueTask MatchAsync(Func some, Func none, CancellationToken cancellationToken = default) => IsSome switch { true => some(Value, cancellationToken), @@ -86,7 +86,7 @@ public readonly ValueTask MatchAsync(Func }; - public readonly Option Bind(Func> bind) + public Option Bind(Func> bind) => IsSome switch { true => bind(Value), @@ -94,7 +94,7 @@ public readonly Option Bind(Func> bind) }; - public readonly int Count() + public int Count() => IsSome switch { true => 1, @@ -103,20 +103,21 @@ public readonly int Count() [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any() + public bool Any() => IsSome; - public readonly bool Contains(TValue value, IEqualityComparer? comparer = default) + public bool Contains(TValue value, IEqualityComparer? comparer = default) => IsSome - && (comparer?.Equals(Value, value) ?? EqualityComparer.Default.Equals(Value, value)); + && (comparer?.Equals(Value, value) + ?? EqualityComparer.Default.Equals(Value, value)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Option Where(Func predicate) + public Option Where(Func predicate) => Where(new FunctionWrapper(predicate)); - public readonly Option Where(TPredicate predicate = default) + public Option Where(TPredicate predicate = default) where TPredicate : struct, IFunction => IsSome && predicate.Invoke(Value) ? this @@ -124,15 +125,15 @@ public readonly Option Where(TPredicate predicate = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueTask> WhereAsync(Func> predicate, CancellationToken cancellationToken = default) + public ValueTask> WhereAsync(Func> predicate, CancellationToken cancellationToken = default) => WhereAsync(new AsyncFunctionWrapper(predicate), cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueTask> WhereAsync(CancellationToken cancellationToken = default) + public ValueTask> WhereAsync(CancellationToken cancellationToken = default) where TPredicate : struct, IAsyncFunction => WhereAsync(default, cancellationToken); - public async readonly ValueTask> WhereAsync(TPredicate predicate, CancellationToken cancellationToken = default) + public async ValueTask> WhereAsync(TPredicate predicate, CancellationToken cancellationToken = default) where TPredicate : struct, IAsyncFunction => IsSome && await predicate.InvokeAsync(Value, cancellationToken).ConfigureAwait(false) ? this @@ -140,10 +141,10 @@ public async readonly ValueTask> WhereAsync(TPredicat [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Option Select(Func selector) + public Option Select(Func selector) => Select>(new FunctionWrapper(selector)); - public readonly Option Select(TSelector selector = default) + public Option Select(TSelector selector = default) where TSelector : struct, IFunction => IsSome switch { @@ -153,15 +154,15 @@ public readonly Option Select(TSelector selector = defaul [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueTask> SelectAsync(Func> selector, CancellationToken cancellationToken = default) + public ValueTask> SelectAsync(Func> selector, CancellationToken cancellationToken = default) => SelectAsync>(new AsyncFunctionWrapper(selector), cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueTask> SelectAsync(CancellationToken cancellationToken = default) + public ValueTask> SelectAsync(CancellationToken cancellationToken = default) where TSelector : struct, IAsyncFunction => SelectAsync(default, cancellationToken); - public async readonly ValueTask> SelectAsync(TSelector selector, CancellationToken cancellationToken = default) + public async ValueTask> SelectAsync(TSelector selector, CancellationToken cancellationToken = default) where TSelector : struct, IAsyncFunction => IsSome switch { @@ -171,20 +172,20 @@ public async readonly ValueTask> SelectAsync(TSele [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable> SelectMany(Func selector) + public SelectManyEnumerable> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => SelectMany>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable SelectMany(TSelector selector) + public SelectManyEnumerable SelectMany(TSelector selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector : struct, IFunction => new(in this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Option ElementAt(int index) + public Option ElementAt(int index) => index switch { 0 => this, @@ -193,16 +194,16 @@ public readonly Option ElementAt(int index) [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Option First() + public Option First() => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Option Single() + public Option Single() => this; - public readonly TValue[] ToArray() + public TValue[] ToArray() => IsSome switch { // ReSharper disable once HeapView.ObjectAllocation.Evident @@ -211,7 +212,7 @@ public readonly TValue[] ToArray() }; - public readonly List ToList() + public List ToList() => IsSome switch { // ReSharper disable once HeapView.ObjectAllocation.Evident @@ -236,12 +237,14 @@ internal SelectManyEnumerable(in Option source, TSelector selector) => (this.source, this.selector) = (source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -265,8 +268,6 @@ internal Enumerator(in SelectManyEnumerable.Current - => Current; readonly object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => Current; @@ -302,6 +303,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs index 2fd69b45b..2c8ac363d 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs @@ -24,18 +24,15 @@ public readonly partial struct SkipEnumerable where TEnumerator : struct, IAsyncEnumerator { readonly TEnumerable source; - readonly int count; + readonly int offset; - internal SkipEnumerable(in TEnumerable source, int count) - { - this.source = source; - this.count = count; - } + internal SkipEnumerable(in TEnumerable source, int offset) + => (this.source, this.offset) = (source, offset); - - public readonly Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) => new Enumerator(in this, cancellationToken); [StructLayout(LayoutKind.Auto)] @@ -56,7 +53,7 @@ public struct Enumerator internal Enumerator(in SkipEnumerable enumerable, CancellationToken cancellationToken) { enumerator = enumerable.source.GetAsyncEnumerator(cancellationToken); - counter = enumerable.count; + counter = enumerable.offset; state = default; builder = default; @@ -170,11 +167,11 @@ void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) [MethodImpl(MethodImplOptions.AggressiveInlining)] public SkipEnumerable Skip(int count) - => source.Skip(this.count + count); + => new(source, offset + count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SkipTakeEnumerable Take(int count) - => source.SkipTake(this.count, count); + => new(source, offset, count); } } } diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs similarity index 68% rename from NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyList.cs rename to NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs index 5128d3a26..4e30d7049 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs @@ -1,14 +1,16 @@ +using System; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { - public static partial class ValueReadOnlyListExtensions + public static partial class ReadOnlyListExtensions { - + + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static SkipTakeEnumerable Skip(this TList source, int count) where TList : struct, IReadOnlyList - => source.SkipTake(count, source.Count); + => new(in source, Utils.Skip(source.Count, count)); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs index 6c933d9aa..2101b7761 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs @@ -22,20 +22,18 @@ public readonly partial struct SkipEnumerable where TEnumerator : struct, IEnumerator { readonly TEnumerable source; - readonly int count; - - internal SkipEnumerable(in TEnumerable source, int count) - { - this.source = source; - this.count = count; - } + readonly int offset; + internal SkipEnumerable(in TEnumerable source, int offset) + => (this.source, this.offset) = (source, offset); - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(in this); [StructLayout(LayoutKind.Auto)] @@ -49,7 +47,7 @@ public struct Enumerator internal Enumerator(in SkipEnumerable enumerable) { enumerator = enumerable.source.GetEnumerator(); - counter = enumerable.count; + counter = enumerable.offset; } public readonly TSource Current @@ -78,6 +76,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); @@ -87,11 +86,11 @@ public void Dispose() [MethodImpl(MethodImplOptions.AggressiveInlining)] public SkipEnumerable Skip(int count) - => source.Skip(this.count + count); + => new(source, offset + count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SkipTakeEnumerable Take(int count) - => source.SkipTake(this.count, count); + => new(source, offset, count); } } } diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyCollection.cs index b6743771e..b17460437 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyCollection.cs @@ -10,6 +10,6 @@ public static partial class ValueReadOnlyCollectionExtensions public static SkipTakeEnumerable Skip(this TEnumerable source, int count) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator - => source.SkipTake(count, source.Count); + => new(in source, Utils.Skip(source.Count, count)); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs index e92456e42..4cbaba57c 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs @@ -11,12 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SkipTakeEnumerable SkipTake(this TEnumerable source, int skipCount, int takeCount) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - => new(in source, skipCount, takeCount); - [StructLayout(LayoutKind.Auto)] public readonly partial struct SkipTakeEnumerable : IAsyncValueEnumerable.Enumerator> @@ -24,21 +18,20 @@ public readonly partial struct SkipTakeEnumerable { readonly TEnumerable source; - readonly int skipCount; - readonly int takeCount; + readonly int offset; + readonly int count; - internal SkipTakeEnumerable(in TEnumerable source, int skipCount, int takeCount) - { - this.source = source; - this.skipCount = skipCount; - this.takeCount = takeCount; - } + internal SkipTakeEnumerable(in TEnumerable source, int offset, int count) + => (this.source, this.offset, this.count) = (source, offset, count); + internal SkipTakeEnumerable(in TEnumerable source, (int Offset, int Count) slice) + => (this.source, offset, count) = (source, slice.Offset, slice.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) => new Enumerator(in this, cancellationToken); [StructLayout(LayoutKind.Auto)] @@ -61,8 +54,8 @@ public struct Enumerator internal Enumerator(in SkipTakeEnumerable enumerable, CancellationToken cancellationToken) { enumerator = enumerable.source.GetAsyncEnumerator(cancellationToken); - skipCounter = enumerable.skipCount; - takeCounter = enumerable.takeCount; + skipCounter = enumerable.offset; + takeCounter = enumerable.count; state = default; builder = default; @@ -213,12 +206,21 @@ void IAsyncStateMachine.MoveNext() } void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) - { } + { + } } + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SkipTakeEnumerable Skip(int count) + => new(source, Utils.Skip(this.count, offset + count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public SkipTakeEnumerable Take(int count) - => source.SkipTake(skipCount, Math.Min(takeCount, count)); + => new(source, offset, Utils.Take(this.count, count)); + + #endregion } } } diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs similarity index 67% rename from NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyList.cs rename to NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs index 56a597036..6c5d6b827 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs @@ -7,14 +7,8 @@ namespace NetFabric.Hyperlinq { - public static partial class ValueReadOnlyListExtensions + public static partial class ReadOnlyListExtensions { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SkipTakeEnumerable SkipTake(this TList source, int skipCount, int takeCount) - where TList : struct, IReadOnlyList - => new(in source, skipCount, takeCount); - [StructLayout(LayoutKind.Auto)] public readonly partial struct SkipTakeEnumerable : IValueReadOnlyList.DisposableEnumerator> @@ -24,11 +18,11 @@ public readonly partial struct SkipTakeEnumerable readonly TList source; readonly int offset; - internal SkipTakeEnumerable(in TList source, int skipCount, int takeCount) - { - this.source = source; - (this.offset, Count) = Utils.SkipTake(source.Count, skipCount, takeCount); - } + internal SkipTakeEnumerable(in TList source, int offset, int count) + => (this.source, this.offset, Count) = (source, offset, count); + + internal SkipTakeEnumerable(in TList source, (int Offset, int Count) slice) + => (this.source, offset, Count) = (source, slice.Offset, slice.Count); public int Count { get; } @@ -37,15 +31,11 @@ public TSource this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if ((uint)index >= (uint)Count) Throw.ArgumentOutOfRangeException(nameof(index)); - + ThrowIfArgument.OutOfRange(index, Count, nameof(index)); return source[index + offset]; } } - TSource IReadOnlyList.this[int index] - => this[index]; - TSource IList.this[int index] { get => this[index]; @@ -63,9 +53,11 @@ DisposableEnumerator IValueEnumerable.GetEnumerat => new(in this); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation => new DisposableEnumerator(in this); bool ICollection.IsReadOnly @@ -97,7 +89,8 @@ public void CopyTo(TSource[] array, int arrayIndex) if (Count is 0) return; - if (offset is 0 && Count == source.Count && source is ICollection collection) + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (offset is 0 && Count == source.Count && source is ICollection collection) collection.CopyTo(array, arrayIndex); else CopyTo(array.AsSpan().Slice(arrayIndex)); @@ -107,7 +100,16 @@ public bool Contains(TSource item) => Contains(item, EqualityComparer.Default); public int IndexOf(TSource item) - => ValueReadOnlyListExtensions.IndexOf(source, item, offset, Count); + { + if (source.Count is 0) + return -1; + + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (offset is 0 && Count == source.Count && source is IList list) + return list.IndexOf(item); + + return ValueReadOnlyCollectionExtensions.IndexOf, DisposableEnumerator, TSource>(this, item); + } [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -180,13 +182,61 @@ public bool MoveNext() => ++index <= end; [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); - public void Dispose() - { } + public readonly void Dispose() + { } } + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SkipTakeEnumerable Skip(int count) + { + var (newOffset, newCount) = Utils.Skip(Count, count); + return new SkipTakeEnumerable(source, offset + newOffset, newCount); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SkipTakeEnumerable Take(int count) + => new(source, offset, Utils.Take(Count, count)); + + #endregion + + #region Conversion + + public SkipTakeEnumerable AsValueEnumerable() + => this; + + public SkipTakeEnumerable AsEnumerable() + => this; + + #endregion + + #region Projection + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.SelectEnumerable, DisposableEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) + => ValueReadOnlyListExtensions.Select, DisposableEnumerator, TSource, TResult>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.SelectEnumerable, DisposableEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) + where TSelector : struct, IFunction + => ValueReadOnlyListExtensions.Select, DisposableEnumerator, TSource, TResult, TSelector>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.SelectAtEnumerable, DisposableEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) + => ValueReadOnlyListExtensions.Select, DisposableEnumerator, TSource, TResult>(this, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueReadOnlyListExtensions.SelectAtEnumerable, DisposableEnumerator, TSource, TResult, TSelector> SelectAt(TSelector selector = default) + where TSelector : struct, IFunction + => ValueReadOnlyListExtensions.SelectAt, DisposableEnumerator, TSource, TResult, TSelector>(this, selector); + + #endregion + public bool Contains(TSource value, IEqualityComparer? comparer) { if (source.Count is 0) @@ -226,10 +276,6 @@ static bool ComparerContains(TList source, TSource value, IEqualityComparer Take(int count) - => source.SkipTake(offset, Math.Min(Count, count)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs index 251b0cacd..f2299f3f0 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs @@ -9,12 +9,6 @@ namespace NetFabric.Hyperlinq { public static partial class ValueEnumerableExtensions { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SkipTakeEnumerable SkipTake(this TEnumerable source, int skipCount, int takeCount) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => new(in source, skipCount, takeCount); [StructLayout(LayoutKind.Auto)] public readonly partial struct SkipTakeEnumerable @@ -23,23 +17,23 @@ public readonly partial struct SkipTakeEnumerable { readonly TEnumerable source; - readonly int skipCount; - readonly int takeCount; + readonly int offset; + readonly int count; - internal SkipTakeEnumerable(in TEnumerable source, int skipCount, int takeCount) - { - this.source = source; - this.skipCount = skipCount; - this.takeCount = takeCount; - } + internal SkipTakeEnumerable(in TEnumerable source, int offset, int count) + => (this.source, this.offset, this.count) = (source, offset, count); + internal SkipTakeEnumerable(in TEnumerable source, (int Offset, int Count) slice) + => (this.source, offset, count) = (source, slice.Offset, slice.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(in this); [StructLayout(LayoutKind.Auto)] @@ -54,8 +48,8 @@ public struct Enumerator internal Enumerator(in SkipTakeEnumerable enumerable) { enumerator = enumerable.source.GetEnumerator(); - skipCounter = enumerable.skipCount; - takeCounter = enumerable.takeCount; + skipCounter = enumerable.offset; + takeCounter = enumerable.count; } public readonly TSource Current @@ -93,6 +87,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); @@ -100,9 +95,17 @@ public void Dispose() => enumerator.Dispose(); } + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SkipTakeEnumerable Skip(int count) + => new(source, Utils.Skip(this.count, offset + count)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public SkipTakeEnumerable Take(int count) - => source.SkipTake(skipCount, Math.Min(takeCount, count)); + => new(source, offset, Utils.Take(this.count, count)); + + #endregion } } } diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs index 9fdeaec90..c3cb77eb2 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs @@ -9,12 +9,6 @@ namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyCollectionExtensions { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static SkipTakeEnumerable SkipTake(this TEnumerable source, int skipCount, int takeCount) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => new(in source, skipCount, takeCount); [StructLayout(LayoutKind.Auto)] public readonly partial struct SkipTakeEnumerable @@ -24,23 +18,24 @@ public readonly partial struct SkipTakeEnumerable { readonly TEnumerable source; - readonly int skipCount; + readonly int offset; - internal SkipTakeEnumerable(in TEnumerable source, int skipCount, int takeCount) - { - this.source = source; - (this.skipCount, Count) = Utils.SkipTake(source.Count, skipCount, takeCount); - } + internal SkipTakeEnumerable(in TEnumerable source, int offset, int count) + => (this.source, this.offset, Count) = (source, offset, count); - public readonly int Count { get; } + internal SkipTakeEnumerable(in TEnumerable source, (int Offset, int Count) slice) + => (this.source, offset, Count) = (source, slice.Offset, slice.Count); + + public int Count { get; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(in this); bool ICollection.IsReadOnly @@ -57,7 +52,7 @@ public void CopyTo(Span span) using var enumerator = source.GetEnumerator(); // skip - for (var counter = 0; counter < skipCount; counter++) + for (var counter = 0; counter < offset; counter++) { if (!enumerator.MoveNext()) Throw.InvalidOperationException(); @@ -79,7 +74,7 @@ public void CopyTo(TSource[] array, int arrayIndex) if (Count is 0) return; - if (skipCount is 0 && Count == source.Count && source is ICollection collection) + if (offset is 0 && Count == source.Count && source is ICollection collection) collection.CopyTo(array, arrayIndex); else CopyTo(array.AsSpan().Slice(arrayIndex)); @@ -111,7 +106,7 @@ public struct Enumerator internal Enumerator(in SkipTakeEnumerable enumerable) { enumerator = enumerable.source.GetEnumerator(); - skipCounter = enumerable.skipCount; + skipCounter = enumerable.offset; takeCounter = enumerable.Count; state = takeCounter > 0 ? EnumeratorState.Uninitialized : EnumeratorState.Complete; } @@ -166,6 +161,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); @@ -181,27 +177,27 @@ public bool Contains(TSource value, IEqualityComparer? comparer) if (Utils.UseDefault(comparer)) { // ReSharper disable once HeapView.PossibleBoxingAllocation - if (skipCount is 0 && Count == source.Count && source is ICollection collection) + if (offset is 0 && Count == source.Count && source is ICollection collection) return collection.Contains(value); - return DefaultContains(source, value, skipCount, Count); + return DefaultContains(source, value, offset, Count); } - return ComparerContains(source, value, comparer, skipCount, Count); + return ComparerContains(source, value, comparer, offset, Count); - static bool DefaultContains(TEnumerable source, TSource value, int skipCount, int takeCount) + static bool DefaultContains(TEnumerable source, TSource value, int offset, int count) { using var enumerator = source.GetEnumerator(); // skip - for (var counter = 0; counter < skipCount; counter++) + for (var counter = 0; counter < offset; counter++) { if (!enumerator.MoveNext()) Throw.InvalidOperationException(); } // take - for (var counter = 0; counter < takeCount; counter++) + for (var counter = 0; counter < count; counter++) { if (!enumerator.MoveNext()) Throw.InvalidOperationException(); @@ -212,20 +208,20 @@ static bool DefaultContains(TEnumerable source, TSource value, int skipCount, in return false; } - static bool ComparerContains(TEnumerable source, TSource value, IEqualityComparer? comparer, int skipCount, int takeCount) + static bool ComparerContains(TEnumerable source, TSource value, IEqualityComparer? comparer, int offset, int count) { comparer ??= EqualityComparer.Default; using var enumerator = source.GetEnumerator(); // skip - for (var counter = 0; counter < skipCount; counter++) + for (var counter = 0; counter < offset; counter++) { if (!enumerator.MoveNext()) Throw.InvalidOperationException(); } // take - for (var counter = 0; counter < takeCount; counter++) + for (var counter = 0; counter < count; counter++) { if (!enumerator.MoveNext()) Throw.InvalidOperationException(); @@ -237,9 +233,20 @@ static bool ComparerContains(TEnumerable source, TSource value, IEqualityCompare } } + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SkipTakeEnumerable Skip(int count) + { + var (newOffset, newCount) = Utils.Skip(Count, count); + return new SkipTakeEnumerable(source, offset + newOffset, newCount); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public SkipTakeEnumerable Take(int count) - => source.SkipTake(skipCount, Math.Min(Count, count)); + => new(source, offset, Utils.Take(Count, count)); + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs index 7ef457d0c..abb22691f 100644 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs @@ -29,11 +29,11 @@ public readonly partial struct TakeEnumerable internal TakeEnumerable(in TEnumerable source, int count) => (this.source, this.count) = (source, count); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) => new Enumerator(in this, cancellationToken); [StructLayout(LayoutKind.Auto)] @@ -173,7 +173,7 @@ void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) [MethodImpl(MethodImplOptions.AggressiveInlining)] public TakeEnumerable Take(int count) - => source.Take(Math.Min(this.count, count)); + => new(source, Utils.Take(this.count, count)); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs similarity index 70% rename from NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyList.cs rename to NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs index a9ad4d35e..c9c2f0361 100644 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs @@ -3,12 +3,13 @@ namespace NetFabric.Hyperlinq { - public static partial class ValueReadOnlyListExtensions + public static partial class ReadOnlyListExtensions { + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static SkipTakeEnumerable Take(this TList source, int count) where TList : struct, IReadOnlyList - => source.SkipTake(0, count); + => new(in source, 0, Utils.Take(source.Count, count)); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs index 4be64afde..982cb3ced 100644 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs @@ -26,18 +26,16 @@ public readonly partial struct TakeEnumerable readonly int count; internal TakeEnumerable(in TEnumerable source, int count) - { - this.source = source; - this.count = count; - } - + => (this.source, this.count) = (source, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(in this); [StructLayout(LayoutKind.Auto)] @@ -82,6 +80,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); @@ -91,7 +90,7 @@ public void Dispose() [MethodImpl(MethodImplOptions.AggressiveInlining)] public TakeEnumerable Take(int count) - => source.Take(Math.Min(this.count, count)); + => new(source, Utils.Take(this.count, count)); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyCollection.cs index 510fad85e..489fbad86 100644 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyCollection.cs @@ -10,6 +10,6 @@ public static partial class ValueReadOnlyCollectionExtensions public static SkipTakeEnumerable Take(this TEnumerable source, int count) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator - => source.SkipTake(0, count); + => new(in source, 0, Utils.Take(source.Count, count)); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index c21894565..e014144d0 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -44,8 +44,7 @@ public TResult this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if ((uint)index >= (uint)Count) Throw.ArgumentOutOfRangeException(nameof(index)); - + ThrowIfArgument.OutOfRange(index, Count, nameof(index)); return selector.Invoke(source.Array![index + source.Offset]); } } @@ -126,8 +125,6 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(source![index]); } - TResult IEnumerator.Current - => selector.Invoke(source![index]); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source![index]); @@ -137,10 +134,11 @@ public bool MoveNext() => ++index <= end; [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs index be3b3847e..0b8e2a7f1 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -41,9 +41,10 @@ internal SelectEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this, cancellationToken); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index 13f57503f..46305ec71 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -11,13 +11,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.Select>(new FunctionWrapper(selector)); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectEnumerable Select(this ReadOnlyMemory source, TSelector selector = default) where TSelector : struct, IFunction @@ -122,8 +120,6 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(source.Span[index]); } - TResult IEnumerator.Current - => selector.Invoke(source.Span[index]); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source.Span[index]); @@ -133,10 +129,11 @@ public bool MoveNext() => ++index < source.Length; [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation @@ -214,28 +211,6 @@ public List ToList() => source.Span.ToList(selector); #endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index f531d39f4..6d25c8e1e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -9,13 +9,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectEnumerable> Select(this ReadOnlySpan source, Func selector) => source.Select>(new FunctionWrapper(selector)); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectEnumerable Select(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index dfb4b54da..27e973436 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -40,12 +40,14 @@ internal SelectEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -68,8 +70,6 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(enumerator.Current); } - TResult IEnumerator.Current - => selector.Invoke(enumerator.Current); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(enumerator.Current); @@ -79,6 +79,7 @@ public bool MoveNext() => enumerator.MoveNext(); [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); @@ -124,13 +125,13 @@ public SelectAtEnumerable source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index 9d71609de..86a52aac4 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -108,8 +108,6 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(enumerator.Current); } - TResult IEnumerator.Current - => selector.Invoke(enumerator.Current); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(enumerator.Current); @@ -119,6 +117,7 @@ public bool MoveNext() => enumerator.MoveNext(); [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs new file mode 100644 index 000000000..800ebbc92 --- /dev/null +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -0,0 +1,311 @@ +using System; +using System.Buffers; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SelectEnumerable> Select(this TEnumerable source, Func selector) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => Select>(source, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SelectEnumerable Select(this TEnumerable source, TSelector selector = default) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => new(in source, selector); + + [GeneratorMapping("TSource", "TResult")] + [StructLayout(LayoutKind.Auto)] + public partial struct SelectEnumerable + : IValueReadOnlyList.Enumerator> + , IList + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + { + internal TEnumerable source; + internal TSelector selector; + + internal SelectEnumerable(in TEnumerable source, TSelector selector) + => (this.source, this.selector) = (source, selector); + + public readonly int Count + => source.Count; + + public TResult this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ThrowIfArgument.OutOfRange(index, Count, nameof(index)); + return selector.Invoke(source[index]); + } + } + TResult IList.this[int index] + { + get => this[index]; + + [ExcludeFromCodeCoverage] + // ReSharper disable once ValueParameterNotUsed + set => Throw.NotSupportedException(); + } + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly Enumerator GetEnumerator() + => new(in this); + readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => GetEnumerator(); + readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => GetEnumerator(); + + bool ICollection.IsReadOnly + => true; + + public readonly void CopyTo(Span span) + { + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + + ValueReadOnlyCollectionExtensions.Copy(source, span, selector); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly void CopyTo(TResult[] array, int arrayIndex) + => CopyTo(array.AsSpan().Slice(arrayIndex)); + + public readonly bool Contains(TResult item) + => ValueReadOnlyCollectionExtensions.Contains(source, item, default, selector); + + public readonly int IndexOf(TResult item) + => ValueReadOnlyCollectionExtensions.IndexOf(source, item, selector); + + [ExcludeFromCodeCoverage] + readonly void ICollection.Add(TResult item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + readonly void ICollection.Clear() + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + readonly bool ICollection.Remove(TResult item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + readonly void IList.Insert(int index, TResult item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + readonly void IList.RemoveAt(int index) + => Throw.NotSupportedException(); + + [StructLayout(LayoutKind.Auto)] + public struct Enumerator + : IEnumerator + { + [SuppressMessage("Style", "IDE0044:Add readonly modifier")] + TEnumerator enumerator; // do not make readonly + [SuppressMessage("Style", "IDE0044:Add readonly modifier")] + TSelector selector; // do not make readonly to avoid + + internal Enumerator(in SelectEnumerable enumerable) + { + enumerator = enumerable.source.GetEnumerator(); + selector = enumerable.selector; + } + + public TResult Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => selector.Invoke(enumerator.Current); + } + object? IEnumerator.Current + // ReSharper disable once HeapView.PossibleBoxingAllocation + => selector.Invoke(enumerator.Current); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => enumerator.MoveNext(); + + [ExcludeFromCodeCoverage] + [DoesNotReturn] + public readonly void Reset() + => Throw.NotSupportedException(); + + public void Dispose() + => enumerator.Dispose(); + } + + #region Partitioning + + #endregion + #region Aggregation + + #endregion + #region Quantifier + + #endregion + #region Filtering + + #endregion + #region Projection + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) + => Select>(new FunctionWrapper(selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SelectEnumerable> Select(TSelector2 selector = default) + where TSelector2 : struct, IFunction + => ValueReadOnlyListExtensions.Select>(source, new SelectorSelectorCombination(this.selector, selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) + => SelectAt>(new FunctionWrapper(selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SelectAtEnumerable> SelectAt(TSelector2 selector = default) + where TSelector2 : struct, IFunction + => ValueReadOnlyListExtensions.SelectAt>(source, new SelectorSelectorAtCombination(this.selector, selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector2 : struct, IFunction + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + + #endregion + #region Element + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly Option ElementAt(int index) + => source.ElementAt(index, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly Option First() + => source.First(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly Option Single() + => source.Single(selector); + + #endregion + #region Conversion + + public readonly SelectEnumerable AsValueEnumerable() + => this; + + public readonly SelectEnumerable AsEnumerable() + => this; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly TResult[] ToArray() + => source.ToArray(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.ToArray(pool, clearOnDispose, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly List ToList() + => source.ToList(selector); + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this in SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + } +} diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 310dd73b3..92417e00e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -47,8 +47,7 @@ public TResult this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if ((uint)index >= (uint)Count) Throw.ArgumentOutOfRangeException(nameof(index)); - + ThrowIfArgument.OutOfRange(index, Count, nameof(index)); return selector.Invoke(source.Array![index + source.Offset], index); } } @@ -118,8 +117,6 @@ internal Enumerator(in ArraySegmentSelectAtEnumerable selector.Invoke(source![index + offset], index); - TResult IEnumerator.Current - => selector.Invoke(source![index + offset], index); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source![index + offset], index); @@ -129,10 +126,11 @@ public bool MoveNext() => ++index <= end; [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation @@ -212,28 +210,6 @@ public List ToList() => ((ReadOnlySpan)source.AsSpan()).ToListAt(selector); #endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index 5ab12a46b..cbb420165 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -41,9 +41,10 @@ internal SelectAtEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this, cancellationToken); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 7532fcc27..d1e548eb1 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -11,13 +11,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectAtEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectAtEnumerable SelectAt(this ReadOnlyMemory source, TSelector selector = default) where TSelector : struct, IFunction @@ -113,8 +111,6 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(source.Span[index], index); } - TResult IEnumerator.Current - => selector.Invoke(source.Span[index], index); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source.Span[index], index); @@ -124,10 +120,11 @@ public bool MoveNext() => ++index < source.Length; [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); - public void Dispose() { } + public readonly void Dispose() { } } #region Aggregation @@ -205,28 +202,6 @@ public List ToList() => source.Span.ToListAt(selector); #endregion - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index 2304fa3bd..0e1cd403a 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -9,13 +9,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectAtEnumerable> Select(this ReadOnlySpan source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectAtEnumerable SelectAt(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index aa6ec3931..281494cd6 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -40,12 +40,14 @@ internal SelectAtEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -70,8 +72,6 @@ public readonly TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(enumerator.Current, index); } - readonly TResult IEnumerator.Current - => selector.Invoke(enumerator.Current, index); readonly object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(enumerator.Current, index); @@ -88,6 +88,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); @@ -134,13 +135,13 @@ public SelectAtEnumerable source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable where TSubEnumerator : struct, IEnumerator where TSelector2 : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index 3b5da95a3..4922ab686 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -110,8 +110,6 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(enumerator.Current, index); } - TResult IEnumerator.Current - => selector.Invoke(enumerator.Current, index); object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(enumerator.Current, index); @@ -128,10 +126,11 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); - public void Dispose() + public readonly void Dispose() => enumerator.Dispose(); } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs new file mode 100644 index 000000000..8659308fd --- /dev/null +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -0,0 +1,326 @@ +using System; +using System.Buffers; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SelectAtEnumerable> Select(this TEnumerable source, Func selector) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => SelectAt>(source, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SelectAtEnumerable SelectAt(this TEnumerable source, TSelector selector = default) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => new(in source, selector); + + [GeneratorMapping("TSource", "TResult")] + [StructLayout(LayoutKind.Auto)] + public partial struct SelectAtEnumerable + : IValueReadOnlyList.Enumerator> + , IList + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + { + internal TEnumerable source; + internal TSelector selector; + + internal SelectAtEnumerable(in TEnumerable source, TSelector selector) + => (this.source, this.selector) = (source, selector); + + public int Count + => source.Count; + + public TResult this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ThrowIfArgument.OutOfRange(index, Count, nameof(index)); + return selector.Invoke(source[index], index); + } + } + TResult IList.this[int index] + { + get => this[index]; + + [ExcludeFromCodeCoverage] + readonly + // ReSharper disable once ValueParameterNotUsed + set => Throw.NotSupportedException(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly Enumerator GetEnumerator() + => new (in this); + readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => GetEnumerator(); + readonly IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => GetEnumerator(); + + bool ICollection.IsReadOnly + => true; + + public void CopyTo(Span span) + { + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + + var end = Count; + for (var index = 0; index < end; index++) + { + var item = source[index]; + span[index] = selector.Invoke(item, index); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TResult[] array, int arrayIndex) + => CopyTo(array.AsSpan().Slice(arrayIndex)); + + public readonly bool Contains(TResult item) + => ValueReadOnlyCollectionExtensions.ContainsAt(source, item, default, selector); + + public readonly int IndexOf(TResult item) + => ValueReadOnlyCollectionExtensions.IndexOfAt(source, item, selector); + + [ExcludeFromCodeCoverage] + void ICollection.Add(TResult item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void ICollection.Clear() + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + bool ICollection.Remove(TResult item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void IList.Insert(int index, TResult item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void IList.RemoveAt(int index) + => Throw.NotSupportedException(); + + [StructLayout(LayoutKind.Auto)] + public struct Enumerator + : IEnumerator + { + [SuppressMessage("Style", "IDE0044:Add readonly modifier")] + TEnumerator enumerator; // do not make readonly + TSelector selector; + int index; + + internal Enumerator(in SelectAtEnumerable enumerable) + { + enumerator = enumerable.source.GetEnumerator(); + selector = enumerable.selector; + index = -1; + } + + public TResult Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => selector.Invoke(enumerator.Current, index); + } + object? IEnumerator.Current + // ReSharper disable once HeapView.PossibleBoxingAllocation + => selector.Invoke(enumerator.Current, index); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + { + if (enumerator.MoveNext()) + { + checked { index++; } + return true; + } + return false; + } + + [ExcludeFromCodeCoverage] + [DoesNotReturn] + public readonly void Reset() + => Throw.NotSupportedException(); + + // ReSharper disable once MA0102 + public void Dispose() + => enumerator.Dispose(); + } + + + #region Partitioning + + #endregion + #region Aggregation + + #endregion + #region Quantifier + + #endregion + #region Filtering + + #endregion + #region Projection + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) + => Select>(new FunctionWrapper(selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly SelectAtEnumerable> Select(TSelector2 selector = default) + where TSelector2 : struct, IFunction + => ValueReadOnlyListExtensions.SelectAt>(source, new SelectorAtSelectorCombination(this.selector, selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) + => SelectAt>(new FunctionWrapper(selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly SelectAtEnumerable> SelectAt(TSelector2 selector = default) + where TSelector2 : struct, IFunction + => ValueReadOnlyListExtensions.SelectAt>(source, new SelectorAtSelectorAtCombination(this.selector, selector)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector2 : struct, IFunction + => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); + + #endregion + #region Element + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly Option ElementAt(int index) + => source.ElementAtAt(index, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly Option First() + => source.FirstAt(selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly Option Single() + => source.SingleAt(selector); + + #endregion + #region Conversion + + public readonly SelectAtEnumerable AsValueEnumerable() + => this; + + public readonly SelectAtEnumerable AsEnumerable() + => this; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly TResult[] ToArray() + => ValueReadOnlyCollectionExtensions.ToArrayAt(source, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ValueReadOnlyCollectionExtensions.ToArrayAt(source, pool, clearOnDispose, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly List ToList() + => ValueReadOnlyCollectionExtensions.ToListAt(source, selector); + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this in SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + } +} diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs index c7ac45bd2..62b2588d1 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs @@ -25,7 +25,6 @@ static SpanSelectVectorContext SelectVec where TResult : struct => source.SelectVector(selector, selector); - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectVectorContext SelectVector(this ReadOnlySpan source, TVectorSelector vectorSelector = default, TSelector selector = default) where TVectorSelector : struct, IFunction, Vector> diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs index 04a93f3ab..cfbad322f 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs @@ -38,12 +38,14 @@ internal ArraySegmentSelectManyEnumerable(in ArraySegment source, TSele => (this.source, this.selector) = (source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -73,8 +75,6 @@ internal Enumerator(in ArraySegmentSelectManyEnumerable subEnumerator.Current; - readonly TResult IEnumerator.Current - => subEnumerator.Current; readonly object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => subEnumerator.Current; @@ -120,7 +120,7 @@ public void Dispose() #region Aggregation [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() + public int Count() => this.Count, Enumerator, TResult>(); #endregion @@ -152,20 +152,20 @@ public bool AnyAt(TPredicate predicate = default) #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) + public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) where TPredicate : struct, IFunction => ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) + public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, IFunction => ValueEnumerableExtensions.Where, Enumerator, TResult, TPredicate>(this, predicate); @@ -173,20 +173,20 @@ public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + public ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) + public ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2, TSelector2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + public ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) + public ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueEnumerableExtensions.SelectAt, Enumerator, TResult, TResult2, TSelector2>(this, selector); @@ -209,18 +209,21 @@ public Option Single() #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ArraySegmentSelectManyEnumerable AsValueEnumerable() + public ArraySegmentSelectManyEnumerable AsValueEnumerable() + => this; + + public ArraySegmentSelectManyEnumerable AsEnumerable() => this; #endregion #region Partitioning [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SkipEnumerable, Enumerator, TResult> Skip(int count) + public ValueEnumerableExtensions.SkipEnumerable, Enumerator, TResult> Skip(int count) => ValueEnumerableExtensions.Skip, Enumerator, TResult>(this, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.TakeEnumerable, Enumerator, TResult> Take(int count) + public ValueEnumerableExtensions.TakeEnumerable, Enumerator, TResult> Take(int count) => ValueEnumerableExtensions.Take, Enumerator, TResult>(this, count); #endregion diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs index 81e08346a..85a6191c7 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs @@ -39,12 +39,14 @@ internal MemorySelectManyEnumerable(ReadOnlyMemory source, TSelector se => (this.source, this.selector) = (source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -72,8 +74,6 @@ internal Enumerator(in MemorySelectManyEnumerable subEnumerator.Current; - readonly TResult IEnumerator.Current - => subEnumerator.Current; readonly object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => subEnumerator.Current; @@ -119,7 +119,7 @@ public void Dispose() #region Aggregation [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() + public int Count() => this.Count, Enumerator, TResult>(); #endregion @@ -151,20 +151,20 @@ public bool AnyAt(TPredicate predicate = default) #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) + public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) where TPredicate : struct, IFunction => ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) + public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, IFunction => ValueEnumerableExtensions.Where, Enumerator, TResult, TPredicate>(this, predicate); @@ -172,20 +172,20 @@ public readonly ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + public ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) + public ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2, TSelector2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + public ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) + public ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueEnumerableExtensions.SelectAt, Enumerator, TResult, TResult2, TSelector2>(this, selector); @@ -208,18 +208,21 @@ public Option Single() #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly MemorySelectManyEnumerable AsValueEnumerable() + public MemorySelectManyEnumerable AsValueEnumerable() + => this; + + public MemorySelectManyEnumerable AsEnumerable() => this; #endregion #region Partitioning [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SkipEnumerable, Enumerator, TResult> Skip(int count) + public ValueEnumerableExtensions.SkipEnumerable, Enumerator, TResult> Skip(int count) => ValueEnumerableExtensions.Skip, Enumerator, TResult>(this, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.TakeEnumerable, Enumerator, TResult> Take(int count) + public ValueEnumerableExtensions.TakeEnumerable, Enumerator, TResult> Take(int count) => ValueEnumerableExtensions.Take, Enumerator, TResult>(this, count); #endregion diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs index e5122506d..5064dcd22 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs @@ -40,7 +40,7 @@ internal SpanSelectManyEnumerable(ReadOnlySpan source, TSelector select } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(this); [StructLayout(LayoutKind.Auto)] diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs index fea266b3c..9d304d6ef 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs @@ -45,12 +45,14 @@ internal SelectManyEnumerable(in TEnumerable source, TSelector selector) => (this.source, this.selector) = (source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -75,8 +77,6 @@ internal Enumerator(in SelectManyEnumerable subEnumerator.Current; - readonly TResult IEnumerator.Current - => subEnumerator.Current; readonly object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => subEnumerator.Current; @@ -111,16 +111,18 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); - public void Dispose() => subEnumerator.Dispose(); + public void Dispose() + => subEnumerator.Dispose(); } #region Aggregation [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() + public int Count() => this.Count, Enumerator, TResult>(); #endregion @@ -152,20 +154,20 @@ public bool AnyAt(TPredicate predicate = default) #region Filtering [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) + public WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) where TPredicate : struct, IFunction => ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) + public WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) + public WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, IFunction => ValueEnumerableExtensions.Where, Enumerator, TResult, TPredicate>(this, predicate); @@ -173,20 +175,20 @@ public readonly WhereEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + public SelectEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) + public SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2, TSelector2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) + public SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) + public SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueEnumerableExtensions.SelectAt, Enumerator, TResult, TResult2, TSelector2>(this, selector); @@ -209,18 +211,21 @@ public Option Single() #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectManyEnumerable AsValueEnumerable() + public SelectManyEnumerable AsValueEnumerable() + => this; + + public SelectManyEnumerable AsEnumerable() => this; #endregion #region Partitioning [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SkipEnumerable, Enumerator, TResult> Skip(int count) + public SkipEnumerable, Enumerator, TResult> Skip(int count) => ValueEnumerableExtensions.Skip, Enumerator, TResult>(this, count); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TakeEnumerable, Enumerator, TResult> Take(int count) + public TakeEnumerable, Enumerator, TResult> Take(int count) => ValueEnumerableExtensions.Take, Enumerator, TResult>(this, count); #endregion diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs index 8d8277415..43c95684c 100644 --- a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs @@ -5,12 +5,10 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool All(this ReadOnlySpan source, Func predicate) => source.All(new FunctionWrapper(predicate)); - [GeneratorIgnore(false)] static bool All(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { @@ -22,12 +20,10 @@ static bool All(this ReadOnlySpan source, TPredica return true; } - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool All(this ReadOnlySpan source, Func predicate) => source.AllAt(new FunctionWrapper(predicate)); - [GeneratorIgnore(false)] static bool AllAt(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs index eebd88585..f32ae561c 100644 --- a/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs @@ -6,18 +6,15 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool Any(this ReadOnlySpan source) => source.Length is not 0; - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool Any(this in ReadOnlySpan source, Func predicate) => source.Any(new FunctionWrapper(predicate)); - [GeneratorIgnore(false)] static bool Any(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { @@ -29,12 +26,10 @@ static bool Any(this ReadOnlySpan source, TPredica return false; } - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool Any(this in ReadOnlySpan source, Func predicate) => source.AnyAt(new FunctionWrapper(predicate)); - [GeneratorIgnore(false)] static bool AnyAt(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate : struct, IFunction { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs index ab05607e5..f2b1df490 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs @@ -4,6 +4,7 @@ namespace NetFabric.Hyperlinq { public static partial class EnumerableExtensions { + [GeneratorIgnore] internal static bool Contains(this TEnumerable source, TSource value, IEqualityComparer? comparer = default) where TEnumerable : IEnumerable { @@ -42,6 +43,7 @@ static bool ComparerContains(TEnumerable source, TSource value, IEqualityCompare } } + [GeneratorIgnore] internal static bool Contains(this TEnumerable source, TEnumeratorGenerator getEnumerator, TSource value, IEqualityComparer? comparer = default) where TEnumerable : IEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs index c8482fc4e..078f638c1 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs @@ -5,7 +5,6 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore(false)] static bool Contains(this ReadOnlySpan source, TSource value, IEqualityComparer? comparer = default) { return source switch @@ -38,6 +37,7 @@ static bool ReferenceContains(ReadOnlySpan source, TSource value, IEqua } } + [GeneratorIgnore] static bool Contains(this ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) where TSelector : struct, IFunction { @@ -71,6 +71,7 @@ static bool ReferenceContains(ReadOnlySpan source, TResult value, IEqua } } + [GeneratorIgnore] static bool ContainsAt(this ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) where TSelector : struct, IFunction { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs index d50c3fdfa..991ef2274 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -44,6 +44,7 @@ static bool ComparerContains(TEnumerable source, TSource value, IEqualityCompare } + [GeneratorIgnore] internal static bool Contains(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -78,6 +79,7 @@ static bool ReferenceContains(TEnumerable source, TResult value, IEqualityCompar } } + [GeneratorIgnore] internal static bool ContainsAt(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs index 1c6c950c1..080b9a4f3 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs @@ -11,6 +11,7 @@ public static bool Contains(this TEnumerable where TEnumerator : struct, IEnumerator => source.Count is not 0 && ValueEnumerableExtensions.Contains(source, value, comparer); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool Contains(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -18,8 +19,9 @@ internal static bool Contains => source.Count is not 0 && ValueEnumerableExtensions.Contains(source, value, comparer, selector); + [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool ContainsAt(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) + internal static bool ContainsAt(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs index 66122d65b..acb2cd2bb 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs @@ -11,7 +11,7 @@ public static async ValueTask ContainsAsync { var enumerator = source.GetAsyncEnumerator(); - await using (enumerator.ConfigureAwait(false)) + try { while (await enumerator.MoveNextAsync().ConfigureAwait(false)) { @@ -19,6 +19,10 @@ public static async ValueTask ContainsAsync ContainsAsync(t where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator { - if (Utils.UseDefault(comparer)) - return DefaultContainsAsync(source, value, cancellationToken); - - return ComparerContainsAsync(source, value, comparer, cancellationToken); + return Utils.UseDefault(comparer) + ? DefaultContainsAsync(source, value, cancellationToken) + : ComparerContainsAsync(source, value, comparer, cancellationToken); static async ValueTask DefaultContainsAsync(TEnumerable source, TSource value, CancellationToken cancellationToken) { var enumerator = source.GetAsyncEnumerator(cancellationToken); - await using (enumerator.ConfigureAwait(false)) + try { while (await enumerator.MoveNextAsync().ConfigureAwait(false)) { @@ -42,6 +45,10 @@ static async ValueTask DefaultContainsAsync(TEnumerable source, TSource va return true; } } + finally + { + await enumerator.DisposeAsync().ConfigureAwait(false); + } return false; } @@ -49,7 +56,7 @@ static async ValueTask ComparerContainsAsync(TEnumerable source, TSource v { comparer ??= EqualityComparer.Default; var enumerator = source.GetAsyncEnumerator(cancellationToken); - await using (enumerator.ConfigureAwait(false)) + try { while (await enumerator.MoveNextAsync().ConfigureAwait(false)) { @@ -57,6 +64,10 @@ static async ValueTask ComparerContainsAsync(TEnumerable source, TSource v return true; } } + finally + { + await enumerator.DisposeAsync().ConfigureAwait(false); + } return false; } } diff --git a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs index e3b5a1041..97965fb1b 100644 --- a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs @@ -9,7 +9,7 @@ public static partial class ArrayExtensions static bool ContainsVector(this ReadOnlySpan source, TSource value) where TSource : struct { - if (source.Length is 0) + if (source.IsEmpty) return false; if (Vector.IsHardwareAccelerated && source.Length > Vector.Count * 2) @@ -42,13 +42,14 @@ static bool ContainsVector(this ReadOnlySpan source, TSource v return false; } + [GeneratorIgnore] static bool ContainsVector(this ReadOnlySpan source, TResult value, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct where TResult : struct { - if (source.Length is 0) + if (source.IsEmpty) return false; if (Vector.IsHardwareAccelerated && source.Length > Vector.Count * 2) diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs index b6fb0e3e6..826da2014 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs @@ -25,12 +25,14 @@ internal ArraySegmentDistinctEnumerable(in ArraySegment source, IEquali => (this.source, this.comparer) = (source, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -81,7 +83,7 @@ public void Dispose() => set.Dispose(); } - readonly Set GetSet() + Set GetSet() { var set = new Set(comparer); foreach (var item in source.AsSpan()) @@ -89,20 +91,38 @@ readonly Set GetSet() return set; } + #region Aggregation + [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() + public int Count() => source switch { { Count: 0 } => 0, _ => GetSet().Count }; + + #endregion + + #region Quantifier [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any() + public bool Any() => source.Count is not 0; + + #endregion + + #region Conversion + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ArraySegmentDistinctEnumerable AsValueEnumerable() + => this; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ArraySegmentDistinctEnumerable AsEnumerable() + => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TSource[] ToArray() + public TSource[] ToArray() => source switch { { Count: 0 } => Array.Empty(), @@ -114,13 +134,15 @@ public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDi => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly List ToList() + public List ToList() => source switch { // ReSharper disable once HeapView.ObjectAllocation.Evident { Count: 0 } => new List(), _ => GetSet().ToList() }; + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs index ead4fb045..d31f4aa05 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs @@ -33,9 +33,10 @@ internal DistinctEnumerable(TEnumerable source, IEqualityComparer? comp => (this.source, this.comparer) = (source, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => new(in this, cancellationToken); - readonly IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this, cancellationToken); @@ -171,7 +172,7 @@ void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) { } } - readonly async ValueTask> FillSetAsync(CancellationToken cancellationToken) + async ValueTask> FillSetAsync(CancellationToken cancellationToken) { var set = new Set(comparer); var enumerator = source.GetAsyncEnumerator(cancellationToken); @@ -187,25 +188,45 @@ readonly async ValueTask> FillSetAsync(CancellationToken cancellati return set; } + #region Aggregation + [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly async ValueTask CountAsync(CancellationToken cancellationToken = default) + public async ValueTask CountAsync(CancellationToken cancellationToken = default) => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).Count; + + #endregion + + #region Quantifier [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueTask AnyAsync(CancellationToken cancellationToken = default) + public ValueTask AnyAsync(CancellationToken cancellationToken = default) => source.AnyAsync(cancellationToken); + + #endregion + + #region Conversion + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public DistinctEnumerable AsValueEnumerable() + => this; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public DistinctEnumerable AsEnumerable() + => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly async ValueTask ToArrayAsync(CancellationToken cancellationToken = default) + public async ValueTask ToArrayAsync(CancellationToken cancellationToken = default) => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly async ValueTask> ToArrayAsync(ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken = default) + public async ValueTask> ToArrayAsync(ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken = default) => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly async ValueTask> ToListAsync(CancellationToken cancellationToken = default) + public async ValueTask> ToListAsync(CancellationToken cancellationToken = default) => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToList(); + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs index 63810e374..75edcc4e8 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryDistinctEnumerable Distinct( this ReadOnlyMemory source, @@ -29,12 +28,14 @@ internal MemoryDistinctEnumerable(ReadOnlyMemory source, IEqualityCompa => (this.source, this.comparer) = (source, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -84,7 +85,7 @@ public void Dispose() => set.Dispose(); } - readonly Set GetSet() + Set GetSet() { var set = new Set(comparer); foreach (var t in source.Span) @@ -92,20 +93,38 @@ readonly Set GetSet() return set; } + #region Aggregation + [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() + public int Count() => source switch { { Length: 0 } => 0, _ => GetSet().Count }; + + #endregion + + #region Quantifier [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any() + public bool Any() => source.Length is not 0; + + #endregion + + #region Conversion + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public MemoryDistinctEnumerable AsValueEnumerable() + => this; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public MemoryDistinctEnumerable AsEnumerable() + => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TSource[] ToArray() + public TSource[] ToArray() => source switch { { Length: 0 } => Array.Empty(), @@ -117,35 +136,15 @@ public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDi => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly List ToList() + public List ToList() => source switch { // ReSharper disable once HeapView.ObjectAllocation.Evident { Length: 0 } => new List(), _ => GetSet().ToList() }; - - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) - { - comparer ??= EqualityComparer.Default; - - using var enumerator = GetEnumerator(); - using var otherEnumerator = other.GetEnumerator(); - while (true) - { - var thisEnded = !enumerator.MoveNext(); - var otherEnded = !otherEnumerator.MoveNext(); - - if (thisEnded != otherEnded) - return false; - - if (thisEnded) - return true; - - if (!comparer.Equals(enumerator.Current!, otherEnumerator.Current)) - return false; - } - } + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs index 4c7c42c09..b422ba564 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(false)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanDistinctEnumerable Distinct( this ReadOnlySpan source, @@ -30,7 +29,7 @@ internal SpanDistinctEnumerable(ReadOnlySpan source, IEqualityComparer< [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); [StructLayout(LayoutKind.Auto)] @@ -68,7 +67,7 @@ public void Dispose() => set.Dispose(); } - readonly Set GetSet() + Set GetSet() { var set = new Set(comparer); foreach (var t in source) @@ -77,7 +76,7 @@ readonly Set GetSet() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() + public int Count() => source.Length switch { 0 => 0, @@ -85,11 +84,11 @@ public readonly int Count() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any() + public bool Any() => source.Length is not 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TSource[] ToArray() + public TSource[] ToArray() => source.Length switch { 0 => Array.Empty(), @@ -101,7 +100,7 @@ public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDi => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly List ToList() + public List ToList() => source.Length switch { // ReSharper disable once HeapView.ObjectAllocation.Evident @@ -109,7 +108,7 @@ public readonly List ToList() _ => GetSet().ToList() }; - public readonly bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) + public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = default) { comparer ??= EqualityComparer.Default; diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs index 9c6a7c772..98112f194 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs @@ -31,12 +31,14 @@ internal DistinctEnumerable(TEnumerable source, IEqualityComparer? comp => (this.source, this.comparer) = (source, comparer); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Enumerator GetEnumerator() + public Enumerator GetEnumerator() => new(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); - readonly IEnumerator IEnumerable.GetEnumerator() + + IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => new Enumerator(in this); @@ -79,6 +81,7 @@ public bool MoveNext() } [ExcludeFromCodeCoverage] + [DoesNotReturn] public readonly void Reset() => Throw.NotSupportedException(); @@ -90,7 +93,7 @@ public void Dispose() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - readonly Set GetSet() + Set GetSet() { using var set = new Set(comparer); using var enumerator = source.GetEnumerator(); @@ -100,15 +103,15 @@ readonly Set GetSet() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() + public int Count() => GetSet().Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any() + public bool Any() => source.Any(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TSource[] ToArray() + public TSource[] ToArray() => GetSet().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -116,7 +119,7 @@ public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDi => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly List ToList() + public List ToList() => GetSet().ToList(); } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index 743706186..12c3e71c6 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -214,22 +214,22 @@ public readonly void CopyTo(TElement[] array, int arrayIndex) => CopyTo(array.AsSpan().Slice(arrayIndex)); [ExcludeFromCodeCoverage] - void ICollection.Add(TElement item) + readonly void ICollection.Add(TElement item) => Throw.NotSupportedException(); [ExcludeFromCodeCoverage] - void ICollection.Clear() + readonly void ICollection.Clear() => Throw.NotSupportedException(); [ExcludeFromCodeCoverage] - bool ICollection.Contains(TElement item) + readonly bool ICollection.Contains(TElement item) => Throw.NotSupportedException(); [ExcludeFromCodeCoverage] - bool ICollection.Remove(TElement item) + readonly bool ICollection.Remove(TElement item) => Throw.NotSupportedException(); [ExcludeFromCodeCoverage] - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() => Throw.NotSupportedException>(); [ExcludeFromCodeCoverage] - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() => Throw.NotSupportedException(); /// diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs deleted file mode 100644 index 77d3778ff..000000000 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.AsyncValueEnumerable.cs +++ /dev/null @@ -1,160 +0,0 @@ -using System.Buffers; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace NetFabric.Hyperlinq -{ - public static partial class AsyncValueEnumerableExtensions - { - - static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - { - var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - while (await enumerator.MoveNextAsync().ConfigureAwait(false)) - { - cancellationToken.ThrowIfCancellationRequested(); - builder.Add(enumerator.Current); - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder; - } - - static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TPredicate : struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - while (await enumerator.MoveNextAsync().ConfigureAwait(false)) - { - cancellationToken.ThrowIfCancellationRequested(); - - var item = enumerator.Current; - if (await predicate.InvokeAsync(item, cancellationToken).ConfigureAwait(false)) - builder.Add(item); - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder; - } - - static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TPredicate : struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - checked - { - for (var index = 0; await enumerator.MoveNextAsync().ConfigureAwait(false); index++) - { - cancellationToken.ThrowIfCancellationRequested(); - - var item = enumerator.Current; - if (await predicate.InvokeAsync(item, index, cancellationToken).ConfigureAwait(false)) - builder.Add(item); - } - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder; - } - - static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TSelector : struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - while (await enumerator.MoveNextAsync().ConfigureAwait(false)) - { - cancellationToken.ThrowIfCancellationRequested(); - - builder.Add(await selector.InvokeAsync(enumerator.Current, cancellationToken).ConfigureAwait(false)); - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder; - } - - static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TSelector : struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - checked - { - for (var index = 0; await enumerator.MoveNextAsync().ConfigureAwait(false); index++) - { - cancellationToken.ThrowIfCancellationRequested(); - - builder.Add(await selector.InvokeAsync(enumerator.Current, index, cancellationToken).ConfigureAwait(false)); - } - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder; - } - - static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TPredicate : struct, IAsyncFunction - where TSelector : struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - while (await enumerator.MoveNextAsync().ConfigureAwait(false)) - { - cancellationToken.ThrowIfCancellationRequested(); - - var item = enumerator.Current; - if (await predicate.InvokeAsync(item, cancellationToken).ConfigureAwait(false)) - builder.Add(await selector.InvokeAsync(item, cancellationToken).ConfigureAwait(false)); - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder; - } - } -} diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs similarity index 95% rename from NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs rename to NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs index 5ac08f295..9688f9b18 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs @@ -3,9 +3,10 @@ namespace NetFabric.Hyperlinq { - public static partial class ValueReadOnlyListExtensions + public static partial class ReadOnlyListExtensions { + [GeneratorIgnore] static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate: struct, IFunction @@ -21,6 +22,7 @@ static LargeArrayBuilder ToArrayBuilder(in return builder; } + [GeneratorIgnore] static LargeArrayBuilder ToArrayBuilderAt(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate: struct, IFunction @@ -48,6 +50,7 @@ static LargeArrayBuilder ToArrayBuilderAt(i return builder; } + [GeneratorIgnore] static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector: struct, IFunction diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs index 47c3cdc71..4bf675d81 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs @@ -6,6 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { + [GeneratorIgnore] static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TPredicate: struct, IFunction { @@ -18,6 +19,7 @@ static LargeArrayBuilder ToArrayBuilder(ReadOnlySp return builder; } + [GeneratorIgnore] static LargeArrayBuilder ToArrayBuilderAt(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TPredicate: struct, IFunction { @@ -31,6 +33,7 @@ static LargeArrayBuilder ToArrayBuilderAt(ReadOnly return builder; } + [GeneratorIgnore] static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate: struct, IFunction where TSelector: struct, IFunction diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs index 8a92f1490..fc060df38 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs @@ -6,6 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { + [GeneratorIgnore] static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -17,6 +18,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -33,6 +35,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -49,6 +52,7 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -61,6 +65,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -76,6 +81,7 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs index b8f153139..4faaf8995 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs @@ -1,5 +1,4 @@ -using System; -using System.Buffers; +using System.Buffers; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -8,12 +7,12 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { - - public static async ValueTask ToArrayBuilderAsync(this TEnumerable source, CancellationToken cancellationToken = default) + [GeneratorIgnore] + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator { - var builder = new LargeArrayBuilder(ArrayPool.Shared, false); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -27,38 +26,16 @@ public static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + [GeneratorIgnore] + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(pool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - while (await enumerator.MoveNextAsync().ConfigureAwait(false)) - { - cancellationToken.ThrowIfCancellationRequested(); - builder.Add(enumerator.Current); - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder.ToArray(pool, clearOnDispose); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - static async ValueTask ToArrayBuilderAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TPredicate: struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(ArrayPool.Shared, false); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -75,70 +52,16 @@ static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TPredicate predicate) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TPredicate: struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(pool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - while (await enumerator.MoveNextAsync().ConfigureAwait(false)) - { - cancellationToken.ThrowIfCancellationRequested(); - - var item = enumerator.Current; - if (await predicate.InvokeAsync(item, cancellationToken).ConfigureAwait(false)) - builder.Add(item); - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder.ToArray(pool, clearOnDispose); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - static async ValueTask ToArrayBuilderAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TPredicate: struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(ArrayPool.Shared, false); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - checked - { - for (var index = 0; await enumerator.MoveNextAsync().ConfigureAwait(false); index++) - { - cancellationToken.ThrowIfCancellationRequested(); - - var item = enumerator.Current; - if (await predicate.InvokeAsync(item, index, cancellationToken).ConfigureAwait(false)) - builder.Add(item); - } - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder.ToArray(); + return builder; } - static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TPredicate predicate) + [GeneratorIgnore] + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator - where TPredicate: struct, IAsyncFunction + where TPredicate : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(pool, clearOnDispose); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -158,17 +81,16 @@ static async ValueTask> ToArrayBuilderAtAsync ToArrayBuilderAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) + [GeneratorIgnore] + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator - where TSelector: struct, IAsyncFunction + where TSelector : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(ArrayPool.Shared, false); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -183,40 +105,16 @@ static async ValueTask ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) + [GeneratorIgnore] + static async ValueTask> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator - where TSelector: struct, IAsyncFunction + where TSelector : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(pool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - while (await enumerator.MoveNextAsync().ConfigureAwait(false)) - { - cancellationToken.ThrowIfCancellationRequested(); - - builder.Add(await selector.InvokeAsync(enumerator.Current, cancellationToken).ConfigureAwait(false)); - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder.ToArray(pool, clearOnDispose); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - static async ValueTask ToArrayBuilderAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TSelector: struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(ArrayPool.Shared, false); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -234,70 +132,17 @@ static async ValueTask ToArrayBuilderAtAsync> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TSelector: struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(pool, clearOnDispose); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - checked - { - for (var index = 0; await enumerator.MoveNextAsync().ConfigureAwait(false); index++) - { - cancellationToken.ThrowIfCancellationRequested(); - - builder.Add(await selector.InvokeAsync(enumerator.Current, index, cancellationToken).ConfigureAwait(false)); - } - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder.ToArray(pool, clearOnDispose); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////// - - static async ValueTask ToArrayBuilderAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TPredicate: struct, IAsyncFunction - where TSelector: struct, IAsyncFunction - { - var builder = new LargeArrayBuilder(ArrayPool.Shared, false); - var enumerator = source.GetAsyncEnumerator(cancellationToken); - try - { - while (await enumerator.MoveNextAsync().ConfigureAwait(false)) - { - cancellationToken.ThrowIfCancellationRequested(); - - var item = enumerator.Current; - if (await predicate.InvokeAsync(item, cancellationToken).ConfigureAwait(false)) - builder.Add(await selector.InvokeAsync(item, cancellationToken).ConfigureAwait(false)); - } - } - finally - { - await enumerator.DisposeAsync().ConfigureAwait(false); - } - return builder.ToArray(); + return builder; } - static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TPredicate predicate, TSelector selector) + [GeneratorIgnore] + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator - where TPredicate: struct, IAsyncFunction - where TSelector: struct, IAsyncFunction + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction { - var builder = new LargeArrayBuilder(pool, clearOnDispose); + var builder = new LargeArrayBuilder(arrayPool, clearOnDispose); var enumerator = source.GetAsyncEnumerator(cancellationToken); try { @@ -314,7 +159,7 @@ static async ValueTask> ToArrayBuilderAsync(TList source, int sourceOffset, Span destination, int count) - where TList : struct, IReadOnlyList - { - Debug.Assert(source.Count >= sourceOffset); - Debug.Assert(destination.Length >= count); - - if (count is 0) - return; - - if (sourceOffset is 0) - { - for (var index = 0; index < count && index < destination.Length; index++) - destination[index] = source[index]; - } - else - { - for (var index = 0; index < count && index < destination.Length; index++) - destination[index] = source[index + sourceOffset]; - } - } - - public static void Copy(TList source, int sourceOffset, Span destination, int count, TSelector selector = default) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - Debug.Assert(source.Count >= sourceOffset); - Debug.Assert(destination.Length >= count); - - if (count is 0) - return; - - if (sourceOffset is 0) - { - for (var index = 0; index < count && index < destination.Length; index++) - destination[index] = selector.Invoke(source[index]); - } - else - { - for (var index = 0; index < count && index < destination.Length; index++) - destination[index] = selector.Invoke(source[index + sourceOffset]); - } - } - - public static void CopyAt(TList source, int sourceOffset, Span destination, int count, TSelector selector = default) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - Debug.Assert(source.Count >= sourceOffset); - Debug.Assert(destination.Length >= count); - - if (count is 0) - return; - - if (sourceOffset is 0) - { - for (var index = 0; index < count && index < destination.Length; index++) - destination[index] = selector.Invoke(source[index], index); - } - else - { - for (var index = 0; index < count && index < destination.Length; index++) - destination[index] = selector.Invoke(source[index + sourceOffset], index); - } - } - - } -} diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs deleted file mode 100644 index f71eeca54..000000000 --- a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlyList.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - static partial class ReadOnlyListExtensions - { - public static int IndexOf(TList source, TSource item, int offset, int count) - where TList : IReadOnlyList - { - if (count is 0) - return -1; - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (offset is 0 && count == source.Count && source is IList list) - return list.IndexOf(item); - - var end = offset + count; - if (Utils.IsValueType()) - { - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (EqualityComparer.Default.Equals(arrayItem, item)) - return index - offset; - } - } - else - { - var defaultComparer = EqualityComparer.Default; - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (defaultComparer.Equals(arrayItem, item)) - return index - offset; - } - } - - return -1; - } - } -} diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs index 422d1dc08..ac734b057 100644 --- a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs @@ -9,7 +9,7 @@ static partial class ArrayExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOf(ReadOnlySpan source, TSource item) { - if (source.Length is 0) + if (source.IsEmpty) return -1; if (Utils.IsValueType()) @@ -39,7 +39,7 @@ public static int IndexOf(ReadOnlySpan source, TSource item) public static int IndexOf(ReadOnlySpan source, TResult item, TSelector selector) where TSelector : struct, IFunction { - if (source.Length is 0) + if (source.IsEmpty) return -1; if (Utils.IsValueType()) @@ -70,7 +70,7 @@ public static int IndexOf(ReadOnlySpan sou public static int IndexOfAt(ReadOnlySpan source, TResult item, TSelector selector) where TSelector : struct, IFunction { - if (source.Length is 0) + if (source.IsEmpty) return -1; if (Utils.IsValueType()) diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyCollection.cs new file mode 100644 index 000000000..d901a4294 --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyCollection.cs @@ -0,0 +1,103 @@ +using System.Collections.Generic; + +namespace NetFabric.Hyperlinq +{ + static partial class ValueReadOnlyCollectionExtensions + { + public static int IndexOf(TEnumerable source, TSource item) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + { + if (source.Count is 0) + return -1; + + using var enumerator = source.GetEnumerator(); + if (Utils.IsValueType()) + { + for (var index = 0; enumerator.MoveNext(); index++) + { + var current = enumerator.Current; + if (EqualityComparer.Default.Equals(current, item)) + return index; + } + } + else + { + var defaultComparer = EqualityComparer.Default; + for (var index = 0; enumerator.MoveNext(); index++) + { + var current = enumerator.Current; + if (defaultComparer.Equals(current, item)) + return index; + } + } + + return -1; + } + + public static int IndexOf(TEnumerable source, TResult item, TSelector selector) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + { + if (source.Count is 0) + return -1; + + using var enumerator = source.GetEnumerator(); + if (Utils.IsValueType()) + { + for (var index = 0; enumerator.MoveNext(); index++) + { + var current = enumerator.Current; + if (EqualityComparer.Default.Equals(selector.Invoke(current), item)) + return index; + } + } + else + { + var defaultComparer = EqualityComparer.Default; + for (var index = 0; enumerator.MoveNext(); index++) + { + var current = enumerator.Current; + if (defaultComparer.Equals(selector.Invoke(current), item)) + return index; + } + } + + return -1; + } + + + public static int IndexOfAt(TEnumerable source, TResult item, TSelector selector) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + { + if (source.Count is 0) + return -1; + + using var enumerator = source.GetEnumerator(); + if (Utils.IsValueType()) + { + for (var index = 0; enumerator.MoveNext(); index++) + { + var current = enumerator.Current; + if (EqualityComparer.Default.Equals(selector.Invoke(current, index), item)) + return index; + } + } + else + { + var defaultComparer = EqualityComparer.Default; + + for (var index = 0; enumerator.MoveNext(); index++) + { + var current = enumerator.Current; + if (defaultComparer.Equals(selector.Invoke(current, index), item)) + return index; + } + } + return -1; + } + } +} diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs deleted file mode 100644 index b9d7b5f19..000000000 --- a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyList.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - static partial class ValueReadOnlyListExtensions - { - public static int IndexOf(TList source, TSource item, int offset, int count) - where TList : struct, IReadOnlyList - { - if (count is 0) - return -1; - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (offset is 0 && count == source.Count && source is IList list) - return list.IndexOf(item); - - var end = offset + count; - if (Utils.IsValueType()) - { - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (EqualityComparer.Default.Equals(arrayItem, item)) - return index - offset; - } - } - else - { - var defaultComparer = EqualityComparer.Default; - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (defaultComparer.Equals(arrayItem, item)) - return index - offset; - } - } - - return -1; - } - - public static int IndexOf(TList source, TResult item, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - if (count is 0) - return -1; - - var end = offset + count; - if (Utils.IsValueType()) - { - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(arrayItem), item)) - return index - offset; - } - } - else - { - var defaultComparer = EqualityComparer.Default; - for (var index = offset; index < end; index++) - { - var arrayItem = source[index]; - if (defaultComparer.Equals(selector.Invoke(arrayItem), item)) - return index - offset; - } - } - - return -1; - } - - - public static int IndexOfAt(TList source, TResult item, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector : struct, IFunction - { - if (count is 0) - return -1; - - if (Utils.IsValueType()) - { - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var listItem = source[index]; - if (EqualityComparer.Default.Equals(selector.Invoke(listItem, index), item)) - return index; - } - } - else - { - for (var index = 0; index < count; index++) - { - var listItem = source[index + offset]; - if (EqualityComparer.Default.Equals(selector.Invoke(listItem, index), item)) - return index; - } - } - } - else - { - var defaultComparer = EqualityComparer.Default; - - if (offset is 0) - { - for (var index = 0; index < count; index++) - { - var listItem = source[index]; - if (defaultComparer.Equals(selector.Invoke(listItem, index), item)) - return index; - } - } - else - { - for (var index = 0; index < count; index++) - { - var listItem = source[index + offset]; - if (defaultComparer.Equals(selector.Invoke(listItem, index), item)) - return index; - } - } - } - return -1; - } - } -} diff --git a/NetFabric.Hyperlinq/Utils/Throw.cs b/NetFabric.Hyperlinq/Utils/Throw.cs index c71a9e110..705ae3841 100644 --- a/NetFabric.Hyperlinq/Utils/Throw.cs +++ b/NetFabric.Hyperlinq/Utils/Throw.cs @@ -7,36 +7,36 @@ namespace NetFabric.Hyperlinq static class Throw { [DoesNotReturn] - public static void ArgumentArraySegmentNullException(string? paramName) - => throw new ArgumentException(Resource.ArraySegmentNull, paramName); + public static void ArgumentArraySegmentNullException(string paramName) + => throw new ArgumentException(paramName: paramName, message: Resource.ArraySegmentNull); [DoesNotReturn] - public static void ArgumentException(string? message, string? paramName) - => throw new ArgumentException(message, paramName); + public static void ArgumentException(string paramName, string? message = default) + => throw new ArgumentException(paramName: paramName, message: message); [DoesNotReturn] - public static void ArgumentNullException(string? paramName) - => throw new ArgumentNullException(paramName); + public static void ArgumentNullException(string paramName, string? message = default) + => throw new ArgumentNullException(paramName: paramName, message: message); [DoesNotReturn] - public static T ArgumentNullException(string? paramName) - => throw new ArgumentNullException(paramName); + public static T ArgumentNullException(string paramName, string? message = default) + => throw new ArgumentNullException(paramName: paramName, message: message); [DoesNotReturn] - public static ref readonly T ArgumentNullExceptionRef(string? paramName) - => throw new ArgumentNullException(paramName); + public static ref readonly T ArgumentNullExceptionRef(string paramName, string? message = default) + => throw new ArgumentNullException(paramName: paramName, message: message); [DoesNotReturn] - public static void ArgumentOutOfRangeException(string? paramName) - => throw new ArgumentOutOfRangeException(paramName); + public static void ArgumentOutOfRangeException(string paramName, string? message = default) + => throw new ArgumentOutOfRangeException(paramName: paramName, message: message); [DoesNotReturn] - public static T ArgumentOutOfRangeException(string? paramName) - => throw new ArgumentOutOfRangeException(paramName); + public static T ArgumentOutOfRangeException(string paramName, string? message = default) + => throw new ArgumentOutOfRangeException(paramName: paramName, message: message); [DoesNotReturn] - public static ref readonly T ArgumentOutOfRangeExceptionRef(string? paramName) - => throw new ArgumentOutOfRangeException(paramName); + public static ref readonly T ArgumentOutOfRangeExceptionRef(string paramName, string? message = default) + => throw new ArgumentOutOfRangeException(paramName: paramName, message: message); [DoesNotReturn] public static void EmptySequence() @@ -63,11 +63,7 @@ public static ref readonly T NotSingleSequenceRef() => throw new InvalidOperationException(Resource.NotSingleSequence); [DoesNotReturn] - public static void InvalidOperationException() - => throw new InvalidOperationException(); - - [DoesNotReturn] - public static void InvalidOperationException(string? message) + public static void InvalidOperationException(string? message = default) => throw new InvalidOperationException(message); [DoesNotReturn] @@ -83,7 +79,7 @@ public static T NotSupportedException() => throw new NotSupportedException(); [DoesNotReturn] - public static void ObjectDisposedException(string? objectName) + public static void ObjectDisposedException(string objectName) => throw new ObjectDisposedException(objectName); } } diff --git a/NetFabric.Hyperlinq/Utils/ThrowIfArgument.cs b/NetFabric.Hyperlinq/Utils/ThrowIfArgument.cs new file mode 100644 index 000000000..7b48dcff6 --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/ThrowIfArgument.cs @@ -0,0 +1,26 @@ +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class ThrowIfArgument + { + // [DebuggerStepThrough] + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static void Null([DoesNotReturnIf()]T paramValue, /*[CallerArgumentExpression("paramValue")]*/ string paramName) + // { + // if (paramValue is null) + // Throw.ArgumentNullException(paramName); + // } + + [DebuggerStepThrough] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void OutOfRange(int paramValue, int maxValue, /*[CallerArgumentExpression("paramValue")]*/ string paramName) + { + if ((uint)paramValue >= (uint)maxValue) + Throw.ArgumentOutOfRangeException(paramName); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs b/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs index a5d244d30..4eeb6f538 100644 --- a/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs +++ b/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs @@ -8,8 +8,9 @@ static partial class Utils [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] AllocateUninitializedArray(int count) #if NET5_0_OR_GREATER - => GC.AllocateUninitializedArray(count); + => GC.AllocateUninitializedArray(count, pinned: false); #else + // ReSharper disable once HeapView.ObjectAllocation.Evident => new T[count]; #endif } diff --git a/NuGet.config b/NuGet.config index f3c7e1ed8..33baf744e 100755 --- a/NuGet.config +++ b/NuGet.config @@ -8,8 +8,7 @@ - - + From 01017e195edad1e54ea14b056c1ea5b03b7ce6d1 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sat, 5 Jun 2021 18:16:19 +0100 Subject: [PATCH 34/61] Update benchmark results --- Benchmarks/AggressiveInliningBenchmarks.md | 8 +- Benchmarks/AllBenchmarks.md | 68 ++++++------- Benchmarks/AnyBenchmarks.md | 68 ++++++------- Benchmarks/AnyPredicateBenchmarks.md | 48 +++++----- Benchmarks/ArrayIterationBenchmarks.md | 24 ++--- Benchmarks/ArrayToArrayBenchmarks.md | 30 +++--- Benchmarks/ContainsBenchmarks.md | 50 +++++----- Benchmarks/ContainsComparerBenchmarks.md | 68 ++++++------- Benchmarks/CountBenchmarks.md | 82 ++++++++-------- Benchmarks/DistinctBenchmarks.md | 86 ++++++++--------- Benchmarks/ElementAtBenchmarks.md | 68 ++++++------- Benchmarks/EmptyBenchmarks.md | 20 ++-- Benchmarks/FirstBenchmarks.md | 68 ++++++------- Benchmarks/ListIterationBenchmarks.md | 26 ++--- Benchmarks/RangeBenchmarks.md | 28 +++--- Benchmarks/RangeToArrayBenchmarks.md | 30 +++--- Benchmarks/ReadOnlyFieldsBenchmarks.md | 10 +- Benchmarks/RepeatBenchmarks.md | 22 ++--- Benchmarks/RepeatToArrayBenchmarks.md | 26 ++--- Benchmarks/ReturnBenchmarks.md | 26 ++--- Benchmarks/SelectBenchmarks.md | 74 +++++++------- Benchmarks/SelectCountBenchmarks.md | 62 ++++++------ Benchmarks/SelectManyBenchmarks.md | 66 ++++++------- Benchmarks/SelectSumBenchmarks.md | 64 ++++++------- Benchmarks/SelectToArrayBenchmarks.md | 86 ++++++++--------- Benchmarks/SelectToListBenchmarks.md | 84 ++++++++-------- Benchmarks/SingleBenchmarks.md | 44 ++++----- Benchmarks/SkipTakeBenchmarks.md | 96 +++++++++---------- Benchmarks/SumBenchmarks.md | 84 ++++++++-------- Benchmarks/ToArrayBenchmarks.md | 58 +++++------ Benchmarks/ToListBenchmarks.md | 82 ++++++++-------- Benchmarks/WhereBenchmarks.md | 86 ++++++++--------- Benchmarks/WhereCountBenchmarks.md | 66 ++++++------- Benchmarks/WhereFirstBenchmarks.md | 68 ++++++------- Benchmarks/WhereSelectBenchmarks.md | 86 ++++++++--------- Benchmarks/WhereSelectCountBenchmarks.md | 48 +++++----- Benchmarks/WhereSingleBenchmarks.md | 64 ++++++------- Benchmarks/WhereToArrayBenchmarks.md | 82 ++++++++-------- Benchmarks/WhereToListBenchmarks.md | 82 ++++++++-------- .../NetFabric.Hyperlinq.Benchmarks.csproj | 2 +- 40 files changed, 1119 insertions(+), 1121 deletions(-) diff --git a/Benchmarks/AggressiveInliningBenchmarks.md b/Benchmarks/AggressiveInliningBenchmarks.md index 59c7c15fc..300f8a9cc 100644 --- a/Benchmarks/AggressiveInliningBenchmarks.md +++ b/Benchmarks/AggressiveInliningBenchmarks.md @@ -14,16 +14,16 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-HOBYXY : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------- |------ |---------:|--------:|--------:|------:|------:|------:|------:|----------:| -| Baseline | 1000 | 609.3 ns | 5.50 ns | 5.14 ns | 1.00 | - | - | - | - | -| AggressiveInlining | 1000 | 611.9 ns | 4.64 ns | 4.34 ns | 1.00 | - | - | - | - | +| Baseline | 1000 | 544.3 ns | 0.85 ns | 0.67 ns | 1.00 | - | - | - | - | +| AggressiveInlining | 1000 | 544.4 ns | 1.39 ns | 1.23 ns | 1.00 | - | - | - | - | diff --git a/Benchmarks/AllBenchmarks.md b/Benchmarks/AllBenchmarks.md index fc67a27eb..afb4834e0 100644 --- a/Benchmarks/AllBenchmarks.md +++ b/Benchmarks/AllBenchmarks.md @@ -4,50 +4,50 @@ [AllBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 592.0 ns | 2.18 ns | 1.82 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 193.8 ns | 1.53 ns | 1.28 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 757.1 ns | 9.53 ns | 8.92 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 228.8 ns | 1.41 ns | 1.25 ns | 0.30 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 750.8 ns | 2.92 ns | 2.74 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 206.9 ns | 1.60 ns | 1.34 ns | 0.28 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 729.5 ns | 6.13 ns | 5.12 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 614.8 ns | 6.33 ns | 5.92 ns | 0.84 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,847.2 ns | 9.89 ns | 8.77 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 273.3 ns | 1.04 ns | 0.92 ns | 0.15 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 726.7 ns | 3.21 ns | 3.00 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 780.2 ns | 6.27 ns | 5.23 ns | 1.07 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 754.7 ns | 7.32 ns | 6.11 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 757.3 ns | 3.90 ns | 3.65 ns | 1.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 724.9 ns | 4.12 ns | 3.85 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 611.9 ns | 2.85 ns | 2.66 ns | 0.84 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,846.2 ns | 6.31 ns | 5.90 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 301.6 ns | 2.90 ns | 2.27 ns | 0.16 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 591.1 ns | 11.49 ns | 10.18 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 192.5 ns | 0.77 ns | 0.60 ns | 0.33 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 770.8 ns | 2.82 ns | 2.64 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 253.3 ns | 2.04 ns | 1.81 ns | 0.33 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 721.0 ns | 3.54 ns | 3.14 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 254.7 ns | 0.98 ns | 0.87 ns | 0.35 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 752.7 ns | 12.49 ns | 9.75 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 777.2 ns | 5.69 ns | 4.44 ns | 1.03 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,709.2 ns | 3.68 ns | 3.45 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 251.1 ns | 0.52 ns | 0.46 ns | 0.15 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 721.5 ns | 3.10 ns | 2.90 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 751.9 ns | 3.21 ns | 2.84 ns | 1.04 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 769.8 ns | 2.26 ns | 2.11 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 789.2 ns | 7.33 ns | 6.12 ns | 1.03 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 775.5 ns | 6.94 ns | 6.15 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 729.0 ns | 2.96 ns | 2.77 ns | 0.94 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,709.5 ns | 4.61 ns | 3.85 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 278.8 ns | 0.94 ns | 0.88 ns | 0.16 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyBenchmarks.md b/Benchmarks/AnyBenchmarks.md index dd768d084..6e6d7f9a6 100644 --- a/Benchmarks/AnyBenchmarks.md +++ b/Benchmarks/AnyBenchmarks.md @@ -4,50 +4,50 @@ [AnyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 8.874 ns | 0.0473 ns | 0.0442 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 8.295 ns | 0.0321 ns | 0.0300 ns | 0.93 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 21.884 ns | 0.1573 ns | 0.1314 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 11.296 ns | 0.0425 ns | 0.0332 ns | 0.52 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 5.370 ns | 0.1195 ns | 0.1118 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.238 ns | 0.0508 ns | 0.0476 ns | 1.53 | 0.03 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.860 ns | 0.0582 ns | 0.0544 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.569 ns | 0.0238 ns | 0.0199 ns | 0.27 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 62.273 ns | 0.4126 ns | 0.3222 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 52.364 ns | 0.1373 ns | 0.1146 ns | 0.84 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 22.123 ns | 0.3594 ns | 0.3361 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 13.315 ns | 0.0734 ns | 0.0650 ns | 0.60 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 5.171 ns | 0.0717 ns | 0.0635 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.568 ns | 0.0145 ns | 0.0135 ns | 0.30 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.851 ns | 0.0434 ns | 0.0406 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.552 ns | 0.0120 ns | 0.0100 ns | 0.26 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 61.675 ns | 0.2805 ns | 0.2624 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 58.200 ns | 0.1898 ns | 0.1585 ns | 0.94 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 8.436 ns | 0.1408 ns | 0.1176 ns | 8.406 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.380 ns | 0.0238 ns | 0.0223 ns | 7.380 ns | 0.88 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 22.024 ns | 0.1236 ns | 0.1156 ns | 22.052 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 10.720 ns | 0.0205 ns | 0.0181 ns | 10.720 ns | 0.49 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 4.119 ns | 0.0185 ns | 0.0173 ns | 4.116 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.241 ns | 0.0261 ns | 0.0245 ns | 8.247 ns | 2.00 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 5.525 ns | 0.0291 ns | 0.0258 ns | 5.520 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.823 ns | 0.0178 ns | 0.0158 ns | 1.820 ns | 0.33 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 56.994 ns | 0.1735 ns | 0.1623 ns | 57.011 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 50.052 ns | 0.2120 ns | 0.1983 ns | 49.988 ns | 0.88 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 20.335 ns | 0.2451 ns | 0.1914 ns | 20.339 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 13.766 ns | 0.0889 ns | 0.0788 ns | 13.778 ns | 0.68 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.552 ns | 0.0522 ns | 0.0463 ns | 4.535 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.825 ns | 0.0144 ns | 0.0135 ns | 1.830 ns | 0.40 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 5.502 ns | 0.0440 ns | 0.0343 ns | 5.515 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.567 ns | 0.0071 ns | 0.0063 ns | 1.568 ns | 0.28 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 58.054 ns | 0.6036 ns | 0.5646 ns | 57.922 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 55.955 ns | 1.1523 ns | 1.4983 ns | 56.983 ns | 0.95 | 0.02 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyPredicateBenchmarks.md b/Benchmarks/AnyPredicateBenchmarks.md index 01afe1f1e..201bbbd87 100644 --- a/Benchmarks/AnyPredicateBenchmarks.md +++ b/Benchmarks/AnyPredicateBenchmarks.md @@ -4,50 +4,50 @@ [AnyPredicateBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 591.00 ns | 1.814 ns | 1.608 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 192.91 ns | 1.138 ns | 1.065 ns | 0.33 | - | - | - | - | +| Linq_Array | Array | 100 | 543.31 ns | 2.697 ns | 2.522 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 168.72 ns | 0.710 ns | 0.630 ns | 0.31 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 751.43 ns | 3.851 ns | 6.844 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 227.78 ns | 1.197 ns | 1.120 ns | 0.30 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 786.29 ns | 5.005 ns | 4.437 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 252.75 ns | 1.126 ns | 1.053 ns | 0.32 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 751.53 ns | 3.422 ns | 3.201 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 207.85 ns | 1.383 ns | 1.155 ns | 0.28 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 781.50 ns | 5.224 ns | 4.362 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 255.94 ns | 1.076 ns | 1.006 ns | 0.33 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 749.40 ns | 4.345 ns | 3.628 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 612.27 ns | 2.321 ns | 2.057 ns | 0.82 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 781.62 ns | 6.332 ns | 5.287 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 782.55 ns | 2.793 ns | 2.476 ns | 1.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,869.98 ns | 7.385 ns | 6.908 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 77.90 ns | 0.339 ns | 0.283 ns | 0.04 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,715.16 ns | 3.292 ns | 2.918 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 76.40 ns | 0.203 ns | 0.180 ns | 0.04 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 725.02 ns | 2.412 ns | 2.256 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 784.85 ns | 2.119 ns | 1.878 ns | 1.08 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 782.33 ns | 5.113 ns | 4.270 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 739.43 ns | 3.734 ns | 3.310 ns | 0.95 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 751.31 ns | 2.980 ns | 2.327 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 739.72 ns | 3.044 ns | 2.542 ns | 0.98 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 732.78 ns | 3.178 ns | 2.654 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 781.34 ns | 2.436 ns | 2.159 ns | 1.07 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 750.60 ns | 5.104 ns | 4.775 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 618.04 ns | 1.425 ns | 1.264 ns | 0.82 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 734.11 ns | 2.595 ns | 2.300 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 740.49 ns | 3.347 ns | 2.967 ns | 1.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,845.41 ns | 8.015 ns | 7.497 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 81.29 ns | 0.305 ns | 0.270 ns | 0.04 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,716.97 ns | 4.259 ns | 3.776 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 77.91 ns | 0.321 ns | 0.284 ns | 0.05 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 6ba38545a..082855f4b 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -14,22 +14,22 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-CGYYAC : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|----------------------------- |-------- |-----------:|---------:|---------:|------:|--------:|------:|------:|------:|----------:| -| Foreach | 1000000 | 454.5 μs | 3.61 μs | 3.37 μs | 1.00 | 0.00 | - | - | - | - | -| For | 1000000 | 452.5 μs | 3.69 μs | 3.27 μs | 1.00 | 0.01 | - | - | - | - | -| For_Unsafe | 1000000 | 450.1 μs | 2.38 μs | 1.98 μs | 0.99 | 0.01 | - | - | - | - | -| Span | 1000000 | 452.9 μs | 2.16 μs | 1.91 μs | 1.00 | 0.01 | - | - | - | - | -| ArraySegment_Foreach | 1000000 | 2,882.3 μs | 18.69 μs | 16.57 μs | 6.34 | 0.05 | - | - | - | 1 B | -| ArraySegment_For | 1000000 | 835.7 μs | 6.87 μs | 6.43 μs | 1.84 | 0.01 | - | - | - | - | -| ArraySegment_Expanded_For | 1000000 | 1,346.8 μs | 7.64 μs | 6.77 μs | 2.96 | 0.03 | - | - | - | - | -| ArraySegment_Wrapper_Foreach | 1000000 | 1,492.8 μs | 8.99 μs | 7.51 μs | 3.29 | 0.03 | - | - | - | - | +| Method | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|----------------------------- |-------- |-----------:|---------:|---------:|-----------:|------:|--------:|------:|------:|------:|----------:| +| Foreach | 1000000 | 450.5 μs | 12.65 μs | 37.29 μs | 424.6 μs | 1.00 | 0.00 | - | - | - | - | +| For | 1000000 | 418.6 μs | 2.47 μs | 1.93 μs | 418.4 μs | 0.86 | 0.05 | - | - | - | - | +| For_Unsafe | 1000000 | 498.8 μs | 4.77 μs | 4.46 μs | 496.8 μs | 1.02 | 0.06 | - | - | - | - | +| Span | 1000000 | 421.8 μs | 2.60 μs | 2.43 μs | 421.8 μs | 0.86 | 0.05 | - | - | - | - | +| ArraySegment_Foreach | 1000000 | 2,816.0 μs | 5.71 μs | 5.06 μs | 2,816.0 μs | 5.78 | 0.30 | - | - | - | 1 B | +| ArraySegment_For | 1000000 | 815.9 μs | 2.95 μs | 5.47 μs | 814.6 μs | 1.81 | 0.15 | - | - | - | - | +| ArraySegment_Expanded_For | 1000000 | 1,327.3 μs | 5.61 μs | 4.98 μs | 1,328.7 μs | 2.72 | 0.14 | - | - | - | - | +| ArraySegment_Wrapper_Foreach | 1000000 | 1,577.4 μs | 5.57 μs | 5.21 μs | 1,577.6 μs | 3.23 | 0.16 | - | - | - | - | diff --git a/Benchmarks/ArrayToArrayBenchmarks.md b/Benchmarks/ArrayToArrayBenchmarks.md index af4a033b1..558de7565 100644 --- a/Benchmarks/ArrayToArrayBenchmarks.md +++ b/Benchmarks/ArrayToArrayBenchmarks.md @@ -14,25 +14,25 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-ERYMHU : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|----------------- |------ |-----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| **ArrayClone** | **10** | **83.162 ns** | **0.9078 ns** | **0.8491 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | -| SpanToArray | 10 | 7.645 ns | 0.0932 ns | 0.0872 ns | 0.09 | 0.00 | 0.0306 | - | - | 64 B | -| CollectionCopyTo | 10 | 15.119 ns | 0.3594 ns | 0.2806 ns | 0.18 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| **ArrayClone** | **100** | **91.453 ns** | **1.2853 ns** | **1.2023 ns** | **1.00** | **0.00** | **0.2021** | **-** | **-** | **424 B** | -| SpanToArray | 100 | 30.949 ns | 0.6774 ns | 0.6336 ns | 0.34 | 0.01 | 0.2027 | - | - | 424 B | -| CollectionCopyTo | 100 | 38.433 ns | 0.7989 ns | 0.8204 ns | 0.42 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | -| **ArrayClone** | **1000** | **243.403 ns** | **4.9315 ns** | **5.8706 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | -| SpanToArray | 1000 | 250.213 ns | 4.9555 ns | 5.5080 ns | 1.03 | 0.03 | 1.9226 | - | - | 4,024 B | -| CollectionCopyTo | 1000 | 242.564 ns | 3.3163 ns | 3.1020 ns | 1.00 | 0.02 | 1.9155 | - | - | 4,024 B | +| Method | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|----------------- |------ |-----------:|----------:|----------:|-----------:|------:|--------:|-------:|------:|------:|----------:| +| **ArrayClone** | **10** | **83.187 ns** | **0.5856 ns** | **0.5191 ns** | **83.125 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | +| SpanToArray | 10 | 7.938 ns | 0.1489 ns | 0.1320 ns | 7.921 ns | 0.10 | 0.00 | 0.0306 | - | - | 64 B | +| CollectionCopyTo | 10 | 16.725 ns | 0.1057 ns | 0.0989 ns | 16.735 ns | 0.20 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| **ArrayClone** | **100** | **91.920 ns** | **0.4655 ns** | **0.4127 ns** | **91.959 ns** | **1.00** | **0.00** | **0.2021** | **-** | **-** | **424 B** | +| SpanToArray | 100 | 33.381 ns | 0.7700 ns | 2.2702 ns | 32.260 ns | 0.39 | 0.02 | 0.2027 | - | - | 424 B | +| CollectionCopyTo | 100 | 39.932 ns | 0.7754 ns | 0.6874 ns | 39.978 ns | 0.43 | 0.01 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | +| **ArrayClone** | **1000** | **284.629 ns** | **3.2346 ns** | **2.7010 ns** | **284.130 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | +| SpanToArray | 1000 | 258.078 ns | 1.8823 ns | 1.6686 ns | 258.441 ns | 0.91 | 0.01 | 1.9226 | - | - | 4,024 B | +| CollectionCopyTo | 1000 | 245.347 ns | 3.6884 ns | 3.4501 ns | 244.683 ns | 0.86 | 0.01 | 1.9155 | - | - | 4,024 B | diff --git a/Benchmarks/ContainsBenchmarks.md b/Benchmarks/ContainsBenchmarks.md index 1747f8d66..5761e7884 100644 --- a/Benchmarks/ContainsBenchmarks.md +++ b/Benchmarks/ContainsBenchmarks.md @@ -4,51 +4,51 @@ [ContainsBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 40.65 ns | 0.211 ns | 0.176 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 30.31 ns | 0.198 ns | 0.176 ns | 0.75 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 25.58 ns | 0.120 ns | 0.106 ns | 0.63 | - | - | - | - | +| Linq_Array | Array | 100 | 38.54 ns | 0.188 ns | 0.167 ns | 1.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 30.81 ns | 0.105 ns | 0.093 ns | 0.80 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 23.83 ns | 0.079 ns | 0.074 ns | 0.62 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 656.14 ns | 1.460 ns | 1.366 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 295.03 ns | 1.379 ns | 1.290 ns | 0.45 | 0.0191 | - | - | 40 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 627.99 ns | 5.507 ns | 4.598 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 199.88 ns | 0.929 ns | 0.823 ns | 0.32 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 36.24 ns | 0.165 ns | 0.146 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 39.45 ns | 0.147 ns | 0.131 ns | 1.09 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 36.85 ns | 0.196 ns | 0.183 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 39.51 ns | 0.242 ns | 0.226 ns | 1.07 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 36.89 ns | 0.126 ns | 0.112 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 40.04 ns | 0.165 ns | 0.155 ns | 1.08 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 37.52 ns | 0.208 ns | 0.184 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 39.57 ns | 0.125 ns | 0.104 ns | 1.05 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,818.57 ns | 3.937 ns | 3.288 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,118.84 ns | 2.749 ns | 2.295 ns | 0.62 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,616.30 ns | 3.258 ns | 2.888 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 942.80 ns | 2.209 ns | 2.066 ns | 0.58 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 658.64 ns | 5.196 ns | 4.057 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 660.32 ns | 3.563 ns | 3.158 ns | 1.00 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 632.57 ns | 3.394 ns | 3.174 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 687.02 ns | 6.790 ns | 5.670 ns | 1.09 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 35.92 ns | 0.107 ns | 0.095 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 39.33 ns | 0.105 ns | 0.088 ns | 1.10 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 36.59 ns | 0.167 ns | 0.148 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 38.74 ns | 0.180 ns | 0.150 ns | 1.06 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 37.08 ns | 0.130 ns | 0.122 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 39.94 ns | 0.186 ns | 0.165 ns | 1.08 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 37.41 ns | 0.140 ns | 0.131 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 40.01 ns | 0.271 ns | 0.226 ns | 1.07 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,821.71 ns | 4.026 ns | 3.569 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,889.72 ns | 6.468 ns | 6.050 ns | 1.04 | 0.0267 | - | - | 56 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,628.33 ns | 3.355 ns | 2.975 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,742.85 ns | 7.018 ns | 6.221 ns | 1.07 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ContainsComparerBenchmarks.md b/Benchmarks/ContainsComparerBenchmarks.md index 30db67ce5..bcfde4f5f 100644 --- a/Benchmarks/ContainsComparerBenchmarks.md +++ b/Benchmarks/ContainsComparerBenchmarks.md @@ -4,50 +4,50 @@ [ContainsComparerBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 578.2 ns | 3.96 ns | 3.51 ns | 577.6 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 202.2 ns | 4.07 ns | 3.61 ns | 200.9 ns | 0.35 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 791.8 ns | 4.20 ns | 3.72 ns | 790.5 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 331.3 ns | 1.38 ns | 1.22 ns | 331.7 ns | 0.42 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 762.0 ns | 2.87 ns | 2.69 ns | 761.8 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 334.3 ns | 1.35 ns | 1.20 ns | 333.9 ns | 0.44 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 792.8 ns | 7.00 ns | 6.20 ns | 790.8 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 651.0 ns | 2.01 ns | 1.88 ns | 651.6 ns | 0.82 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,881.0 ns | 24.51 ns | 42.93 ns | 1,865.7 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,130.2 ns | 6.01 ns | 4.69 ns | 1,129.5 ns | 0.59 | 0.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 799.4 ns | 13.46 ns | 23.58 ns | 790.3 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 796.2 ns | 15.83 ns | 15.55 ns | 789.4 ns | 0.99 | 0.05 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 763.8 ns | 3.89 ns | 3.45 ns | 763.3 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 839.9 ns | 16.22 ns | 21.66 ns | 827.3 ns | 1.10 | 0.03 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 760.8 ns | 2.52 ns | 2.23 ns | 760.6 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 679.7 ns | 5.17 ns | 4.58 ns | 679.4 ns | 0.89 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,866.1 ns | 3.78 ns | 3.35 ns | 1,866.0 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,870.3 ns | 3.93 ns | 3.48 ns | 1,871.0 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 575.8 ns | 2.05 ns | 1.71 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 199.6 ns | 0.61 ns | 0.54 ns | 0.35 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 781.4 ns | 3.23 ns | 2.86 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 277.7 ns | 1.33 ns | 1.25 ns | 0.36 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 764.8 ns | 4.02 ns | 3.76 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 283.1 ns | 1.37 ns | 1.21 ns | 0.37 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 757.7 ns | 5.42 ns | 4.81 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 784.6 ns | 2.73 ns | 2.55 ns | 1.04 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,724.8 ns | 4.29 ns | 4.02 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 925.7 ns | 2.06 ns | 1.82 ns | 0.54 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 757.5 ns | 3.90 ns | 3.46 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 759.2 ns | 3.28 ns | 2.90 ns | 1.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 780.0 ns | 2.86 ns | 2.54 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 794.5 ns | 4.30 ns | 4.02 ns | 1.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 756.6 ns | 3.25 ns | 2.88 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 810.1 ns | 2.14 ns | 1.67 ns | 1.07 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,727.3 ns | 5.91 ns | 5.24 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,719.1 ns | 4.03 ns | 3.58 ns | 1.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/CountBenchmarks.md b/Benchmarks/CountBenchmarks.md index 5250c04b2..80b8c2fb6 100644 --- a/Benchmarks/CountBenchmarks.md +++ b/Benchmarks/CountBenchmarks.md @@ -4,57 +4,57 @@ [CountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |--------------:|----------:|----------:|--------------:|-------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 10.3993 ns | 0.0441 ns | 0.0368 ns | 10.3876 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Array | Array | 100 | 0.9824 ns | 0.0801 ns | 0.2324 ns | 0.8387 ns | 0.10 | 0.01 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 7.7113 ns | 0.0235 ns | 0.0220 ns | 7.7153 ns | 0.74 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 356.9077 ns | 1.8740 ns | 1.6612 ns | 356.6942 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 576.8413 ns | 2.4870 ns | 2.2046 ns | 576.5287 ns | 1.62 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 142.7680 ns | 0.3979 ns | 0.3722 ns | 142.7317 ns | 0.40 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.6516 ns | 0.0187 ns | 0.0156 ns | 4.6471 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Value | Collection_Value | 100 | 602.4877 ns | 3.4145 ns | 3.1939 ns | 602.2316 ns | 129.35 | 0.83 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.5152 ns | 0.0144 ns | 0.0134 ns | 7.5154 ns | 1.62 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.5309 ns | 0.0427 ns | 0.0378 ns | 5.5097 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Value | List_Value | 100 | 2.1173 ns | 0.0114 ns | 0.0095 ns | 2.1155 ns | 0.38 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.5830 ns | 0.0067 ns | 0.0056 ns | 1.5826 ns | 0.29 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,798.5748 ns | 4.3133 ns | 3.8236 ns | 1,798.4897 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 937.4144 ns | 2.1488 ns | 2.0100 ns | 937.4766 ns | 0.52 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 348.9051 ns | 1.3518 ns | 1.1288 ns | 349.2017 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 604.3288 ns | 1.6966 ns | 1.3246 ns | 604.4109 ns | 1.73 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 365.9486 ns | 2.2888 ns | 2.0290 ns | 365.5504 ns | 1.05 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.6149 ns | 0.0363 ns | 0.0322 ns | 4.6059 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 576.8288 ns | 1.9345 ns | 1.7149 ns | 576.9421 ns | 125.00 | 0.98 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.5439 ns | 0.0139 ns | 0.0116 ns | 1.5435 ns | 0.33 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.4194 ns | 0.0493 ns | 0.0385 ns | 5.4114 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Reference | List_Reference | 100 | 576.9825 ns | 3.0149 ns | 2.6726 ns | 576.4323 ns | 106.53 | 0.70 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.6144 ns | 0.0079 ns | 0.0066 ns | 1.6134 ns | 0.30 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,793.2356 ns | 5.6385 ns | 5.2742 ns | 1,790.5483 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,562.0711 ns | 5.7935 ns | 5.1358 ns | 1,561.1134 ns | 0.87 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |--------------:|----------:|----------:|-------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 9.1074 ns | 0.0784 ns | 0.0655 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Array | Array | 100 | 0.6715 ns | 0.0133 ns | 0.0125 ns | 0.07 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.9661 ns | 0.0225 ns | 0.0210 ns | 0.87 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 349.7961 ns | 3.6308 ns | 3.3963 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 598.2427 ns | 2.5847 ns | 2.0180 ns | 1.71 | 0.02 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 141.0781 ns | 0.2799 ns | 0.2618 ns | 0.40 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 4.0306 ns | 0.0247 ns | 0.0207 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Value | Collection_Value | 100 | 651.6739 ns | 4.1784 ns | 3.4892 ns | 161.69 | 1.35 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.7398 ns | 0.0236 ns | 0.0209 ns | 1.92 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 5.0033 ns | 0.0309 ns | 0.0274 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Value | List_Value | 100 | 2.0895 ns | 0.0152 ns | 0.0143 ns | 0.42 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.7885 ns | 0.0177 ns | 0.0157 ns | 0.36 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,617.7575 ns | 5.5046 ns | 4.2976 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 776.3272 ns | 2.0551 ns | 1.7161 ns | 0.48 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 347.5843 ns | 1.2942 ns | 1.1473 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 648.1673 ns | 3.0979 ns | 2.7462 ns | 1.86 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 382.5596 ns | 3.7097 ns | 3.2886 ns | 1.10 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.1545 ns | 0.0403 ns | 0.0377 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 596.9610 ns | 1.8706 ns | 1.6583 ns | 143.75 | 1.49 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.7762 ns | 0.0103 ns | 0.0091 ns | 0.43 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 4.9565 ns | 0.0651 ns | 0.0577 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Reference | List_Reference | 100 | 604.8412 ns | 3.4385 ns | 3.2164 ns | 122.05 | 1.78 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.7892 ns | 0.0157 ns | 0.0140 ns | 0.36 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,617.0364 ns | 4.1368 ns | 3.8696 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,416.2269 ns | 3.3714 ns | 2.9887 ns | 0.88 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/DistinctBenchmarks.md b/Benchmarks/DistinctBenchmarks.md index d6d6c71b1..9500dce6b 100644 --- a/Benchmarks/DistinctBenchmarks.md +++ b/Benchmarks/DistinctBenchmarks.md @@ -4,59 +4,59 @@ [DistinctBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |---------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 2.886 μs | 0.0206 μs | 0.0193 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Array | Array | 100 | 1.329 μs | 0.0132 μs | 0.0123 μs | 0.46 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 1.515 μs | 0.0091 μs | 0.0085 μs | 0.52 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 1.513 μs | 0.0080 μs | 0.0071 μs | 0.52 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.638 μs | 0.0081 μs | 0.0067 μs | 0.57 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.192 μs | 0.0208 μs | 0.0184 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.264 μs | 0.0147 μs | 0.0138 μs | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.513 μs | 0.0082 μs | 0.0077 μs | 0.47 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 3.177 μs | 0.0116 μs | 0.0109 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 2.255 μs | 0.0174 μs | 0.0154 μs | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.611 μs | 0.0198 μs | 0.0175 μs | 0.51 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 3.194 μs | 0.0141 μs | 0.0125 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_List_Value | List_Value | 100 | 1.479 μs | 0.0083 μs | 0.0073 μs | 0.46 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 2.150 μs | 0.0131 μs | 0.0102 μs | 0.67 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.507 μs | 0.0173 μs | 0.0153 μs | 1.00 | 2.0599 | - | - | 4,320 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.560 μs | 0.0202 μs | 0.0169 μs | 0.61 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 3.193 μs | 0.0142 μs | 0.0119 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.267 μs | 0.0097 μs | 0.0086 μs | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.695 μs | 0.0076 μs | 0.0063 μs | 0.84 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 3.201 μs | 0.0086 μs | 0.0076 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 2.272 μs | 0.0070 μs | 0.0058 μs | 0.71 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.684 μs | 0.0058 μs | 0.0055 μs | 0.84 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 3.231 μs | 0.0276 μs | 0.0230 μs | 1.00 | 2.0599 | - | - | 4,312 B | -| StructLinq_List_Reference | List_Reference | 100 | 2.264 μs | 0.0130 μs | 0.0115 μs | 0.70 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.961 μs | 0.0073 μs | 0.0064 μs | 0.61 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.527 μs | 0.0221 μs | 0.0196 μs | 1.00 | 2.0599 | - | - | 4,320 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5.132 μs | 0.0460 μs | 0.0408 μs | 0.68 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |---------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 1.902 μs | 0.0359 μs | 0.0336 μs | 1.00 | 0.00 | 1.3294 | - | - | 2,784 B | +| StructLinq_Array | Array | 100 | 1.271 μs | 0.0052 μs | 0.0046 μs | 0.67 | 0.01 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 1.476 μs | 0.0065 μs | 0.0060 μs | 0.78 | 0.01 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 1.529 μs | 0.0074 μs | 0.0065 μs | 0.80 | 0.02 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.562 μs | 0.0064 μs | 0.0057 μs | 0.82 | 0.02 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.260 μs | 0.0111 μs | 0.0093 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.186 μs | 0.0113 μs | 0.0106 μs | 0.97 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.556 μs | 0.0041 μs | 0.0037 μs | 0.69 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 2.251 μs | 0.0163 μs | 0.0144 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 2.176 μs | 0.0138 μs | 0.0129 μs | 0.97 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.518 μs | 0.0092 μs | 0.0081 μs | 0.67 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 2.205 μs | 0.0162 μs | 0.0152 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_List_Value | List_Value | 100 | 1.514 μs | 0.0065 μs | 0.0061 μs | 0.69 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 2.732 μs | 0.0129 μs | 0.0114 μs | 1.24 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.589 μs | 0.1489 μs | 0.1828 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.450 μs | 0.0323 μs | 0.0286 μs | 0.59 | 0.02 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.195 μs | 0.0094 μs | 0.0083 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.191 μs | 0.0144 μs | 0.0127 μs | 1.00 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.576 μs | 0.0078 μs | 0.0061 μs | 1.17 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 2.284 μs | 0.0135 μs | 0.0112 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 2.191 μs | 0.0158 μs | 0.0148 μs | 0.96 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.663 μs | 0.0179 μs | 0.0140 μs | 1.17 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 2.432 μs | 0.0137 μs | 0.0129 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_List_Reference | List_Reference | 100 | 2.153 μs | 0.0155 μs | 0.0130 μs | 0.89 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 2.765 μs | 0.0202 μs | 0.0179 μs | 1.14 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8.357 μs | 0.1664 μs | 0.2590 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4.899 μs | 0.0221 μs | 0.0196 μs | 0.59 | 0.02 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ElementAtBenchmarks.md b/Benchmarks/ElementAtBenchmarks.md index e97ffe3dd..217b82e3e 100644 --- a/Benchmarks/ElementAtBenchmarks.md +++ b/Benchmarks/ElementAtBenchmarks.md @@ -4,50 +4,50 @@ [ElementAtBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 18.585 ns | 0.0733 ns | 0.0650 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 12.935 ns | 0.0287 ns | 0.0268 ns | 0.70 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 343.258 ns | 1.3405 ns | 1.1194 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 144.574 ns | 0.3296 ns | 0.2752 ns | 0.42 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 344.587 ns | 1.0413 ns | 0.8130 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 149.877 ns | 0.4437 ns | 0.3933 ns | 0.44 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 9.966 ns | 0.0418 ns | 0.0391 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 14.887 ns | 0.0451 ns | 0.0422 ns | 1.49 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,794.411 ns | 6.5545 ns | 5.4733 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 969.878 ns | 4.0156 ns | 3.7562 ns | 0.54 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 344.638 ns | 1.2438 ns | 1.1026 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 341.807 ns | 1.5447 ns | 1.3694 ns | 0.99 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 344.314 ns | 0.9447 ns | 0.8375 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 370.607 ns | 1.3467 ns | 1.1245 ns | 1.08 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 10.000 ns | 0.0869 ns | 0.0770 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 14.735 ns | 0.0550 ns | 0.0487 ns | 1.47 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,793.513 ns | 5.0783 ns | 4.5017 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,604.776 ns | 3.7408 ns | 3.1238 ns | 0.89 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 16.195 ns | 0.1166 ns | 0.0974 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 12.970 ns | 0.0407 ns | 0.0361 ns | 0.80 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 345.293 ns | 1.8967 ns | 1.7741 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 131.154 ns | 0.4162 ns | 0.3689 ns | 0.38 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 317.201 ns | 2.3228 ns | 1.9397 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 136.510 ns | 0.4444 ns | 0.3711 ns | 0.43 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 9.763 ns | 0.0775 ns | 0.0687 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 344.678 ns | 4.0756 ns | 3.1819 ns | 35.30 | 0.40 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,623.137 ns | 6.5760 ns | 5.4913 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 801.118 ns | 1.8841 ns | 1.5733 ns | 0.49 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 343.991 ns | 5.0239 ns | 4.4535 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 340.969 ns | 1.2339 ns | 0.9633 ns | 0.99 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 343.868 ns | 1.5650 ns | 3.5325 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 353.880 ns | 2.0154 ns | 1.7866 ns | 1.04 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 9.557 ns | 0.0418 ns | 0.0371 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 318.015 ns | 1.8263 ns | 1.5250 ns | 33.27 | 0.19 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,615.527 ns | 3.2110 ns | 2.8465 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,408.213 ns | 5.3995 ns | 5.0507 ns | 0.87 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/EmptyBenchmarks.md b/Benchmarks/EmptyBenchmarks.md index 5e63a9d01..91ff28fd2 100644 --- a/Benchmarks/EmptyBenchmarks.md +++ b/Benchmarks/EmptyBenchmarks.md @@ -4,29 +4,29 @@ [EmptyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/EmptyBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------------- |------------ |-----------:|----------:|----------:|------:|------:|------:|------:|----------:| -| Linq_Empty | Empty | 6.3669 ns | 0.0298 ns | 0.0278 ns | 1.000 | - | - | - | - | -| Hyperlinq_Empty | Empty | 0.0000 ns | 0.0000 ns | 0.0000 ns | 0.000 | - | - | - | - | +| Linq_Empty | Empty | 6.5124 ns | 0.0392 ns | 0.0366 ns | 1.000 | - | - | - | - | +| Hyperlinq_Empty | Empty | 0.0120 ns | 0.0080 ns | 0.0075 ns | 0.002 | - | - | - | - | | | | | | | | | | | | -| Linq_Empty_Async | Empty_Async | 40.5218 ns | 0.0720 ns | 0.0638 ns | 1.00 | - | - | - | - | -| Hyperlinq_Empty_Async | Empty_Async | 20.7372 ns | 0.0697 ns | 0.0618 ns | 0.51 | - | - | - | - | +| Linq_Empty_Async | Empty_Async | 42.3276 ns | 0.1002 ns | 0.0837 ns | 1.00 | - | - | - | - | +| Hyperlinq_Empty_Async | Empty_Async | 20.8454 ns | 0.0723 ns | 0.0604 ns | 0.49 | - | - | - | - | diff --git a/Benchmarks/FirstBenchmarks.md b/Benchmarks/FirstBenchmarks.md index 873b3b16a..fbae71c9c 100644 --- a/Benchmarks/FirstBenchmarks.md +++ b/Benchmarks/FirstBenchmarks.md @@ -4,50 +4,50 @@ [FirstBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 21.69 ns | 0.108 ns | 0.096 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 13.33 ns | 0.029 ns | 0.024 ns | 0.61 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 25.27 ns | 0.083 ns | 0.073 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.62 ns | 0.036 ns | 0.032 ns | 0.62 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 26.29 ns | 0.138 ns | 0.116 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 19.12 ns | 0.054 ns | 0.051 ns | 0.73 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 13.38 ns | 0.072 ns | 0.067 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 14.99 ns | 0.089 ns | 0.083 ns | 1.12 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 104.97 ns | 0.191 ns | 0.169 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 63.66 ns | 0.292 ns | 0.273 ns | 0.61 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 25.65 ns | 0.151 ns | 0.141 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 17.22 ns | 0.066 ns | 0.062 ns | 0.67 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 25.67 ns | 0.173 ns | 0.153 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 18.86 ns | 0.073 ns | 0.061 ns | 0.73 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 13.32 ns | 0.071 ns | 0.059 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 14.66 ns | 0.058 ns | 0.048 ns | 1.10 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 107.94 ns | 0.590 ns | 0.552 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 71.80 ns | 0.260 ns | 0.230 ns | 0.66 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 19.24 ns | 0.078 ns | 0.073 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 13.26 ns | 0.034 ns | 0.032 ns | 0.69 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 25.00 ns | 0.127 ns | 0.112 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.57 ns | 0.040 ns | 0.033 ns | 0.62 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 28.18 ns | 0.592 ns | 1.127 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 18.92 ns | 0.061 ns | 0.054 ns | 0.68 | 0.02 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 12.44 ns | 0.050 ns | 0.039 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 22.00 ns | 0.120 ns | 0.172 ns | 1.77 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 103.75 ns | 0.487 ns | 0.432 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 61.99 ns | 0.117 ns | 0.098 ns | 0.60 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 26.59 ns | 0.528 ns | 0.468 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 17.38 ns | 0.114 ns | 0.101 ns | 0.65 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 25.97 ns | 0.191 ns | 0.178 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 20.63 ns | 0.114 ns | 0.095 ns | 0.79 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 12.52 ns | 0.091 ns | 0.081 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 20.87 ns | 0.104 ns | 0.093 ns | 1.67 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 103.68 ns | 2.016 ns | 2.071 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 70.01 ns | 1.326 ns | 1.240 ns | 0.67 | 0.02 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ListIterationBenchmarks.md b/Benchmarks/ListIterationBenchmarks.md index bfcaf687b..246988644 100644 --- a/Benchmarks/ListIterationBenchmarks.md +++ b/Benchmarks/ListIterationBenchmarks.md @@ -4,7 +4,7 @@ [ListIterationBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21222.10 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,20 +14,20 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21227.6 - [Host] : .NET 6.0.0 (6.0.21.22210), X64 RyuJIT - Job-QJGPYZ : .NET 6.0.0 (6.0.21.22210), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------- |-------------- |-------- |------------:|------------:|------------:|------:|--------:|------:|------:|------:|----------:| -| List_numerable | List | 1000000 | 1,987.8 μs | 113.79 μs | 335.50 μs | 1.00 | 0.00 | - | - | - | 1 B | -| List_Indexer | List | 1000000 | 1,332.8 μs | 34.49 μs | 101.71 μs | 0.69 | 0.13 | - | - | - | - | -| List_Span | List | 1000000 | 625.0 μs | 24.47 μs | 72.15 μs | 0.32 | 0.07 | - | - | - | - | -| | | | | | | | | | | | | -| ImmutableList_Enumerable | ImmutableList | 1000000 | 45,007.3 μs | 1,574.97 μs | 4,643.83 μs | 1.00 | 0.00 | - | - | - | 12 B | -| ImmutableList_Indexer | ImmutableList | 1000000 | 65,105.0 μs | 1,295.17 μs | 3,343.25 μs | 1.46 | 0.17 | - | - | - | 18 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------- |-------------- |-------- |------------:|----------:|----------:|------:|--------:|------:|------:|------:|----------:| +| List_Enumerable | List | 1000000 | 1,344.6 μs | 7.83 μs | 6.54 μs | 1.00 | 0.00 | - | - | - | 1 B | +| List_Indexer | List | 1000000 | 1,176.2 μs | 5.95 μs | 5.56 μs | 0.87 | 0.01 | - | - | - | 1 B | +| List_Span | List | 1000000 | 459.5 μs | 6.01 μs | 5.32 μs | 0.34 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| ImmutableList_Enumerable | ImmutableList | 1000000 | 35,174.0 μs | 356.44 μs | 315.97 μs | 1.00 | 0.00 | - | - | - | 10 B | +| ImmutableList_Indexer | ImmutableList | 1000000 | 62,851.2 μs | 274.72 μs | 256.97 μs | 1.79 | 0.02 | - | - | - | 16 B | diff --git a/Benchmarks/RangeBenchmarks.md b/Benchmarks/RangeBenchmarks.md index 76b97cec2..c2566d35a 100644 --- a/Benchmarks/RangeBenchmarks.md +++ b/Benchmarks/RangeBenchmarks.md @@ -4,30 +4,30 @@ [RangeBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------ |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 416.88 ns | 2.728 ns | 2.130 ns | 1.00 | 0.0191 | - | - | 40 B | -| StructLinq | Range | 100 | 34.04 ns | 0.144 ns | 0.128 ns | 0.08 | - | - | - | - | -| Hyperlinq | Range | 100 | 47.38 ns | 0.148 ns | 0.131 ns | 0.11 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 3,912.38 ns | 22.969 ns | 21.485 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Range_Async | 100 | 1,320.37 ns | 4.421 ns | 4.136 ns | 0.34 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------ |------ |------------:|----------:|---------:|------:|-------:|------:|------:|----------:| +| Linq | Range | 100 | 397.16 ns | 4.535 ns | 4.242 ns | 1.00 | 0.0191 | - | - | 40 B | +| StructLinq | Range | 100 | 33.81 ns | 0.143 ns | 0.126 ns | 0.09 | - | - | - | - | +| Hyperlinq | Range | 100 | 42.34 ns | 0.192 ns | 0.170 ns | 0.11 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Async | Range_Async | 100 | 3,689.77 ns | 10.303 ns | 9.133 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Range_Async | 100 | 1,230.03 ns | 4.703 ns | 3.927 ns | 0.33 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/RangeToArrayBenchmarks.md b/Benchmarks/RangeToArrayBenchmarks.md index e0515d399..5d97b3fda 100644 --- a/Benchmarks/RangeToArrayBenchmarks.md +++ b/Benchmarks/RangeToArrayBenchmarks.md @@ -4,31 +4,31 @@ [RangeToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------ |------ |----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 82.74 ns | 0.862 ns | 0.807 ns | 1.00 | 0.2218 | - | - | 464 B | -| StructLinq | Range | 100 | 89.71 ns | 0.455 ns | 0.403 ns | 1.09 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Range | 100 | 36.82 ns | 0.408 ns | 0.382 ns | 0.45 | 0.2027 | - | - | 424 B | -| Hyperlinq | Range | 100 | 45.49 ns | 0.218 ns | 0.170 ns | 0.55 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 108.02 ns | 0.607 ns | 0.538 ns | 1.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Range_Async | 100 | 146.15 ns | 0.743 ns | 0.620 ns | 1.35 | 0.2027 | - | - | 424 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------ |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq | Range | 100 | 83.82 ns | 1.079 ns | 0.957 ns | 1.00 | 0.00 | 0.2218 | - | - | 464 B | +| StructLinq | Range | 100 | 87.92 ns | 1.112 ns | 1.040 ns | 1.05 | 0.02 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Range | 100 | 44.87 ns | 0.414 ns | 0.388 ns | 0.54 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq | Range | 100 | 45.34 ns | 0.845 ns | 0.791 ns | 0.54 | 0.01 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | +| Linq_Async | Range_Async | 100 | 107.52 ns | 1.990 ns | 3.738 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Range_Async | 100 | 159.51 ns | 3.245 ns | 3.737 ns | 1.46 | 0.08 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/ReadOnlyFieldsBenchmarks.md b/Benchmarks/ReadOnlyFieldsBenchmarks.md index 41e55ff73..b830919ec 100644 --- a/Benchmarks/ReadOnlyFieldsBenchmarks.md +++ b/Benchmarks/ReadOnlyFieldsBenchmarks.md @@ -14,17 +14,17 @@ ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-NLALVJ : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------ |---------:|--------:|--------:|------:|------:|------:|------:|----------:| -| Baseline | 1000 | 607.9 ns | 5.01 ns | 4.68 ns | 1.00 | - | - | - | - | -| ReadOnlyCurrent | 1000 | 610.8 ns | 6.02 ns | 5.64 ns | 1.00 | - | - | - | - | -| ReadOnlyField | 1000 | 611.9 ns | 4.35 ns | 4.07 ns | 1.01 | - | - | - | - | +| Baseline | 1000 | 544.6 ns | 1.08 ns | 1.01 ns | 1.00 | - | - | - | - | +| ReadOnlyCurrent | 1000 | 544.2 ns | 1.28 ns | 1.20 ns | 1.00 | - | - | - | - | +| ReadOnlyField | 1000 | 546.4 ns | 1.84 ns | 1.72 ns | 1.00 | - | - | - | - | diff --git a/Benchmarks/RepeatBenchmarks.md b/Benchmarks/RepeatBenchmarks.md index 546acfade..6365b98b1 100644 --- a/Benchmarks/RepeatBenchmarks.md +++ b/Benchmarks/RepeatBenchmarks.md @@ -4,30 +4,30 @@ [RepeatBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 415.37 ns | 0.629 ns | 0.589 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq | Repeat | 100 | 34.32 ns | 0.159 ns | 0.148 ns | 0.08 | - | - | - | - | -| Hyperlinq | Repeat | 100 | 167.30 ns | 0.277 ns | 0.259 ns | 0.40 | - | - | - | - | +| Linq | Repeat | 100 | 388.03 ns | 2.670 ns | 2.367 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq | Repeat | 100 | 44.37 ns | 0.187 ns | 0.146 ns | 0.11 | - | - | - | - | +| Hyperlinq | Repeat | 100 | 147.12 ns | 0.422 ns | 0.395 ns | 0.38 | - | - | - | - | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 4,969.95 ns | 19.484 ns | 16.270 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Repeat_Async | 100 | 933.46 ns | 1.937 ns | 1.717 ns | 0.19 | - | - | - | - | +| Linq_Async | Repeat_Async | 100 | 4,715.35 ns | 18.267 ns | 15.253 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Repeat_Async | 100 | 795.54 ns | 1.931 ns | 1.711 ns | 0.17 | - | - | - | - | diff --git a/Benchmarks/RepeatToArrayBenchmarks.md b/Benchmarks/RepeatToArrayBenchmarks.md index b964ecac5..66d3a2c74 100644 --- a/Benchmarks/RepeatToArrayBenchmarks.md +++ b/Benchmarks/RepeatToArrayBenchmarks.md @@ -4,32 +4,32 @@ [RepeatToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------- |------ |----------:|---------:|---------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 92.29 ns | 0.656 ns | 0.582 ns | 92.23 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq | Repeat | 100 | 110.61 ns | 0.756 ns | 0.631 ns | 110.42 ns | 1.20 | 0.01 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Repeat | 100 | 28.17 ns | 0.569 ns | 0.504 ns | 28.10 ns | 0.31 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq | Repeat | 100 | 55.52 ns | 0.252 ns | 0.223 ns | 55.53 ns | 0.60 | 0.00 | 0.2027 | - | - | 424 B | -| Hyperlinq_SIMD | Repeat | 100 | 41.57 ns | 0.774 ns | 1.928 ns | 40.74 ns | 0.48 | 0.03 | 0.2027 | - | - | 424 B | +| Linq | Repeat | 100 | 80.60 ns | 0.607 ns | 0.538 ns | 80.59 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq | Repeat | 100 | 89.59 ns | 0.325 ns | 0.288 ns | 89.70 ns | 1.11 | 0.01 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Repeat | 100 | 30.88 ns | 0.668 ns | 0.686 ns | 30.89 ns | 0.38 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq | Repeat | 100 | 56.78 ns | 0.811 ns | 0.719 ns | 56.77 ns | 0.70 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_SIMD | Repeat | 100 | 39.50 ns | 0.827 ns | 0.849 ns | 39.70 ns | 0.49 | 0.01 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 91.33 ns | 0.327 ns | 0.256 ns | 91.29 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Repeat_Async | 100 | 119.23 ns | 0.548 ns | 0.428 ns | 119.24 ns | 1.31 | 0.00 | 0.2027 | - | - | 424 B | +| Linq_Async | Repeat_Async | 100 | 96.49 ns | 1.982 ns | 4.554 ns | 94.05 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Repeat_Async | 100 | 180.18 ns | 3.646 ns | 4.868 ns | 182.13 ns | 1.84 | 0.08 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/ReturnBenchmarks.md b/Benchmarks/ReturnBenchmarks.md index 7521fe228..a9b9b2ee5 100644 --- a/Benchmarks/ReturnBenchmarks.md +++ b/Benchmarks/ReturnBenchmarks.md @@ -4,29 +4,29 @@ [ReturnBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReturnBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|----------------------- |------------- |----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Return | Return | 15.684 ns | 0.1203 ns | 0.1067 ns | 1.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_Return | Return | 8.965 ns | 0.0158 ns | 0.0140 ns | 0.57 | - | - | - | - | -| | | | | | | | | | | -| Linq_Return_Async | Return_Async | 56.114 ns | 0.1545 ns | 0.1370 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Return_Async | Return_Async | 42.330 ns | 0.0832 ns | 0.0738 ns | 0.75 | - | - | - | - | +| Method | Categories | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|----------------------- |------------- |----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Return | Return | 15.500 ns | 0.0639 ns | 0.0534 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_Return | Return | 8.722 ns | 0.0172 ns | 0.0153 ns | 0.56 | 0.00 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Return_Async | Return_Async | 59.634 ns | 1.1815 ns | 1.2642 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Return_Async | Return_Async | 39.919 ns | 0.0888 ns | 0.0787 ns | 0.67 | 0.02 | - | - | - | - | diff --git a/Benchmarks/SelectBenchmarks.md b/Benchmarks/SelectBenchmarks.md index f4d375c51..741aabb42 100644 --- a/Benchmarks/SelectBenchmarks.md +++ b/Benchmarks/SelectBenchmarks.md @@ -4,64 +4,62 @@ [SelectBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 634.6 ns | 2.38 ns | 2.11 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 232.2 ns | 0.37 ns | 0.29 ns | 0.37 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 226.5 ns | 3.05 ns | 2.54 ns | 0.36 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 209.0 ns | 0.85 ns | 0.76 ns | 0.33 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 199.0 ns | 0.86 ns | 0.76 ns | 0.31 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 209.5 ns | 0.96 ns | 0.90 ns | 0.33 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 352.7 ns | 1.13 ns | 1.00 ns | 0.56 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 237.4 ns | 1.09 ns | 0.97 ns | 0.37 | - | - | - | - | +| Linq_Array | Array | 100 | 642.6 ns | 2.60 ns | 2.17 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 206.1 ns | 0.58 ns | 0.52 ns | 0.32 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 273.0 ns | 1.36 ns | 1.13 ns | 0.42 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 209.9 ns | 0.67 ns | 0.56 ns | 0.33 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 172.1 ns | 0.72 ns | 0.64 ns | 0.27 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 208.8 ns | 0.72 ns | 0.60 ns | 0.32 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 298.9 ns | 1.53 ns | 1.36 ns | 0.47 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 232.7 ns | 0.57 ns | 0.48 ns | 0.36 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,216.2 ns | 5.09 ns | 4.25 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 739.1 ns | 4.27 ns | 3.57 ns | 0.61 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 211.1 ns | 1.23 ns | 1.09 ns | 0.17 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,138.7 ns | 5.13 ns | 4.80 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 754.1 ns | 6.10 ns | 5.41 ns | 0.66 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 229.8 ns | 0.52 ns | 0.46 ns | 0.20 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,165.7 ns | 6.67 ns | 5.91 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 735.9 ns | 3.02 ns | 2.68 ns | 0.63 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 211.3 ns | 0.64 ns | 0.57 ns | 0.18 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,230.2 ns | 11.48 ns | 10.17 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 758.3 ns | 5.50 ns | 5.15 ns | 0.62 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 207.7 ns | 0.54 ns | 0.50 ns | 0.17 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,174.4 ns | 4.15 ns | 3.68 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 374.7 ns | 2.22 ns | 1.97 ns | 0.32 | - | - | - | - | -| Hyperlinq_List_Value_For | List_Value | 100 | 379.3 ns | 1.18 ns | 1.04 ns | 0.32 | - | - | - | - | -| Hyperlinq_List_Value_Foreach | List_Value | 100 | 393.0 ns | 1.47 ns | 1.38 ns | 0.33 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 1,227.2 ns | 5.49 ns | 4.58 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 438.1 ns | 0.93 ns | 0.82 ns | 0.36 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 742.3 ns | 4.22 ns | 3.74 ns | 0.60 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,148.1 ns | 18.84 ns | 16.70 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,148.5 ns | 16.21 ns | 15.16 ns | 0.72 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,756.0 ns | 28.27 ns | 26.45 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,746.1 ns | 31.36 ns | 29.34 ns | 0.70 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,164.0 ns | 4.45 ns | 3.95 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 790.4 ns | 4.13 ns | 3.66 ns | 0.68 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 780.9 ns | 3.94 ns | 3.49 ns | 0.67 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,170.2 ns | 4.51 ns | 4.00 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 703.7 ns | 4.61 ns | 4.08 ns | 0.60 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 785.8 ns | 7.09 ns | 6.28 ns | 0.67 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,197.2 ns | 4.66 ns | 4.36 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 736.3 ns | 2.27 ns | 2.01 ns | 0.61 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 814.1 ns | 2.98 ns | 2.79 ns | 0.68 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,173.1 ns | 5.95 ns | 5.27 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 758.6 ns | 4.39 ns | 3.89 ns | 0.65 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 755.6 ns | 3.61 ns | 3.38 ns | 0.64 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,205.2 ns | 3.78 ns | 3.35 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 735.4 ns | 2.67 ns | 2.37 ns | 0.61 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference_For | List_Reference | 100 | 403.9 ns | 1.10 ns | 0.97 ns | 0.34 | - | - | - | - | -| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 399.8 ns | 1.51 ns | 1.18 ns | 0.33 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 1,130.5 ns | 7.47 ns | 6.24 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 753.1 ns | 4.04 ns | 3.58 ns | 0.67 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 753.5 ns | 4.30 ns | 3.81 ns | 0.67 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,226.5 ns | 19.84 ns | 17.58 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,544.6 ns | 21.90 ns | 19.41 ns | 0.77 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,635.0 ns | 40.24 ns | 35.67 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,152.2 ns | 20.92 ns | 18.54 ns | 0.78 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectCountBenchmarks.md b/Benchmarks/SelectCountBenchmarks.md index 310108b9b..498f006ee 100644 --- a/Benchmarks/SelectCountBenchmarks.md +++ b/Benchmarks/SelectCountBenchmarks.md @@ -4,57 +4,57 @@ [SelectCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-------------:|-----------:|-----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 195.967 ns | 0.6597 ns | 0.5848 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 10.188 ns | 0.0342 ns | 0.0320 ns | 0.05 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 15.532 ns | 0.0697 ns | 0.0582 ns | 0.08 | - | - | - | - | +| Linq_Array | Array | 100 | 219.711 ns | 4.1739 ns | 3.9042 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 10.184 ns | 0.0370 ns | 0.0328 ns | 0.05 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 15.418 ns | 0.0369 ns | 0.0345 ns | 0.07 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 771.437 ns | 4.7738 ns | 4.2319 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 763.172 ns | 2.2538 ns | 2.1082 ns | 0.99 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 162.321 ns | 0.1898 ns | 0.1682 ns | 0.21 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 812.967 ns | 5.9923 ns | 5.3121 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 784.076 ns | 4.0677 ns | 3.6059 ns | 0.96 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 144.744 ns | 0.2739 ns | 0.2562 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 775.472 ns | 2.9631 ns | 2.7717 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 802.103 ns | 6.4102 ns | 5.3528 ns | 1.03 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 16.077 ns | 0.0369 ns | 0.0327 ns | 0.02 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 801.510 ns | 5.9916 ns | 5.3114 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 769.218 ns | 4.4604 ns | 3.9541 ns | 0.96 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 16.540 ns | 0.0370 ns | 0.0328 ns | 0.02 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 482.164 ns | 0.8969 ns | 0.7951 ns | 1.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Value | List_Value | 100 | 10.268 ns | 0.0340 ns | 0.0302 ns | 0.02 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 9.873 ns | 0.0109 ns | 0.0085 ns | 0.02 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 402.821 ns | 0.5863 ns | 0.4895 ns | 1.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Value | List_Value | 100 | 10.144 ns | 0.0241 ns | 0.0225 ns | 0.03 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 4.959 ns | 0.0321 ns | 0.0268 ns | 0.01 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,523.203 ns | 22.8359 ns | 20.2434 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 947.472 ns | 1.2425 ns | 1.1015 ns | 0.13 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,802.309 ns | 15.9078 ns | 14.8802 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 786.096 ns | 1.0756 ns | 1.0061 ns | 0.10 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 820.965 ns | 4.0317 ns | 3.7713 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 764.338 ns | 3.4927 ns | 2.9166 ns | 0.93 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 368.547 ns | 1.3929 ns | 1.1631 ns | 0.45 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 779.795 ns | 5.2856 ns | 4.9441 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 755.027 ns | 3.7415 ns | 3.1243 ns | 0.97 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 373.832 ns | 3.4209 ns | 2.6708 ns | 0.48 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 809.920 ns | 2.3646 ns | 1.9745 ns | 1.000 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 767.365 ns | 2.4976 ns | 2.0856 ns | 0.947 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.228 ns | 0.0221 ns | 0.0184 ns | 0.005 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 764.223 ns | 3.1207 ns | 2.7664 ns | 1.000 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 785.206 ns | 4.3773 ns | 3.8804 ns | 1.027 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.343 ns | 0.0194 ns | 0.0172 ns | 0.006 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 420.192 ns | 2.0857 ns | 1.9509 ns | 1.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Reference | List_Reference | 100 | 767.197 ns | 5.1913 ns | 4.6020 ns | 1.83 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 9.831 ns | 0.2176 ns | 0.2234 ns | 0.02 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 414.345 ns | 3.3147 ns | 2.9384 ns | 1.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Reference | List_Reference | 100 | 754.097 ns | 2.5777 ns | 2.1525 ns | 1.82 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 4.476 ns | 0.0161 ns | 0.0143 ns | 0.01 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,586.118 ns | 32.0225 ns | 28.3871 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,630.690 ns | 31.2243 ns | 30.6665 ns | 0.22 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,958.364 ns | 21.2835 ns | 17.7727 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,428.854 ns | 6.0499 ns | 5.3631 ns | 0.21 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectManyBenchmarks.md b/Benchmarks/SelectManyBenchmarks.md index 7127f1f5d..d5b410e65 100644 --- a/Benchmarks/SelectManyBenchmarks.md +++ b/Benchmarks/SelectManyBenchmarks.md @@ -4,49 +4,49 @@ [SelectManyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectManyBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------- |-------------------------- |------ |----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 2.825 μs | 0.0094 μs | 0.0084 μs | 1.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Array | Array | 100 | 1.227 μs | 0.0019 μs | 0.0016 μs | 0.43 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.415 μs | 0.0230 μs | 0.0215 μs | 0.50 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.925 μs | 0.0093 μs | 0.0077 μs | 1.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.394 μs | 0.0151 μs | 0.0141 μs | 1.16 | 2.3575 | - | - | 4,936 B | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 2.993 μs | 0.0306 μs | 0.0255 μs | 1.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.451 μs | 0.0081 μs | 0.0067 μs | 1.15 | 2.3575 | - | - | 4,936 B | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 2.919 μs | 0.0096 μs | 0.0080 μs | 1.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_List_Value | List_Value | 100 | 3.660 μs | 0.0242 μs | 0.0214 μs | 1.25 | 2.3537 | - | - | 4,928 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 12.341 μs | 0.0542 μs | 0.0480 μs | 1.00 | 2.3346 | - | - | 4,904 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.992 μs | 0.0233 μs | 0.0218 μs | 1.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 3.384 μs | 0.0112 μs | 0.0099 μs | 1.13 | 2.3499 | - | - | 4,920 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 2.966 μs | 0.0183 μs | 0.0171 μs | 1.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 3.468 μs | 0.0193 μs | 0.0171 μs | 1.17 | 2.3499 | - | - | 4,920 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 2.976 μs | 0.0175 μs | 0.0155 μs | 1.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 3.618 μs | 0.0194 μs | 0.0162 μs | 1.22 | 2.3537 | - | - | 4,928 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 12.289 μs | 0.0295 μs | 0.0247 μs | 1.00 | 2.3346 | - | - | 4,904 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------- |-------------------------- |------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 2.815 μs | 0.0153 μs | 0.0128 μs | 2.812 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Array | Array | 100 | 1.221 μs | 0.0032 μs | 0.0028 μs | 1.221 μs | 0.43 | 0.00 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.382 μs | 0.0040 μs | 0.0037 μs | 1.382 μs | 0.49 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.976 μs | 0.0218 μs | 0.0182 μs | 2.970 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.251 μs | 0.0315 μs | 0.0263 μs | 3.239 μs | 1.09 | 0.01 | 2.3575 | - | - | 4,936 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 3.073 μs | 0.0543 μs | 0.0965 μs | 3.030 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.328 μs | 0.0194 μs | 0.0182 μs | 3.324 μs | 1.06 | 0.04 | 2.3575 | - | - | 4,936 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 3.178 μs | 0.0422 μs | 0.0374 μs | 3.186 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_List_Value | List_Value | 100 | 3.391 μs | 0.0676 μs | 0.1318 μs | 3.306 μs | 1.13 | 0.01 | 2.3499 | - | - | 4,920 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 11.623 μs | 0.0643 μs | 0.0601 μs | 11.616 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.999 μs | 0.0136 μs | 0.0128 μs | 3.001 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 3.308 μs | 0.0185 μs | 0.0164 μs | 3.308 μs | 1.10 | 0.01 | 2.3499 | - | - | 4,920 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 3.249 μs | 0.0358 μs | 0.0317 μs | 3.249 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 3.677 μs | 0.0255 μs | 0.0238 μs | 3.670 μs | 1.13 | 0.01 | 2.3499 | - | - | 4,920 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 2.939 μs | 0.0252 μs | 0.0224 μs | 2.930 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 3.302 μs | 0.0110 μs | 0.0092 μs | 3.301 μs | 1.12 | 0.01 | 2.3499 | - | - | 4,920 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 11.592 μs | 0.0238 μs | 0.0199 μs | 11.595 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | diff --git a/Benchmarks/SelectSumBenchmarks.md b/Benchmarks/SelectSumBenchmarks.md index eb550e103..9348240e3 100644 --- a/Benchmarks/SelectSumBenchmarks.md +++ b/Benchmarks/SelectSumBenchmarks.md @@ -4,58 +4,58 @@ [SelectSumBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 624.04 ns | 3.238 ns | 3.029 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 206.45 ns | 0.546 ns | 0.456 ns | 0.33 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 200.01 ns | 0.456 ns | 0.404 ns | 0.32 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 66.82 ns | 0.265 ns | 0.234 ns | 0.11 | - | - | - | - | +| Linq_Array | Array | 100 | 646.61 ns | 3.030 ns | 2.686 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 224.11 ns | 0.872 ns | 0.728 ns | 0.35 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 198.38 ns | 0.554 ns | 0.491 ns | 0.31 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 66.40 ns | 0.203 ns | 0.190 ns | 0.10 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,160.78 ns | 6.146 ns | 5.448 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 776.38 ns | 4.821 ns | 4.509 ns | 0.67 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 204.93 ns | 0.518 ns | 0.433 ns | 0.18 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,164.53 ns | 12.105 ns | 11.323 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 761.98 ns | 3.117 ns | 2.763 ns | 0.65 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 226.80 ns | 0.409 ns | 0.362 ns | 0.19 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,164.42 ns | 2.973 ns | 2.781 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 795.29 ns | 2.956 ns | 2.468 ns | 0.68 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 213.97 ns | 0.790 ns | 0.700 ns | 0.18 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,151.16 ns | 4.268 ns | 3.784 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 757.00 ns | 3.107 ns | 2.755 ns | 0.66 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 209.40 ns | 0.830 ns | 0.648 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,174.97 ns | 7.585 ns | 7.095 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 347.10 ns | 1.846 ns | 1.636 ns | 0.30 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 619.75 ns | 2.497 ns | 2.085 ns | 0.53 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 1,160.97 ns | 3.731 ns | 3.490 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 366.61 ns | 1.448 ns | 1.284 ns | 0.32 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 772.26 ns | 3.474 ns | 3.250 ns | 0.67 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,626.26 ns | 25.790 ns | 22.863 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,295.19 ns | 6.061 ns | 5.373 ns | 0.30 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,088.46 ns | 25.657 ns | 22.744 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,998.94 ns | 4.643 ns | 4.343 ns | 0.28 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,166.44 ns | 2.742 ns | 2.430 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 780.54 ns | 4.485 ns | 4.196 ns | 0.67 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 769.02 ns | 3.871 ns | 3.431 ns | 0.66 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,154.50 ns | 3.956 ns | 3.507 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 787.50 ns | 4.158 ns | 3.686 ns | 0.68 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 756.37 ns | 4.099 ns | 3.634 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,160.10 ns | 6.752 ns | 5.985 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 791.96 ns | 2.826 ns | 2.360 ns | 0.68 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 744.96 ns | 3.601 ns | 3.192 ns | 0.64 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,205.65 ns | 11.671 ns | 9.746 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 781.71 ns | 3.806 ns | 3.374 ns | 0.65 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 783.24 ns | 3.150 ns | 2.947 ns | 0.65 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,170.01 ns | 6.032 ns | 5.347 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 772.95 ns | 4.429 ns | 3.926 ns | 0.66 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 692.92 ns | 3.153 ns | 2.950 ns | 0.59 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 1,211.02 ns | 10.733 ns | 9.515 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 756.32 ns | 3.160 ns | 2.801 ns | 0.62 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 818.50 ns | 2.569 ns | 2.145 ns | 0.68 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,577.98 ns | 27.143 ns | 24.062 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,061.96 ns | 6.833 ns | 6.057 ns | 0.40 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,124.15 ns | 20.434 ns | 18.114 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,821.11 ns | 6.822 ns | 5.697 ns | 0.40 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectToArrayBenchmarks.md b/Benchmarks/SelectToArrayBenchmarks.md index 8fea5ca6b..531c4099e 100644 --- a/Benchmarks/SelectToArrayBenchmarks.md +++ b/Benchmarks/SelectToArrayBenchmarks.md @@ -4,59 +4,59 @@ [SelectToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|-----------:|-----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 219.64 ns | 3.342 ns | 2.609 ns | 218.45 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | -| StructLinq_Array | Array | 100 | 239.53 ns | 4.705 ns | 6.118 ns | 237.06 ns | 1.10 | 0.04 | 0.2027 | - | - | 424 B | -| LinqFasterSIMD_Array | Array | 100 | 61.80 ns | 0.444 ns | 0.371 ns | 61.78 ns | 0.28 | 0.00 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 228.42 ns | 1.300 ns | 1.216 ns | 228.24 ns | 1.04 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array_SIMD | Array | 100 | 83.17 ns | 0.507 ns | 0.423 ns | 82.98 ns | 0.38 | 0.00 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,083.36 ns | 17.145 ns | 14.317 ns | 1,078.07 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,094.55 ns | 6.370 ns | 5.319 ns | 1,094.50 ns | 1.01 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 590.88 ns | 2.817 ns | 2.497 ns | 591.27 ns | 0.55 | 0.01 | 0.2022 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,108.09 ns | 21.893 ns | 33.433 ns | 1,100.53 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,063.27 ns | 5.059 ns | 4.485 ns | 1,063.31 ns | 0.96 | 0.03 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 337.41 ns | 2.007 ns | 1.780 ns | 336.84 ns | 0.30 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 464.84 ns | 9.535 ns | 26.421 ns | 451.63 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Value | List_Value | 100 | 429.96 ns | 1.118 ns | 0.933 ns | 430.25 ns | 0.88 | 0.06 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 731.32 ns | 14.433 ns | 24.114 ns | 719.49 ns | 1.53 | 0.12 | 0.2022 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,013.72 ns | 43.980 ns | 36.725 ns | 8,010.56 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,691.14 ns | 8.372 ns | 7.831 ns | 2,690.70 ns | 0.34 | 0.00 | 0.5646 | - | - | 1,184 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,070.31 ns | 3.945 ns | 3.497 ns | 1,069.38 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,038.29 ns | 4.257 ns | 3.555 ns | 1,038.69 ns | 0.97 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,116.07 ns | 4.839 ns | 4.290 ns | 1,115.42 ns | 1.04 | 0.00 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,098.39 ns | 3.601 ns | 3.192 ns | 1,098.48 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,046.69 ns | 3.930 ns | 3.483 ns | 1,046.08 ns | 0.95 | 0.00 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 812.84 ns | 2.602 ns | 2.434 ns | 812.98 ns | 0.74 | 0.00 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 412.14 ns | 2.762 ns | 2.448 ns | 411.58 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,046.03 ns | 3.970 ns | 3.099 ns | 1,045.62 ns | 2.54 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 733.19 ns | 2.886 ns | 2.700 ns | 733.51 ns | 1.78 | 0.01 | 0.2022 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,264.86 ns | 163.535 ns | 307.158 ns | 8,161.45 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,500.80 ns | 28.083 ns | 23.450 ns | 3,491.77 ns | 0.42 | 0.02 | 0.5798 | - | - | 1,216 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 238.12 ns | 1.606 ns | 1.424 ns | 237.93 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | +| StructLinq_Array | Array | 100 | 228.97 ns | 1.286 ns | 1.203 ns | 228.58 ns | 0.96 | 0.01 | 0.2027 | - | - | 424 B | +| LinqFasterSIMD_Array | Array | 100 | 66.11 ns | 0.824 ns | 0.770 ns | 66.35 ns | 0.28 | 0.00 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 251.01 ns | 1.267 ns | 1.185 ns | 250.89 ns | 1.05 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array_SIMD | Array | 100 | 82.69 ns | 0.862 ns | 0.720 ns | 82.89 ns | 0.35 | 0.00 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,044.51 ns | 4.877 ns | 4.561 ns | 1,044.31 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,097.91 ns | 10.184 ns | 9.028 ns | 1,095.62 ns | 1.05 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 640.70 ns | 4.753 ns | 4.446 ns | 640.70 ns | 0.61 | 0.00 | 0.2022 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,046.33 ns | 4.834 ns | 4.521 ns | 1,046.07 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,112.99 ns | 13.512 ns | 12.639 ns | 1,111.75 ns | 1.06 | 0.02 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 337.75 ns | 2.273 ns | 2.015 ns | 337.25 ns | 0.32 | 0.00 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 489.36 ns | 7.094 ns | 16.156 ns | 482.28 ns | 1.00 | 0.00 | 0.2289 | - | - | 480 B | +| StructLinq_List_Value | List_Value | 100 | 479.61 ns | 9.434 ns | 15.762 ns | 471.26 ns | 0.97 | 0.04 | 0.2022 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 860.85 ns | 3.419 ns | 3.031 ns | 860.22 ns | 1.70 | 0.07 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,878.85 ns | 21.260 ns | 18.847 ns | 7,870.09 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,348.99 ns | 13.204 ns | 12.351 ns | 2,345.72 ns | 0.30 | 0.00 | 0.5646 | - | - | 1,184 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,092.08 ns | 7.737 ns | 6.859 ns | 1,092.57 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,069.71 ns | 4.509 ns | 3.997 ns | 1,069.70 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,113.28 ns | 6.848 ns | 6.406 ns | 1,110.74 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,089.46 ns | 5.675 ns | 5.031 ns | 1,088.57 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,062.92 ns | 7.179 ns | 6.715 ns | 1,060.91 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 802.62 ns | 2.754 ns | 2.441 ns | 802.85 ns | 0.74 | 0.00 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 407.26 ns | 2.298 ns | 2.037 ns | 407.27 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,117.81 ns | 6.631 ns | 6.203 ns | 1,117.31 ns | 2.74 | 0.02 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 830.13 ns | 3.880 ns | 3.440 ns | 830.16 ns | 2.04 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,528.33 ns | 40.727 ns | 36.103 ns | 7,532.99 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,137.39 ns | 8.987 ns | 8.406 ns | 3,138.36 ns | 0.42 | 0.00 | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/SelectToListBenchmarks.md b/Benchmarks/SelectToListBenchmarks.md index 1dfe244bd..af4b1c5ed 100644 --- a/Benchmarks/SelectToListBenchmarks.md +++ b/Benchmarks/SelectToListBenchmarks.md @@ -4,58 +4,58 @@ [SelectToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 328.41 ns | 1.343 ns | 1.190 ns | 328.28 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | -| StructLinq_Array | Array | 100 | 250.78 ns | 1.578 ns | 1.398 ns | 250.56 ns | 0.76 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 238.97 ns | 0.796 ns | 0.705 ns | 238.75 ns | 0.73 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array_SIMD | Array | 100 | 91.71 ns | 0.274 ns | 0.229 ns | 91.75 ns | 0.28 | 0.00 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,077.53 ns | 3.826 ns | 3.391 ns | 1,077.96 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,086.74 ns | 4.359 ns | 3.864 ns | 1,087.33 ns | 1.01 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 584.68 ns | 1.477 ns | 1.233 ns | 584.39 ns | 0.54 | 0.00 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,075.27 ns | 5.659 ns | 4.418 ns | 1,073.35 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,090.71 ns | 4.000 ns | 3.546 ns | 1,092.31 ns | 1.01 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 284.67 ns | 0.905 ns | 0.802 ns | 284.70 ns | 0.26 | 0.00 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 494.15 ns | 2.027 ns | 1.693 ns | 494.24 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Value | List_Value | 100 | 421.75 ns | 2.045 ns | 1.913 ns | 421.72 ns | 0.85 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 699.97 ns | 2.857 ns | 2.385 ns | 700.04 ns | 1.42 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,072.61 ns | 63.935 ns | 49.916 ns | 8,072.89 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,752.00 ns | 10.470 ns | 9.281 ns | 2,749.44 ns | 0.34 | 0.00 | 0.5798 | - | - | 1,216 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,057.57 ns | 6.568 ns | 5.823 ns | 1,056.86 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,070.48 ns | 3.387 ns | 3.168 ns | 1,070.46 ns | 1.01 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,130.56 ns | 6.983 ns | 6.190 ns | 1,129.37 ns | 1.07 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,056.31 ns | 4.561 ns | 3.808 ns | 1,056.26 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,045.65 ns | 4.994 ns | 4.671 ns | 1,045.30 ns | 0.99 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 863.54 ns | 17.211 ns | 40.229 ns | 848.88 ns | 0.85 | 0.05 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 507.48 ns | 2.043 ns | 1.811 ns | 507.20 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,047.64 ns | 3.631 ns | 3.397 ns | 1,046.74 ns | 2.06 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 696.65 ns | 2.076 ns | 1.734 ns | 697.20 ns | 1.37 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,329.45 ns | 30.382 ns | 26.933 ns | 8,333.65 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,534.33 ns | 6.510 ns | 5.436 ns | 3,532.52 ns | 0.42 | 0.00 | 0.5951 | - | - | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|-----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 318.54 ns | 2.104 ns | 1.968 ns | 319.01 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | +| StructLinq_Array | Array | 100 | 274.49 ns | 5.546 ns | 10.552 ns | 268.35 ns | 0.90 | 0.03 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 263.28 ns | 1.527 ns | 1.275 ns | 263.23 ns | 0.83 | 0.01 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array_SIMD | Array | 100 | 94.63 ns | 1.226 ns | 0.958 ns | 94.58 ns | 0.30 | 0.00 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,031.86 ns | 5.098 ns | 4.769 ns | 1,032.46 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,117.67 ns | 19.198 ns | 23.577 ns | 1,130.15 ns | 1.08 | 0.03 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 656.82 ns | 2.735 ns | 2.424 ns | 657.04 ns | 0.64 | 0.00 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,039.83 ns | 4.234 ns | 3.536 ns | 1,039.80 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,073.25 ns | 20.361 ns | 21.786 ns | 1,062.53 ns | 1.04 | 0.02 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 335.40 ns | 1.856 ns | 1.646 ns | 335.36 ns | 0.32 | 0.00 | 0.2179 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 491.66 ns | 1.910 ns | 1.787 ns | 491.87 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Value | List_Value | 100 | 433.96 ns | 2.390 ns | 2.119 ns | 433.79 ns | 0.88 | 0.01 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 877.39 ns | 16.359 ns | 14.502 ns | 881.65 ns | 1.79 | 0.03 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,728.30 ns | 25.213 ns | 22.351 ns | 7,721.39 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,401.31 ns | 7.980 ns | 6.663 ns | 2,399.46 ns | 0.31 | 0.00 | 0.5798 | - | - | 1,216 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,032.95 ns | 4.367 ns | 3.871 ns | 1,033.26 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,086.31 ns | 21.295 ns | 23.669 ns | 1,089.19 ns | 1.04 | 0.02 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,162.20 ns | 5.644 ns | 5.279 ns | 1,160.66 ns | 1.13 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,037.77 ns | 4.895 ns | 4.088 ns | 1,037.80 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,071.48 ns | 19.183 ns | 26.892 ns | 1,054.76 ns | 1.05 | 0.03 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 885.80 ns | 17.755 ns | 20.447 ns | 893.39 ns | 0.84 | 0.02 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 514.96 ns | 2.669 ns | 2.496 ns | 515.25 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,068.53 ns | 6.080 ns | 5.687 ns | 1,066.40 ns | 2.08 | 0.02 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 890.36 ns | 2.653 ns | 2.216 ns | 890.99 ns | 1.73 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,740.03 ns | 104.055 ns | 92.242 ns | 7,689.45 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,188.25 ns | 7.847 ns | 6.956 ns | 3,188.34 ns | 0.41 | 0.00 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/SingleBenchmarks.md b/Benchmarks/SingleBenchmarks.md index b25c4e2ff..608c1a7cc 100644 --- a/Benchmarks/SingleBenchmarks.md +++ b/Benchmarks/SingleBenchmarks.md @@ -4,48 +4,48 @@ [SingleBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------- |-------------------------- |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 11.635 ns | 0.0684 ns | 0.0640 ns | 11.627 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 13.992 ns | 0.0369 ns | 0.0346 ns | 13.991 ns | 1.20 | 0.01 | - | - | - | - | +| Linq_Array | Array | 12.902 ns | 0.0570 ns | 0.0505 ns | 12.905 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 14.553 ns | 0.0493 ns | 0.0412 ns | 14.552 ns | 1.13 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 22.812 ns | 0.1626 ns | 0.1357 ns | 22.762 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 16.591 ns | 0.0190 ns | 0.0148 ns | 16.588 ns | 0.73 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 26.178 ns | 0.1226 ns | 0.1024 ns | 26.166 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 16.540 ns | 0.0497 ns | 0.0441 ns | 16.537 ns | 0.63 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 24.000 ns | 0.0923 ns | 0.0771 ns | 24.008 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 20.092 ns | 0.4312 ns | 0.9283 ns | 19.611 ns | 0.83 | 0.04 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 25.996 ns | 0.1079 ns | 0.0901 ns | 26.006 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 19.269 ns | 0.0717 ns | 0.0671 ns | 19.274 ns | 0.74 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 7.458 ns | 0.0386 ns | 0.0342 ns | 7.458 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 15.178 ns | 0.0638 ns | 0.0533 ns | 15.181 ns | 2.04 | 0.01 | - | - | - | - | +| Linq_List_Value | List_Value | 8.465 ns | 0.0502 ns | 0.0445 ns | 8.468 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 21.993 ns | 0.1262 ns | 0.1054 ns | 21.981 ns | 2.60 | 0.02 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 80.227 ns | 0.2933 ns | 0.2449 ns | 80.195 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 76.277 ns | 0.2799 ns | 0.2481 ns | 76.248 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 23.091 ns | 0.1006 ns | 0.0892 ns | 23.088 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 20.565 ns | 0.2968 ns | 0.3048 ns | 20.477 ns | 0.89 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 26.102 ns | 0.1026 ns | 0.0910 ns | 26.136 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 21.601 ns | 0.4574 ns | 0.6560 ns | 21.870 ns | 0.81 | 0.03 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 23.872 ns | 0.1125 ns | 0.1052 ns | 23.871 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 19.679 ns | 0.1339 ns | 0.1187 ns | 19.635 ns | 0.82 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 27.082 ns | 0.5695 ns | 0.9975 ns | 27.757 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 18.833 ns | 0.1737 ns | 0.1625 ns | 18.805 ns | 0.69 | 0.02 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 7.714 ns | 0.1763 ns | 0.3223 ns | 7.603 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 15.060 ns | 0.0598 ns | 0.0530 ns | 15.045 ns | 1.93 | 0.11 | - | - | - | - | +| Linq_List_Reference | List_Reference | 8.446 ns | 0.0465 ns | 0.0413 ns | 8.435 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 22.542 ns | 0.1073 ns | 0.0951 ns | 22.514 ns | 2.67 | 0.02 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 81.415 ns | 1.6193 ns | 3.4857 ns | 79.958 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 76.279 ns | 1.5123 ns | 1.6810 ns | 76.028 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SkipTakeBenchmarks.md b/Benchmarks/SkipTakeBenchmarks.md index 880a317b1..51d689c90 100644 --- a/Benchmarks/SkipTakeBenchmarks.md +++ b/Benchmarks/SkipTakeBenchmarks.md @@ -4,64 +4,64 @@ [SkipTakeBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Skip | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |----- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 100 | 902.71 ns | 2.658 ns | 2.219 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| StructLinq_Array | Array | 100 | 100 | 112.12 ns | 0.192 ns | 0.160 ns | 0.12 | 0.00 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 100 | 107.79 ns | 0.367 ns | 0.287 ns | 0.12 | 0.00 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 100 | 186.24 ns | 0.505 ns | 0.448 ns | 0.21 | 0.00 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 100 | 81.25 ns | 0.248 ns | 0.219 ns | 0.09 | 0.00 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 100 | 172.23 ns | 0.336 ns | 0.298 ns | 0.19 | 0.00 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 100 | 230.42 ns | 0.646 ns | 0.539 ns | 0.26 | 0.00 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 183.45 ns | 0.349 ns | 0.310 ns | 0.20 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,559.15 ns | 6.211 ns | 5.506 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 994.03 ns | 4.729 ns | 3.692 ns | 0.64 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 475.14 ns | 0.961 ns | 0.852 ns | 0.30 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,558.00 ns | 7.834 ns | 6.945 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 994.20 ns | 3.863 ns | 3.226 ns | 0.64 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 597.12 ns | 3.689 ns | 3.270 ns | 0.38 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 100 | 841.66 ns | 2.832 ns | 2.211 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Value | List_Value | 100 | 100 | 252.80 ns | 1.332 ns | 1.040 ns | 0.30 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 249.39 ns | 1.399 ns | 1.309 ns | 0.30 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 220.75 ns | 0.740 ns | 0.618 ns | 0.26 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 8,763.59 ns | 33.055 ns | 30.920 ns | 1.00 | 0.00 | 0.0763 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 4,701.30 ns | 15.689 ns | 14.676 ns | 0.54 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,560.19 ns | 9.015 ns | 7.992 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 997.33 ns | 3.544 ns | 3.141 ns | 0.64 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,098.92 ns | 3.134 ns | 2.778 ns | 0.70 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,564.56 ns | 10.457 ns | 9.782 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 992.69 ns | 4.468 ns | 4.180 ns | 0.63 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 1,395.36 ns | 24.772 ns | 23.171 ns | 0.89 | 0.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 100 | 839.72 ns | 3.032 ns | 2.532 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Reference | List_Reference | 100 | 100 | 993.12 ns | 5.039 ns | 4.467 ns | 1.18 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 247.86 ns | 0.783 ns | 0.694 ns | 0.30 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 220.54 ns | 0.657 ns | 0.548 ns | 0.26 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 8,813.65 ns | 35.743 ns | 31.685 ns | 1.00 | 0.00 | 0.0763 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 5,739.89 ns | 18.257 ns | 17.078 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Skip | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |----- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 100 | 853.98 ns | 8.132 ns | 7.209 ns | 850.86 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| StructLinq_Array | Array | 100 | 100 | 49.84 ns | 0.203 ns | 0.180 ns | 49.85 ns | 0.06 | 0.00 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 100 | 204.17 ns | 0.634 ns | 0.593 ns | 203.91 ns | 0.24 | 0.00 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 100 | 180.97 ns | 1.274 ns | 1.192 ns | 180.47 ns | 0.21 | 0.00 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 100 | 80.31 ns | 0.330 ns | 0.293 ns | 80.27 ns | 0.09 | 0.00 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 100 | 172.94 ns | 0.375 ns | 0.351 ns | 172.94 ns | 0.20 | 0.00 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 100 | 226.21 ns | 0.971 ns | 0.908 ns | 226.01 ns | 0.26 | 0.00 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 176.05 ns | 0.528 ns | 0.441 ns | 175.99 ns | 0.21 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,480.91 ns | 16.136 ns | 14.304 ns | 1,480.87 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 943.84 ns | 3.397 ns | 3.011 ns | 943.48 ns | 0.64 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 469.67 ns | 1.231 ns | 1.091 ns | 469.61 ns | 0.32 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,508.72 ns | 5.482 ns | 4.860 ns | 1,509.01 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 984.25 ns | 6.638 ns | 6.209 ns | 985.39 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 583.37 ns | 4.036 ns | 3.578 ns | 582.54 ns | 0.39 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 100 | 806.46 ns | 4.327 ns | 3.835 ns | 805.79 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Value | List_Value | 100 | 100 | 224.47 ns | 1.092 ns | 1.021 ns | 224.42 ns | 0.28 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 612.75 ns | 2.801 ns | 2.483 ns | 611.98 ns | 0.76 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 219.77 ns | 1.651 ns | 1.464 ns | 219.57 ns | 0.27 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 8,018.11 ns | 40.874 ns | 34.131 ns | 8,007.43 ns | 1.00 | 0.00 | 0.0763 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 4,301.89 ns | 17.554 ns | 15.561 ns | 4,299.62 ns | 0.54 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,488.30 ns | 11.664 ns | 10.340 ns | 1,486.65 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 979.25 ns | 6.183 ns | 5.163 ns | 977.18 ns | 0.66 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,075.79 ns | 5.613 ns | 4.976 ns | 1,075.80 ns | 0.72 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,507.67 ns | 6.986 ns | 5.833 ns | 1,506.12 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 980.01 ns | 6.165 ns | 5.767 ns | 980.92 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 1,361.27 ns | 8.596 ns | 7.620 ns | 1,360.66 ns | 0.90 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 100 | 805.04 ns | 3.290 ns | 2.916 ns | 804.20 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Reference | List_Reference | 100 | 100 | 942.00 ns | 3.220 ns | 2.854 ns | 942.83 ns | 1.17 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 690.20 ns | 18.041 ns | 52.626 ns | 661.15 ns | 0.95 | 0.07 | - | - | - | - | +| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 242.95 ns | 0.928 ns | 0.775 ns | 243.15 ns | 0.30 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 8,025.06 ns | 43.992 ns | 41.150 ns | 8,020.88 ns | 1.00 | 0.00 | 0.0763 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 5,302.52 ns | 12.140 ns | 10.762 ns | 5,301.04 ns | 0.66 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SumBenchmarks.md b/Benchmarks/SumBenchmarks.md index ebb517241..923aaa914 100644 --- a/Benchmarks/SumBenchmarks.md +++ b/Benchmarks/SumBenchmarks.md @@ -4,58 +4,58 @@ [SumBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 425.27 ns | 2.881 ns | 2.695 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | Array | 100 | 65.84 ns | 0.273 ns | 0.242 ns | 0.15 | 0.00 | - | - | - | - | -| LinqFasterSIMD_Array | Array | 100 | 10.69 ns | 0.044 ns | 0.041 ns | 0.03 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 23.66 ns | 0.072 ns | 0.068 ns | 0.06 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 634.67 ns | 2.631 ns | 2.054 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 605.39 ns | 3.714 ns | 3.474 ns | 0.95 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 219.93 ns | 0.603 ns | 0.534 ns | 0.35 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 634.89 ns | 3.052 ns | 2.706 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 602.10 ns | 2.106 ns | 1.867 ns | 0.95 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 219.81 ns | 0.299 ns | 0.265 ns | 0.35 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 633.89 ns | 4.020 ns | 3.761 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Value | List_Value | 100 | 225.58 ns | 3.444 ns | 4.939 ns | 0.36 | 0.01 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 538.85 ns | 1.711 ns | 1.517 ns | 0.85 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,758.59 ns | 4.769 ns | 4.227 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 991.61 ns | 3.324 ns | 2.947 ns | 0.56 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 630.94 ns | 2.925 ns | 2.736 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 604.48 ns | 2.336 ns | 2.071 ns | 0.96 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 634.73 ns | 2.188 ns | 1.939 ns | 1.01 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 632.99 ns | 3.984 ns | 3.532 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 603.76 ns | 2.819 ns | 2.354 ns | 0.95 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 627.49 ns | 1.632 ns | 1.447 ns | 0.99 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 647.44 ns | 11.664 ns | 19.806 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Reference | List_Reference | 100 | 604.37 ns | 1.283 ns | 1.137 ns | 0.92 | 0.03 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 494.88 ns | 2.268 ns | 1.894 ns | 0.75 | 0.03 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,757.92 ns | 4.957 ns | 4.139 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,776.30 ns | 4.838 ns | 4.288 ns | 1.01 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 439.30 ns | 2.853 ns | 2.529 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 60.82 ns | 0.115 ns | 0.096 ns | 0.14 | - | - | - | - | +| LinqFasterSIMD_Array | Array | 100 | 10.47 ns | 0.060 ns | 0.053 ns | 0.02 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 21.91 ns | 0.116 ns | 0.103 ns | 0.05 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 633.54 ns | 3.352 ns | 2.971 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 596.97 ns | 2.907 ns | 2.719 ns | 0.94 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 201.72 ns | 0.352 ns | 0.294 ns | 0.32 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 621.90 ns | 3.402 ns | 3.015 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 604.20 ns | 2.209 ns | 1.958 ns | 0.97 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 209.29 ns | 0.466 ns | 0.389 ns | 0.34 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 626.93 ns | 2.667 ns | 2.227 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 222.14 ns | 1.074 ns | 0.952 ns | 0.35 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 660.98 ns | 3.469 ns | 3.075 ns | 1.06 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,613.20 ns | 6.600 ns | 5.851 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 827.48 ns | 1.437 ns | 1.273 ns | 0.51 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 621.20 ns | 1.839 ns | 1.630 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 599.42 ns | 4.674 ns | 4.144 ns | 0.96 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 568.79 ns | 2.844 ns | 2.660 ns | 0.92 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 627.08 ns | 6.018 ns | 5.335 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 602.22 ns | 3.609 ns | 3.014 ns | 0.96 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 603.41 ns | 2.582 ns | 2.415 ns | 0.96 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 629.82 ns | 6.382 ns | 5.658 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 601.84 ns | 2.868 ns | 2.683 ns | 0.96 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 630.16 ns | 1.561 ns | 1.219 ns | 1.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,603.92 ns | 4.272 ns | 3.996 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,630.44 ns | 4.742 ns | 4.203 ns | 1.02 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ToArrayBenchmarks.md b/Benchmarks/ToArrayBenchmarks.md index d1b08099b..de4f83bc9 100644 --- a/Benchmarks/ToArrayBenchmarks.md +++ b/Benchmarks/ToArrayBenchmarks.md @@ -4,55 +4,55 @@ [ToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 50.97 ns | 0.450 ns | 0.399 ns | 50.91 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Array | Array | 100 | 82.41 ns | 0.398 ns | 0.372 ns | 82.48 ns | 1.62 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 38.24 ns | 0.447 ns | 0.396 ns | 38.21 ns | 0.75 | 0.01 | 0.2027 | - | - | 424 B | +| Linq_Array | Array | 100 | 59.88 ns | 1.195 ns | 1.227 ns | 60.23 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Array | Array | 100 | 85.69 ns | 1.549 ns | 1.449 ns | 85.96 ns | 1.43 | 0.04 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 38.84 ns | 0.832 ns | 0.925 ns | 38.72 ns | 0.65 | 0.02 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 924.44 ns | 16.211 ns | 26.178 ns | 911.77 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 855.97 ns | 4.395 ns | 3.896 ns | 855.47 ns | 0.91 | 0.03 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 535.49 ns | 2.560 ns | 2.137 ns | 535.19 ns | 0.57 | 0.02 | 0.2213 | - | - | 464 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 964.16 ns | 19.141 ns | 22.786 ns | 969.43 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 940.39 ns | 3.655 ns | 3.419 ns | 940.89 ns | 0.98 | 0.03 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 549.45 ns | 2.348 ns | 2.197 ns | 550.01 ns | 0.57 | 0.02 | 0.2022 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 45.29 ns | 0.259 ns | 0.230 ns | 45.28 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 880.78 ns | 3.505 ns | 2.926 ns | 880.52 ns | 19.45 | 0.09 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 137.30 ns | 0.759 ns | 0.673 ns | 137.27 ns | 3.03 | 0.02 | 0.2217 | - | - | 464 B | +| Linq_Collection_Value | Collection_Value | 100 | 47.70 ns | 0.554 ns | 0.519 ns | 47.74 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 897.71 ns | 7.573 ns | 6.713 ns | 894.91 ns | 18.81 | 0.24 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 284.85 ns | 1.007 ns | 0.942 ns | 284.32 ns | 5.97 | 0.06 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 48.02 ns | 0.598 ns | 0.530 ns | 48.10 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Value | List_Value | 100 | 275.88 ns | 1.662 ns | 1.555 ns | 275.99 ns | 5.75 | 0.08 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 552.05 ns | 3.294 ns | 2.920 ns | 551.52 ns | 11.50 | 0.17 | 0.2022 | - | - | 424 B | +| Linq_List_Value | List_Value | 100 | 56.08 ns | 0.551 ns | 0.488 ns | 56.11 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Value | List_Value | 100 | 265.05 ns | 5.273 ns | 7.729 ns | 268.00 ns | 4.65 | 0.17 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 699.93 ns | 3.692 ns | 3.273 ns | 699.75 ns | 12.48 | 0.10 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 913.85 ns | 7.358 ns | 6.144 ns | 911.78 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 880.11 ns | 4.908 ns | 4.351 ns | 879.76 ns | 0.96 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,012.75 ns | 3.967 ns | 3.517 ns | 1,011.31 ns | 1.11 | 0.01 | 0.2174 | - | - | 456 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 903.06 ns | 5.220 ns | 4.627 ns | 901.71 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 888.17 ns | 5.147 ns | 4.814 ns | 887.75 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,038.64 ns | 5.813 ns | 5.153 ns | 1,038.27 ns | 1.15 | 0.01 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 48.19 ns | 1.145 ns | 3.172 ns | 46.69 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 930.43 ns | 6.676 ns | 6.245 ns | 928.30 ns | 19.60 | 1.21 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 718.27 ns | 6.036 ns | 5.646 ns | 717.41 ns | 15.13 | 0.90 | 0.2289 | - | - | 480 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 47.91 ns | 0.828 ns | 0.646 ns | 47.94 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 894.16 ns | 2.240 ns | 1.749 ns | 893.90 ns | 18.67 | 0.25 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 757.71 ns | 4.528 ns | 4.014 ns | 757.37 ns | 15.82 | 0.20 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 49.20 ns | 1.051 ns | 2.330 ns | 48.29 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Reference | List_Reference | 100 | 882.71 ns | 6.091 ns | 5.399 ns | 880.09 ns | 17.43 | 1.03 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 549.66 ns | 2.190 ns | 1.829 ns | 549.87 ns | 10.82 | 0.64 | 0.2022 | - | - | 424 B | +| Linq_List_Reference | List_Reference | 100 | 49.13 ns | 0.740 ns | 0.822 ns | 48.89 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Reference | List_Reference | 100 | 909.31 ns | 17.445 ns | 23.879 ns | 895.84 ns | 18.61 | 0.61 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 714.93 ns | 3.366 ns | 2.984 ns | 713.96 ns | 14.53 | 0.24 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,335.34 ns | 3.342 ns | 2.791 ns | 1,335.74 ns | ? | ? | 0.5646 | - | - | 1,184 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,157.19 ns | 3.927 ns | 3.066 ns | 1,157.21 ns | ? | ? | 0.5646 | - | - | 1,184 B | | | | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,126.59 ns | 5.203 ns | 4.062 ns | 2,126.87 ns | ? | ? | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,974.38 ns | 12.564 ns | 11.137 ns | 1,974.81 ns | ? | ? | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/ToListBenchmarks.md b/Benchmarks/ToListBenchmarks.md index 39f882f6c..da71d4de1 100644 --- a/Benchmarks/ToListBenchmarks.md +++ b/Benchmarks/ToListBenchmarks.md @@ -4,57 +4,57 @@ [ToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 57.07 ns | 0.628 ns | 0.556 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Array | Array | 100 | 117.12 ns | 0.639 ns | 0.598 ns | 2.05 | 0.02 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 48.40 ns | 0.729 ns | 0.682 ns | 0.85 | 0.02 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 880.19 ns | 3.297 ns | 2.922 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 881.63 ns | 3.729 ns | 3.306 ns | 1.00 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 548.65 ns | 6.695 ns | 10.224 ns | 0.62 | 0.01 | 0.2365 | - | - | 496 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 51.04 ns | 0.384 ns | 0.340 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 883.85 ns | 5.757 ns | 4.807 ns | 17.33 | 0.15 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 149.37 ns | 0.969 ns | 0.809 ns | 2.93 | 0.02 | 0.2370 | - | - | 496 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 53.30 ns | 0.464 ns | 0.412 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Value | List_Value | 100 | 256.68 ns | 1.914 ns | 1.598 ns | 4.82 | 0.05 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 600.97 ns | 2.968 ns | 2.776 ns | 11.27 | 0.10 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,045.94 ns | 9.630 ns | 8.042 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,402.94 ns | 4.992 ns | 4.669 ns | 0.69 | 0.00 | 0.5798 | - | - | 1,216 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 880.06 ns | 4.079 ns | 3.616 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 910.87 ns | 3.254 ns | 2.885 ns | 1.04 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,019.00 ns | 3.928 ns | 3.674 ns | 1.16 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 50.64 ns | 0.554 ns | 0.519 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 886.92 ns | 6.848 ns | 5.719 ns | 17.50 | 0.17 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 748.21 ns | 9.986 ns | 8.339 ns | 14.76 | 0.23 | 0.2441 | - | - | 512 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 52.48 ns | 0.279 ns | 0.248 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Reference | List_Reference | 100 | 886.53 ns | 4.900 ns | 4.344 ns | 16.89 | 0.08 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 562.00 ns | 3.656 ns | 3.419 ns | 10.71 | 0.09 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,070.35 ns | 11.109 ns | 9.276 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,190.63 ns | 6.834 ns | 6.392 ns | 1.06 | 0.00 | 0.5951 | - | - | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 59.28 ns | 1.254 ns | 1.288 ns | 59.79 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Array | Array | 100 | 92.73 ns | 0.843 ns | 0.747 ns | 92.66 ns | 1.56 | 0.04 | 0.2180 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 49.88 ns | 1.064 ns | 2.629 ns | 48.68 ns | 0.83 | 0.05 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 948.74 ns | 18.850 ns | 36.317 ns | 925.55 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 938.74 ns | 3.250 ns | 2.537 ns | 938.82 ns | 0.98 | 0.03 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 558.80 ns | 11.170 ns | 18.037 ns | 566.01 ns | 0.58 | 0.03 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 54.69 ns | 1.149 ns | 2.732 ns | 53.34 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 943.48 ns | 8.286 ns | 6.919 ns | 940.54 ns | 17.62 | 0.44 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 293.56 ns | 4.750 ns | 6.659 ns | 291.01 ns | 5.25 | 0.33 | 0.2179 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 58.06 ns | 1.221 ns | 3.017 ns | 57.68 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Value | List_Value | 100 | 255.44 ns | 1.213 ns | 0.947 ns | 255.64 ns | 4.27 | 0.21 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 744.41 ns | 6.725 ns | 6.291 ns | 743.00 ns | 12.39 | 0.55 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,870.70 ns | 5.179 ns | 4.591 ns | 1,870.29 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,208.58 ns | 6.498 ns | 5.760 ns | 1,208.21 ns | 0.65 | 0.00 | 0.5798 | - | - | 1,216 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 939.71 ns | 18.708 ns | 37.361 ns | 913.84 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 992.53 ns | 7.155 ns | 5.975 ns | 991.79 ns | 1.04 | 0.04 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,009.21 ns | 8.154 ns | 7.627 ns | 1,008.90 ns | 1.05 | 0.04 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 56.80 ns | 1.201 ns | 3.144 ns | 56.97 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 932.65 ns | 7.394 ns | 5.773 ns | 931.02 ns | 16.72 | 0.80 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 706.73 ns | 12.697 ns | 19.004 ns | 716.63 ns | 12.33 | 0.53 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 54.98 ns | 1.086 ns | 0.848 ns | 55.10 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Reference | List_Reference | 100 | 969.38 ns | 14.223 ns | 18.988 ns | 975.80 ns | 17.70 | 0.40 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 743.46 ns | 3.592 ns | 2.999 ns | 743.35 ns | 13.53 | 0.23 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,983.00 ns | 13.421 ns | 12.554 ns | 1,978.37 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,033.51 ns | 12.827 ns | 10.711 ns | 2,028.62 ns | 1.03 | 0.01 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/WhereBenchmarks.md b/Benchmarks/WhereBenchmarks.md index e63a126d7..c604309c0 100644 --- a/Benchmarks/WhereBenchmarks.md +++ b/Benchmarks/WhereBenchmarks.md @@ -4,59 +4,59 @@ [WhereBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 482.7 ns | 2.93 ns | 2.60 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 255.5 ns | 1.88 ns | 1.76 ns | 0.53 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 275.0 ns | 2.62 ns | 2.32 ns | 0.57 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 283.5 ns | 1.19 ns | 0.99 ns | 0.59 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 258.8 ns | 1.24 ns | 1.16 ns | 0.54 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,378.9 ns | 4.68 ns | 4.15 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,281.6 ns | 4.92 ns | 4.36 ns | 0.93 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 245.6 ns | 1.43 ns | 1.27 ns | 0.18 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,372.2 ns | 5.77 ns | 5.40 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,309.7 ns | 5.30 ns | 4.70 ns | 0.95 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 246.7 ns | 1.16 ns | 1.03 ns | 0.18 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,430.2 ns | 3.68 ns | 3.07 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 592.9 ns | 3.64 ns | 3.22 ns | 0.41 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 668.1 ns | 1.79 ns | 1.59 ns | 0.47 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,788.7 ns | 13.25 ns | 11.07 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,136.0 ns | 13.36 ns | 11.85 ns | 1.07 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,384.4 ns | 5.79 ns | 4.83 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,292.5 ns | 4.30 ns | 3.59 ns | 0.93 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,279.8 ns | 7.65 ns | 6.39 ns | 0.92 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,404.8 ns | 6.73 ns | 5.97 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,286.7 ns | 3.31 ns | 3.10 ns | 0.92 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,255.1 ns | 3.37 ns | 3.15 ns | 0.89 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,379.1 ns | 4.52 ns | 4.01 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,288.6 ns | 5.30 ns | 4.70 ns | 0.93 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 675.4 ns | 2.44 ns | 2.28 ns | 0.49 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,819.7 ns | 23.74 ns | 22.20 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,155.6 ns | 15.89 ns | 12.40 ns | 1.07 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 476.1 ns | 1.28 ns | 1.00 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 420.7 ns | 2.05 ns | 1.60 ns | 0.88 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 454.9 ns | 8.96 ns | 7.48 ns | 0.96 | 0.02 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 285.2 ns | 3.14 ns | 2.78 ns | 0.60 | 0.01 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 281.9 ns | 3.91 ns | 3.66 ns | 0.59 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,435.5 ns | 4.18 ns | 3.49 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,312.0 ns | 4.36 ns | 3.87 ns | 0.91 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 318.3 ns | 5.67 ns | 4.73 ns | 0.22 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,425.6 ns | 5.94 ns | 4.96 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,250.3 ns | 4.41 ns | 4.12 ns | 0.88 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 457.9 ns | 2.28 ns | 2.02 ns | 0.32 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,424.8 ns | 6.49 ns | 5.75 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 537.2 ns | 6.07 ns | 5.38 ns | 0.38 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1,192.8 ns | 4.17 ns | 3.69 ns | 0.84 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,588.5 ns | 28.72 ns | 25.46 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,824.0 ns | 38.62 ns | 34.24 ns | 1.05 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,472.5 ns | 9.86 ns | 9.23 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,315.8 ns | 5.21 ns | 4.35 ns | 0.89 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,323.7 ns | 12.74 ns | 10.64 ns | 0.90 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,445.5 ns | 4.36 ns | 4.08 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,281.3 ns | 7.90 ns | 7.01 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,201.4 ns | 5.52 ns | 4.90 ns | 0.83 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,486.3 ns | 3.86 ns | 3.61 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,313.5 ns | 4.98 ns | 4.41 ns | 0.88 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,239.1 ns | 5.14 ns | 4.02 ns | 0.83 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,582.2 ns | 12.88 ns | 12.04 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,766.2 ns | 26.21 ns | 20.46 ns | 1.04 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereCountBenchmarks.md b/Benchmarks/WhereCountBenchmarks.md index 8e7d6af7f..a00d88929 100644 --- a/Benchmarks/WhereCountBenchmarks.md +++ b/Benchmarks/WhereCountBenchmarks.md @@ -4,59 +4,59 @@ [WhereCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 683.0 ns | 3.38 ns | 2.82 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | Array | 100 | 242.0 ns | 2.34 ns | 2.07 ns | 0.35 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 175.4 ns | 0.35 ns | 0.27 ns | 0.26 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 197.9 ns | 0.64 ns | 0.54 ns | 0.29 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 201.8 ns | 0.50 ns | 0.41 ns | 0.30 | - | - | - | - | +| Linq_Array | Array | 100 | 842.3 ns | 2.02 ns | 1.69 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 239.0 ns | 1.77 ns | 1.57 ns | 0.28 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 198.2 ns | 0.82 ns | 0.73 ns | 0.24 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 172.3 ns | 0.81 ns | 0.76 ns | 0.20 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 199.3 ns | 0.45 ns | 0.40 ns | 0.24 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,173.3 ns | 7.26 ns | 6.79 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,117.3 ns | 4.93 ns | 4.37 ns | 0.95 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 206.0 ns | 1.31 ns | 1.02 ns | 0.18 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,059.7 ns | 4.74 ns | 4.43 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,030.2 ns | 4.70 ns | 3.92 ns | 0.97 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 223.6 ns | 0.60 ns | 0.50 ns | 0.21 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,187.3 ns | 9.07 ns | 7.57 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,139.5 ns | 5.64 ns | 5.00 ns | 0.96 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 213.0 ns | 0.73 ns | 0.64 ns | 0.18 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,075.4 ns | 4.71 ns | 4.17 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,057.9 ns | 4.87 ns | 4.56 ns | 0.98 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 218.1 ns | 0.77 ns | 0.65 ns | 0.20 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,168.6 ns | 4.37 ns | 3.65 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Value | List_Value | 100 | 498.9 ns | 2.41 ns | 2.13 ns | 0.43 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 702.5 ns | 2.26 ns | 2.11 ns | 0.60 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 1,091.3 ns | 7.05 ns | 6.59 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 451.4 ns | 2.28 ns | 2.02 ns | 0.41 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 826.2 ns | 2.40 ns | 2.13 ns | 0.76 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,849.7 ns | 5.54 ns | 4.91 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,816.1 ns | 3.11 ns | 2.42 ns | 1.52 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,696.3 ns | 4.29 ns | 3.58 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,488.0 ns | 3.12 ns | 2.77 ns | 1.47 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,165.7 ns | 6.51 ns | 5.77 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,139.5 ns | 4.77 ns | 4.47 ns | 0.98 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 769.7 ns | 3.39 ns | 3.01 ns | 0.66 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,080.9 ns | 3.99 ns | 3.54 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,030.4 ns | 4.60 ns | 4.08 ns | 0.95 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 731.4 ns | 2.25 ns | 2.00 ns | 0.68 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,165.7 ns | 6.68 ns | 6.25 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,099.9 ns | 2.64 ns | 2.47 ns | 0.94 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 804.9 ns | 2.60 ns | 2.30 ns | 0.69 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,083.8 ns | 6.26 ns | 5.85 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,053.2 ns | 3.79 ns | 3.36 ns | 0.97 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 714.5 ns | 7.96 ns | 6.64 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,162.3 ns | 4.96 ns | 4.64 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,100.8 ns | 4.93 ns | 4.61 ns | 0.95 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 688.8 ns | 3.99 ns | 3.54 ns | 0.59 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 1,068.2 ns | 4.53 ns | 4.01 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,045.3 ns | 6.44 ns | 5.71 ns | 0.98 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 781.7 ns | 4.09 ns | 3.62 ns | 0.73 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,849.7 ns | 4.99 ns | 4.42 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,148.6 ns | 7.67 ns | 6.80 ns | 1.70 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,689.9 ns | 3.43 ns | 3.04 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,839.4 ns | 4.06 ns | 3.60 ns | 1.68 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereFirstBenchmarks.md b/Benchmarks/WhereFirstBenchmarks.md index 9efc1de34..41229396f 100644 --- a/Benchmarks/WhereFirstBenchmarks.md +++ b/Benchmarks/WhereFirstBenchmarks.md @@ -4,50 +4,50 @@ [WhereFirstBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 585.0 ns | 3.10 ns | 2.75 ns | 584.7 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Array | Array | 100 | 211.1 ns | 0.79 ns | 0.74 ns | 211.1 ns | 0.36 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 755.3 ns | 4.54 ns | 4.03 ns | 754.5 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 219.2 ns | 0.84 ns | 0.75 ns | 219.4 ns | 0.29 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 752.8 ns | 4.13 ns | 3.87 ns | 752.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 225.7 ns | 0.79 ns | 0.70 ns | 225.6 ns | 0.30 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 753.9 ns | 2.72 ns | 2.41 ns | 753.9 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Value | List_Value | 100 | 670.8 ns | 2.08 ns | 1.74 ns | 670.9 ns | 0.89 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,914.6 ns | 4.18 ns | 3.49 ns | 1,915.0 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,934.7 ns | 7.32 ns | 6.84 ns | 2,933.2 ns | 1.53 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 796.3 ns | 3.15 ns | 2.79 ns | 796.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 775.8 ns | 2.32 ns | 2.06 ns | 776.4 ns | 0.97 | 0.00 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 792.5 ns | 2.01 ns | 1.78 ns | 792.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 793.4 ns | 2.35 ns | 2.08 ns | 793.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 816.9 ns | 16.29 ns | 32.15 ns | 801.4 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 676.6 ns | 2.79 ns | 2.61 ns | 676.2 ns | 0.83 | 0.03 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,918.5 ns | 7.27 ns | 6.07 ns | 1,919.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,241.0 ns | 21.98 ns | 18.35 ns | 3,236.1 ns | 1.69 | 0.01 | 0.0458 | - | - | 96 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 607.3 ns | 2.67 ns | 2.37 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Array | Array | 100 | 213.5 ns | 3.27 ns | 3.06 ns | 0.35 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 776.9 ns | 3.00 ns | 2.81 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 243.3 ns | 4.84 ns | 5.76 ns | 0.32 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 763.9 ns | 2.67 ns | 2.37 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 241.3 ns | 1.59 ns | 1.41 ns | 0.32 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 797.4 ns | 6.86 ns | 5.36 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Value | List_Value | 100 | 790.3 ns | 2.20 ns | 2.06 ns | 0.99 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,770.0 ns | 5.42 ns | 4.81 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,607.4 ns | 7.50 ns | 6.65 ns | 1.47 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 747.5 ns | 3.38 ns | 2.99 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 753.7 ns | 2.27 ns | 2.12 ns | 1.01 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 751.1 ns | 11.02 ns | 10.30 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 768.9 ns | 2.22 ns | 1.97 ns | 1.02 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 742.8 ns | 10.66 ns | 9.45 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 767.8 ns | 3.95 ns | 3.29 ns | 1.03 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,745.1 ns | 6.89 ns | 6.11 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,868.8 ns | 13.30 ns | 11.79 ns | 1.64 | 0.0458 | - | - | 96 B | diff --git a/Benchmarks/WhereSelectBenchmarks.md b/Benchmarks/WhereSelectBenchmarks.md index baeab94a0..703081eed 100644 --- a/Benchmarks/WhereSelectBenchmarks.md +++ b/Benchmarks/WhereSelectBenchmarks.md @@ -4,59 +4,59 @@ [WhereSelectBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 699.0 ns | 8.31 ns | 7.37 ns | 1.00 | 0.00 | 0.0496 | - | - | 104 B | -| StructLinq_Array | Array | 100 | 354.4 ns | 1.18 ns | 1.05 ns | 0.51 | 0.01 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 376.4 ns | 2.92 ns | 2.58 ns | 0.54 | 0.01 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 370.5 ns | 2.20 ns | 1.95 ns | 0.53 | 0.01 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 389.2 ns | 1.10 ns | 0.97 ns | 0.56 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,565.5 ns | 5.14 ns | 4.02 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,397.1 ns | 7.10 ns | 6.29 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 360.3 ns | 0.96 ns | 0.75 ns | 0.23 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,606.3 ns | 24.27 ns | 18.95 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,331.4 ns | 7.65 ns | 6.78 ns | 0.83 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 388.9 ns | 7.71 ns | 14.85 ns | 0.24 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,587.1 ns | 28.89 ns | 22.56 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Value | List_Value | 100 | 805.4 ns | 3.80 ns | 2.97 ns | 0.51 | 0.01 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 777.0 ns | 11.53 ns | 14.15 ns | 0.49 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,871.2 ns | 62.58 ns | 55.47 ns | 1.00 | 0.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,789.1 ns | 51.25 ns | 47.94 ns | 1.19 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,565.6 ns | 6.76 ns | 5.99 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,345.7 ns | 17.99 ns | 25.80 ns | 0.86 | 0.02 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,301.5 ns | 25.08 ns | 31.72 ns | 0.83 | 0.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,561.5 ns | 5.99 ns | 5.31 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,395.4 ns | 4.25 ns | 3.98 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,278.9 ns | 5.40 ns | 5.05 ns | 0.82 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,556.2 ns | 15.73 ns | 12.28 ns | 1.00 | 0.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,327.4 ns | 5.37 ns | 4.48 ns | 0.85 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 783.5 ns | 3.26 ns | 3.05 ns | 0.50 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,026.8 ns | 100.49 ns | 181.20 ns | 1.00 | 0.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,829.7 ns | 16.69 ns | 14.80 ns | 1.13 | 0.05 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 685.4 ns | 5.29 ns | 4.69 ns | 1.00 | 0.0496 | - | - | 104 B | +| StructLinq_Array | Array | 100 | 341.1 ns | 4.00 ns | 3.55 ns | 0.50 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 320.2 ns | 2.11 ns | 1.76 ns | 0.47 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 342.0 ns | 1.98 ns | 1.76 ns | 0.50 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 311.5 ns | 1.76 ns | 1.56 ns | 0.45 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,534.6 ns | 6.02 ns | 5.33 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,295.4 ns | 7.73 ns | 6.45 ns | 0.84 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 344.9 ns | 1.64 ns | 1.54 ns | 0.22 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,534.1 ns | 6.13 ns | 4.79 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,314.8 ns | 5.35 ns | 5.01 ns | 0.86 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 337.7 ns | 1.82 ns | 1.52 ns | 0.22 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,560.1 ns | 6.92 ns | 5.78 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Value | List_Value | 100 | 641.5 ns | 2.23 ns | 2.09 ns | 0.41 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1,309.6 ns | 7.32 ns | 6.49 ns | 0.84 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,566.5 ns | 18.63 ns | 16.51 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,182.6 ns | 15.41 ns | 13.66 ns | 1.13 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,536.6 ns | 11.02 ns | 10.30 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,263.9 ns | 4.48 ns | 3.97 ns | 0.82 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,305.1 ns | 8.92 ns | 7.91 ns | 0.85 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,539.3 ns | 9.95 ns | 8.82 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,340.1 ns | 4.31 ns | 3.82 ns | 0.87 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,303.3 ns | 5.44 ns | 4.54 ns | 0.85 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,507.4 ns | 7.45 ns | 6.60 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,317.5 ns | 7.39 ns | 6.17 ns | 0.87 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,316.8 ns | 7.71 ns | 7.21 ns | 0.87 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,638.1 ns | 14.50 ns | 12.85 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,311.7 ns | 22.40 ns | 20.96 ns | 1.15 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereSelectCountBenchmarks.md b/Benchmarks/WhereSelectCountBenchmarks.md index 178275130..77fd0e860 100644 --- a/Benchmarks/WhereSelectCountBenchmarks.md +++ b/Benchmarks/WhereSelectCountBenchmarks.md @@ -4,50 +4,50 @@ [WhereSelectCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 345.9 ns | 0.90 ns | 0.84 ns | 1.00 | 0.0496 | - | - | 104 B | -| Hyperlinq_Array | Array | 100 | 209.4 ns | 1.38 ns | 1.15 ns | 0.61 | - | - | - | - | +| Linq_Array | Array | 100 | 340.2 ns | 1.68 ns | 1.49 ns | 1.00 | 0.0496 | - | - | 104 B | +| Hyperlinq_Array | Array | 100 | 207.8 ns | 0.89 ns | 0.83 ns | 0.61 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,264.3 ns | 4.34 ns | 4.06 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 214.1 ns | 0.76 ns | 0.67 ns | 0.17 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,227.6 ns | 3.23 ns | 2.86 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 223.6 ns | 1.07 ns | 0.90 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,279.1 ns | 4.00 ns | 3.34 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 221.3 ns | 1.91 ns | 1.69 ns | 0.17 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,213.9 ns | 6.79 ns | 6.02 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 244.9 ns | 0.98 ns | 0.82 ns | 0.20 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,246.3 ns | 4.13 ns | 3.44 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Value | List_Value | 100 | 630.4 ns | 2.49 ns | 2.21 ns | 0.51 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 1,217.0 ns | 8.90 ns | 7.43 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Value | List_Value | 100 | 825.4 ns | 3.13 ns | 2.93 ns | 0.68 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,311.0 ns | 22.90 ns | 21.42 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,826.6 ns | 7.29 ns | 6.47 ns | 0.53 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,807.9 ns | 13.21 ns | 11.71 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,502.3 ns | 4.88 ns | 4.57 ns | 0.52 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,274.2 ns | 5.65 ns | 5.00 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 775.7 ns | 3.07 ns | 2.88 ns | 0.61 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,161.1 ns | 7.68 ns | 6.80 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 736.1 ns | 2.98 ns | 2.79 ns | 0.63 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,261.5 ns | 4.05 ns | 3.59 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 799.5 ns | 3.15 ns | 2.79 ns | 0.63 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,238.9 ns | 7.04 ns | 5.88 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 756.8 ns | 2.86 ns | 2.53 ns | 0.61 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,265.8 ns | 2.83 ns | 2.36 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 649.8 ns | 2.98 ns | 2.49 ns | 0.51 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 1,218.8 ns | 5.17 ns | 4.58 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 798.9 ns | 2.40 ns | 2.00 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,174.8 ns | 38.53 ns | 30.08 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,162.1 ns | 9.40 ns | 8.80 ns | 0.61 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,858.8 ns | 17.22 ns | 13.44 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,826.6 ns | 7.05 ns | 5.89 ns | 0.58 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereSingleBenchmarks.md b/Benchmarks/WhereSingleBenchmarks.md index a98ae37b5..c08836cfa 100644 --- a/Benchmarks/WhereSingleBenchmarks.md +++ b/Benchmarks/WhereSingleBenchmarks.md @@ -4,48 +4,48 @@ [WhereSingleBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------- |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 599.1 ns | 3.34 ns | 2.97 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Array | Array | 100 | 187.4 ns | 0.61 ns | 0.54 ns | 0.31 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 803.8 ns | 3.14 ns | 2.78 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 225.4 ns | 0.87 ns | 0.77 ns | 0.28 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 770.7 ns | 4.53 ns | 4.02 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 226.8 ns | 0.82 ns | 0.72 ns | 0.29 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 770.0 ns | 3.13 ns | 2.77 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Value | List_Value | 100 | 699.6 ns | 1.56 ns | 1.38 ns | 0.91 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,910.7 ns | 4.99 ns | 4.67 ns | 1.00 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 770.5 ns | 4.03 ns | 3.37 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 779.4 ns | 3.55 ns | 3.15 ns | 1.01 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 821.6 ns | 3.66 ns | 3.25 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 752.5 ns | 3.27 ns | 3.06 ns | 0.92 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 801.4 ns | 3.33 ns | 3.12 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 635.3 ns | 1.86 ns | 1.56 ns | 0.79 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,938.1 ns | 6.93 ns | 6.14 ns | 1.00 | 0.0458 | - | - | 96 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------- |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 594.5 ns | 5.05 ns | 4.72 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Array | Array | 100 | 189.5 ns | 2.34 ns | 1.95 ns | 0.32 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 717.0 ns | 3.46 ns | 3.07 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 261.6 ns | 4.08 ns | 4.00 ns | 0.37 | 0.01 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 784.2 ns | 5.06 ns | 4.73 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 269.9 ns | 1.43 ns | 1.27 ns | 0.34 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 754.6 ns | 3.91 ns | 3.06 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Value | List_Value | 100 | 751.4 ns | 3.06 ns | 2.86 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,727.5 ns | 5.56 ns | 4.92 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 756.5 ns | 2.78 ns | 2.46 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 775.9 ns | 7.57 ns | 6.71 ns | 1.03 | 0.01 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 730.3 ns | 6.58 ns | 6.15 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 880.0 ns | 17.50 ns | 39.87 ns | 1.20 | 0.04 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 780.9 ns | 3.25 ns | 2.88 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,351.5 ns | 24.31 ns | 22.74 ns | 1.73 | 0.03 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,721.3 ns | 5.21 ns | 4.87 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | diff --git a/Benchmarks/WhereToArrayBenchmarks.md b/Benchmarks/WhereToArrayBenchmarks.md index 07840b8c2..fc23b61ab 100644 --- a/Benchmarks/WhereToArrayBenchmarks.md +++ b/Benchmarks/WhereToArrayBenchmarks.md @@ -4,57 +4,57 @@ [WhereToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 427.1 ns | 1.44 ns | 1.20 ns | 1.00 | 0.3519 | - | - | 736 B | -| StructLinq_Array | Array | 100 | 403.1 ns | 1.33 ns | 1.11 ns | 0.94 | 0.1144 | - | - | 240 B | -| Hyperlinq_Array | Array | 100 | 508.5 ns | 2.19 ns | 1.94 ns | 1.19 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,196.0 ns | 7.47 ns | 6.63 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,231.8 ns | 2.70 ns | 2.10 ns | 1.03 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 550.9 ns | 3.57 ns | 3.16 ns | 0.46 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,205.4 ns | 3.50 ns | 2.92 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,257.0 ns | 6.59 ns | 5.84 ns | 1.04 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 521.4 ns | 1.31 ns | 1.03 ns | 0.43 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,208.0 ns | 3.79 ns | 3.36 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Value | List_Value | 100 | 806.1 ns | 3.44 ns | 3.05 ns | 0.67 | 0.1144 | - | - | 240 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,147.2 ns | 2.94 ns | 2.45 ns | 0.95 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,377.3 ns | 32.86 ns | 29.13 ns | 1.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,278.9 ns | 11.69 ns | 10.94 ns | 0.61 | 0.3433 | - | - | 720 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,241.1 ns | 5.44 ns | 4.82 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,250.7 ns | 4.35 ns | 3.85 ns | 1.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,347.2 ns | 5.68 ns | 4.74 ns | 1.09 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,233.7 ns | 3.62 ns | 3.21 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,240.4 ns | 3.89 ns | 3.25 ns | 1.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,373.4 ns | 2.59 ns | 2.16 ns | 1.11 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,267.2 ns | 6.20 ns | 5.50 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,245.2 ns | 3.72 ns | 3.29 ns | 0.98 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,184.4 ns | 2.50 ns | 1.95 ns | 0.94 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,438.5 ns | 40.03 ns | 37.45 ns | 1.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,029.0 ns | 9.78 ns | 9.15 ns | 0.74 | 0.3586 | - | - | 752 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 508.9 ns | 23.93 ns | 70.18 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | +| StructLinq_Array | Array | 100 | 420.0 ns | 8.31 ns | 9.89 ns | 0.80 | 0.05 | 0.1144 | - | - | 240 B | +| Hyperlinq_Array | Array | 100 | 483.7 ns | 2.73 ns | 2.56 ns | 0.91 | 0.09 | 0.1144 | - | - | 240 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,360.0 ns | 21.55 ns | 20.16 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,235.3 ns | 3.55 ns | 2.77 ns | 0.91 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 548.7 ns | 3.04 ns | 2.70 ns | 0.40 | 0.01 | 0.1144 | - | - | 240 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,295.6 ns | 6.24 ns | 5.21 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,218.2 ns | 6.60 ns | 5.85 ns | 0.94 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 569.5 ns | 3.02 ns | 2.68 ns | 0.44 | 0.00 | 0.1144 | - | - | 240 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,294.1 ns | 4.14 ns | 3.46 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Value | List_Value | 100 | 824.5 ns | 5.59 ns | 5.23 ns | 0.64 | 0.00 | 0.1144 | - | - | 240 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,307.7 ns | 6.50 ns | 6.08 ns | 1.01 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,111.2 ns | 34.86 ns | 30.90 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,868.6 ns | 13.02 ns | 10.87 ns | 0.56 | 0.00 | 0.3433 | - | - | 720 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,264.1 ns | 10.27 ns | 9.61 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,212.4 ns | 5.85 ns | 5.19 ns | 0.96 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,308.1 ns | 7.94 ns | 7.04 ns | 1.04 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,284.0 ns | 9.48 ns | 8.87 ns | 1.00 | 0.00 | 0.3681 | - | - | 776 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,217.6 ns | 6.08 ns | 5.08 ns | 0.95 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,292.9 ns | 5.11 ns | 4.53 ns | 1.01 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,287.8 ns | 8.44 ns | 7.48 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,268.3 ns | 4.33 ns | 3.84 ns | 0.98 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,400.0 ns | 14.89 ns | 13.20 ns | 1.09 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,972.6 ns | 62.02 ns | 54.98 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,526.4 ns | 39.59 ns | 37.04 ns | 0.71 | 0.01 | 0.3548 | - | - | 752 B | diff --git a/Benchmarks/WhereToListBenchmarks.md b/Benchmarks/WhereToListBenchmarks.md index a7c6ec886..f13a0ca13 100644 --- a/Benchmarks/WhereToListBenchmarks.md +++ b/Benchmarks/WhereToListBenchmarks.md @@ -4,57 +4,57 @@ [WhereToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.2.21154.6 +- Linq: 6.0.0-preview.4.21253.7 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.25.3](https://www.nuget.org/packages/StructLinq/0.25.3) +- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) - NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) ### Results: ``` ini -BenchmarkDotNet=v0.12.1.1521-nightly, OS=Windows 10.0.19043 +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.2.21155.3 - [Host] : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT - Job-XHOKQA : .NET 6.0.0 (6.0.21.15406), X64 RyuJIT +.NET SDK=6.0.100-preview.4.21255.9 + [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 360.4 ns | 0.78 ns | 0.65 ns | 1.00 | 0.3328 | - | - | 696 B | -| StructLinq_Array | Array | 100 | 413.7 ns | 2.24 ns | 1.99 ns | 1.15 | 0.1297 | - | - | 272 B | -| Hyperlinq_Array | Array | 100 | 506.2 ns | 4.85 ns | 4.05 ns | 1.40 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,223.5 ns | 4.30 ns | 3.59 ns | 1.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,261.3 ns | 6.69 ns | 6.25 ns | 1.03 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 521.5 ns | 3.36 ns | 3.14 ns | 0.43 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,232.6 ns | 11.34 ns | 9.47 ns | 1.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,253.2 ns | 2.26 ns | 1.89 ns | 1.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 532.1 ns | 3.83 ns | 3.59 ns | 0.43 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,227.6 ns | 3.87 ns | 3.23 ns | 1.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Value | List_Value | 100 | 812.6 ns | 5.19 ns | 4.05 ns | 0.66 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,228.8 ns | 8.43 ns | 7.89 ns | 1.00 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,264.3 ns | 14.12 ns | 13.21 ns | 1.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,278.2 ns | 9.48 ns | 8.40 ns | 0.62 | 0.3586 | - | - | 752 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,225.8 ns | 2.45 ns | 1.91 ns | 1.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,258.7 ns | 3.44 ns | 3.05 ns | 1.03 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,319.2 ns | 5.28 ns | 4.41 ns | 1.08 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,226.7 ns | 3.26 ns | 2.89 ns | 1.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,247.0 ns | 4.48 ns | 3.97 ns | 1.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,370.6 ns | 5.58 ns | 4.66 ns | 1.12 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,231.1 ns | 7.91 ns | 7.01 ns | 1.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,242.9 ns | 4.32 ns | 3.37 ns | 1.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,210.8 ns | 5.63 ns | 5.27 ns | 0.98 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,347.5 ns | 15.41 ns | 13.66 ns | 1.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,975.5 ns | 9.77 ns | 9.14 ns | 0.74 | 0.3738 | - | - | 784 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 395.9 ns | 1.46 ns | 2.23 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | +| StructLinq_Array | Array | 100 | 427.0 ns | 2.38 ns | 2.11 ns | 1.08 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Array | Array | 100 | 487.7 ns | 2.52 ns | 2.24 ns | 1.23 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,188.2 ns | 5.73 ns | 5.36 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,223.5 ns | 15.17 ns | 22.71 ns | 1.03 | 0.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 552.2 ns | 9.09 ns | 8.06 ns | 0.46 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,130.1 ns | 5.41 ns | 4.79 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,232.5 ns | 7.81 ns | 7.31 ns | 1.09 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 580.9 ns | 10.97 ns | 10.26 ns | 0.51 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,135.3 ns | 5.03 ns | 4.20 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Value | List_Value | 100 | 819.8 ns | 3.41 ns | 2.84 ns | 0.72 | 0.00 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,375.5 ns | 8.27 ns | 7.33 ns | 1.21 | 0.01 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,116.5 ns | 21.33 ns | 19.95 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,956.4 ns | 44.63 ns | 41.75 ns | 0.58 | 0.01 | 0.3586 | - | - | 752 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,201.5 ns | 8.47 ns | 7.08 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,200.7 ns | 4.88 ns | 4.33 ns | 1.00 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,297.9 ns | 20.30 ns | 19.94 ns | 1.08 | 0.02 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,165.1 ns | 3.84 ns | 3.60 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,221.9 ns | 21.50 ns | 20.11 ns | 1.05 | 0.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,366.8 ns | 3.97 ns | 3.52 ns | 1.17 | 0.00 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,137.7 ns | 7.08 ns | 6.62 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,241.5 ns | 22.59 ns | 17.63 ns | 1.09 | 0.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,363.4 ns | 4.61 ns | 3.60 ns | 1.20 | 0.01 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,112.7 ns | 20.47 ns | 18.14 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,583.1 ns | 45.80 ns | 42.84 ns | 0.70 | 0.01 | 0.3738 | - | - | 784 B | diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index d8b1e4e01..f860f61cd 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -18,7 +18,7 @@ - + From e8ce7c9db383f05d281ed24061dc46f30d704910 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sun, 6 Jun 2021 00:38:50 +0100 Subject: [PATCH 35/61] Fix casts to ICollection --- Benchmarks/ArrayToArrayBenchmarks.md | 31 ++++---- Benchmarks/RangeToArrayBenchmarks.md | 14 ++-- Benchmarks/RepeatToArrayBenchmarks.md | 22 +++--- Benchmarks/SelectToArrayBenchmarks.md | 76 +++++++++---------- Benchmarks/SelectToListBenchmarks.md | 74 +++++++++--------- Benchmarks/ToArrayBenchmarks.md | 70 ++++++++--------- Benchmarks/ToListBenchmarks.md | 72 +++++++++--------- Benchmarks/WhereToArrayBenchmarks.md | 72 +++++++++--------- Benchmarks/WhereToListBenchmarks.md | 52 ++++++------- .../Benchmarks/ArrayToArrayBenchmarks.cs | 11 ++- .../Benchmarks/ToArrayBenchmarks.cs | 12 +++ .../AsValueEnumerable'1.ReadOnlyCollection.cs | 10 ++- .../AsValueEnumerable'1.ReadOnlyList.cs | 2 +- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 6 +- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 6 +- ...lueEnumerable'6.ValueReadOnlyCollection.cs | 8 +- .../AsValueEnumerable'6.ValueReadOnlyList.cs | 9 ++- .../AsValueEnumerable.ArraySegment.cs | 12 +-- .../ToArray/ToArray.ValueEnumerable.cs | 9 +++ .../ToArray.ValueReadOnlyCollection.cs | 13 +++- .../NetFabric.Hyperlinq.csproj | 4 + .../SkipTake/SkipTake.ReadOnlyList.cs | 2 +- .../SkipTake.ValueReadOnlyCollection.cs | 3 +- .../Contains/Contains.Enumerable.cs | 22 +++--- .../Contains/Contains.ValueEnumerable.cs | 11 +-- 25 files changed, 346 insertions(+), 277 deletions(-) diff --git a/Benchmarks/ArrayToArrayBenchmarks.md b/Benchmarks/ArrayToArrayBenchmarks.md index 558de7565..47e6917c6 100644 --- a/Benchmarks/ArrayToArrayBenchmarks.md +++ b/Benchmarks/ArrayToArrayBenchmarks.md @@ -18,21 +18,24 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-ZXXAXW : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|----------------- |------ |-----------:|----------:|----------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| **ArrayClone** | **10** | **83.187 ns** | **0.5856 ns** | **0.5191 ns** | **83.125 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | -| SpanToArray | 10 | 7.938 ns | 0.1489 ns | 0.1320 ns | 7.921 ns | 0.10 | 0.00 | 0.0306 | - | - | 64 B | -| CollectionCopyTo | 10 | 16.725 ns | 0.1057 ns | 0.0989 ns | 16.735 ns | 0.20 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| **ArrayClone** | **100** | **91.920 ns** | **0.4655 ns** | **0.4127 ns** | **91.959 ns** | **1.00** | **0.00** | **0.2021** | **-** | **-** | **424 B** | -| SpanToArray | 100 | 33.381 ns | 0.7700 ns | 2.2702 ns | 32.260 ns | 0.39 | 0.02 | 0.2027 | - | - | 424 B | -| CollectionCopyTo | 100 | 39.932 ns | 0.7754 ns | 0.6874 ns | 39.978 ns | 0.43 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| **ArrayClone** | **1000** | **284.629 ns** | **3.2346 ns** | **2.7010 ns** | **284.130 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | -| SpanToArray | 1000 | 258.078 ns | 1.8823 ns | 1.6686 ns | 258.441 ns | 0.91 | 0.01 | 1.9226 | - | - | 4,024 B | -| CollectionCopyTo | 1000 | 245.347 ns | 3.6884 ns | 3.4501 ns | 244.683 ns | 0.86 | 0.01 | 1.9155 | - | - | 4,024 B | +| Method | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|----------------- |------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| **ArrayClone** | **10** | **131.36 ns** | **7.707 ns** | **22.724 ns** | **134.45 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | +| SpanToArray | 10 | 12.59 ns | 0.804 ns | 2.370 ns | 12.90 ns | 0.10 | 0.02 | 0.0306 | - | - | 64 B | +| SpanCopyTo | 10 | 12.86 ns | 0.750 ns | 2.212 ns | 13.18 ns | 0.10 | 0.03 | 0.0306 | - | - | 64 B | +| CollectionCopyTo | 10 | 19.71 ns | 1.111 ns | 3.276 ns | 19.25 ns | 0.16 | 0.04 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| **ArrayClone** | **100** | **131.39 ns** | **7.409 ns** | **21.846 ns** | **120.03 ns** | **1.00** | **0.00** | **0.2019** | **-** | **-** | **424 B** | +| SpanToArray | 100 | 43.71 ns | 2.028 ns | 5.979 ns | 43.53 ns | 0.34 | 0.07 | 0.2027 | - | - | 424 B | +| SpanCopyTo | 100 | 45.43 ns | 1.786 ns | 5.238 ns | 45.30 ns | 0.35 | 0.06 | 0.2027 | - | - | 424 B | +| CollectionCopyTo | 100 | 52.84 ns | 2.653 ns | 7.822 ns | 48.41 ns | 0.41 | 0.09 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | +| **ArrayClone** | **1000** | **339.56 ns** | **16.058 ns** | **47.348 ns** | **336.98 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | +| SpanToArray | 1000 | 342.84 ns | 12.889 ns | 38.002 ns | 359.05 ns | 1.03 | 0.18 | 1.9226 | - | - | 4,024 B | +| SpanCopyTo | 1000 | 313.68 ns | 13.129 ns | 38.710 ns | 327.16 ns | 0.94 | 0.19 | 1.9155 | - | - | 4,024 B | +| CollectionCopyTo | 1000 | 322.00 ns | 12.162 ns | 35.670 ns | 315.88 ns | 0.97 | 0.17 | 1.9155 | - | - | 4,024 B | diff --git a/Benchmarks/RangeToArrayBenchmarks.md b/Benchmarks/RangeToArrayBenchmarks.md index 5d97b3fda..28fe1aa92 100644 --- a/Benchmarks/RangeToArrayBenchmarks.md +++ b/Benchmarks/RangeToArrayBenchmarks.md @@ -18,17 +18,17 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------ |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 83.82 ns | 1.079 ns | 0.957 ns | 1.00 | 0.00 | 0.2218 | - | - | 464 B | -| StructLinq | Range | 100 | 87.92 ns | 1.112 ns | 1.040 ns | 1.05 | 0.02 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Range | 100 | 44.87 ns | 0.414 ns | 0.388 ns | 0.54 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq | Range | 100 | 45.34 ns | 0.845 ns | 0.791 ns | 0.54 | 0.01 | 0.2027 | - | - | 424 B | +| Linq | Range | 100 | 81.27 ns | 0.932 ns | 1.774 ns | 1.00 | 0.00 | 0.2218 | - | - | 464 B | +| StructLinq | Range | 100 | 85.57 ns | 0.620 ns | 0.580 ns | 1.04 | 0.03 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Range | 100 | 36.20 ns | 0.377 ns | 0.352 ns | 0.44 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq | Range | 100 | 41.93 ns | 0.655 ns | 0.580 ns | 0.51 | 0.02 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 107.52 ns | 1.990 ns | 3.738 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Range_Async | 100 | 159.51 ns | 3.245 ns | 3.737 ns | 1.46 | 0.08 | 0.2027 | - | - | 424 B | +| Linq_Async | Range_Async | 100 | 105.20 ns | 1.541 ns | 1.366 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Range_Async | 100 | 146.42 ns | 1.256 ns | 1.175 ns | 1.39 | 0.02 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/RepeatToArrayBenchmarks.md b/Benchmarks/RepeatToArrayBenchmarks.md index 66d3a2c74..547cd2a89 100644 --- a/Benchmarks/RepeatToArrayBenchmarks.md +++ b/Benchmarks/RepeatToArrayBenchmarks.md @@ -18,18 +18,18 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------- |------ |----------:|---------:|---------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 80.60 ns | 0.607 ns | 0.538 ns | 80.59 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq | Repeat | 100 | 89.59 ns | 0.325 ns | 0.288 ns | 89.70 ns | 1.11 | 0.01 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Repeat | 100 | 30.88 ns | 0.668 ns | 0.686 ns | 30.89 ns | 0.38 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq | Repeat | 100 | 56.78 ns | 0.811 ns | 0.719 ns | 56.77 ns | 0.70 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_SIMD | Repeat | 100 | 39.50 ns | 0.827 ns | 0.849 ns | 39.70 ns | 0.49 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 96.49 ns | 1.982 ns | 4.554 ns | 94.05 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Repeat_Async | 100 | 180.18 ns | 3.646 ns | 4.868 ns | 182.13 ns | 1.84 | 0.08 | 0.2027 | - | - | 424 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------- |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq | Repeat | 100 | 75.53 ns | 0.909 ns | 0.851 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq | Repeat | 100 | 79.08 ns | 0.694 ns | 0.649 ns | 1.05 | 0.02 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Repeat | 100 | 27.64 ns | 0.234 ns | 0.195 ns | 0.37 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq | Repeat | 100 | 53.12 ns | 0.632 ns | 0.528 ns | 0.70 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_SIMD | Repeat | 100 | 37.55 ns | 0.457 ns | 0.405 ns | 0.50 | 0.01 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | +| Linq_Async | Repeat_Async | 100 | 90.23 ns | 0.866 ns | 0.723 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Repeat_Async | 100 | 117.80 ns | 1.777 ns | 1.576 ns | 1.31 | 0.02 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/SelectToArrayBenchmarks.md b/Benchmarks/SelectToArrayBenchmarks.md index 531c4099e..dfe9dc745 100644 --- a/Benchmarks/SelectToArrayBenchmarks.md +++ b/Benchmarks/SelectToArrayBenchmarks.md @@ -18,45 +18,45 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 238.12 ns | 1.606 ns | 1.424 ns | 237.93 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | -| StructLinq_Array | Array | 100 | 228.97 ns | 1.286 ns | 1.203 ns | 228.58 ns | 0.96 | 0.01 | 0.2027 | - | - | 424 B | -| LinqFasterSIMD_Array | Array | 100 | 66.11 ns | 0.824 ns | 0.770 ns | 66.35 ns | 0.28 | 0.00 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 251.01 ns | 1.267 ns | 1.185 ns | 250.89 ns | 1.05 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array_SIMD | Array | 100 | 82.69 ns | 0.862 ns | 0.720 ns | 82.89 ns | 0.35 | 0.00 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,044.51 ns | 4.877 ns | 4.561 ns | 1,044.31 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,097.91 ns | 10.184 ns | 9.028 ns | 1,095.62 ns | 1.05 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 640.70 ns | 4.753 ns | 4.446 ns | 640.70 ns | 0.61 | 0.00 | 0.2022 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,046.33 ns | 4.834 ns | 4.521 ns | 1,046.07 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,112.99 ns | 13.512 ns | 12.639 ns | 1,111.75 ns | 1.06 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 337.75 ns | 2.273 ns | 2.015 ns | 337.25 ns | 0.32 | 0.00 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 489.36 ns | 7.094 ns | 16.156 ns | 482.28 ns | 1.00 | 0.00 | 0.2289 | - | - | 480 B | -| StructLinq_List_Value | List_Value | 100 | 479.61 ns | 9.434 ns | 15.762 ns | 471.26 ns | 0.97 | 0.04 | 0.2022 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 860.85 ns | 3.419 ns | 3.031 ns | 860.22 ns | 1.70 | 0.07 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,878.85 ns | 21.260 ns | 18.847 ns | 7,870.09 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,348.99 ns | 13.204 ns | 12.351 ns | 2,345.72 ns | 0.30 | 0.00 | 0.5646 | - | - | 1,184 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,092.08 ns | 7.737 ns | 6.859 ns | 1,092.57 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,069.71 ns | 4.509 ns | 3.997 ns | 1,069.70 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,113.28 ns | 6.848 ns | 6.406 ns | 1,110.74 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,089.46 ns | 5.675 ns | 5.031 ns | 1,088.57 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,062.92 ns | 7.179 ns | 6.715 ns | 1,060.91 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 802.62 ns | 2.754 ns | 2.441 ns | 802.85 ns | 0.74 | 0.00 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 407.26 ns | 2.298 ns | 2.037 ns | 407.27 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,117.81 ns | 6.631 ns | 6.203 ns | 1,117.31 ns | 2.74 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 830.13 ns | 3.880 ns | 3.440 ns | 830.16 ns | 2.04 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,528.33 ns | 40.727 ns | 36.103 ns | 7,532.99 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,137.39 ns | 8.987 ns | 8.406 ns | 3,138.36 ns | 0.42 | 0.00 | 0.5798 | - | - | 1,216 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 240.17 ns | 1.474 ns | 1.306 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | +| StructLinq_Array | Array | 100 | 228.00 ns | 1.364 ns | 1.276 ns | 0.95 | 0.01 | 0.2027 | - | - | 424 B | +| LinqFasterSIMD_Array | Array | 100 | 63.28 ns | 0.716 ns | 0.635 ns | 0.26 | 0.00 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 250.31 ns | 1.640 ns | 1.370 ns | 1.04 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array_SIMD | Array | 100 | 80.24 ns | 0.918 ns | 0.859 ns | 0.33 | 0.00 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,061.43 ns | 11.789 ns | 9.844 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,056.96 ns | 11.352 ns | 8.863 ns | 1.00 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 601.80 ns | 5.579 ns | 4.659 ns | 0.57 | 0.01 | 0.2022 | - | - | 424 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,093.15 ns | 6.813 ns | 6.373 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,059.03 ns | 8.171 ns | 7.643 ns | 0.97 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 330.50 ns | 1.925 ns | 1.706 ns | 0.30 | 0.00 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 454.75 ns | 2.799 ns | 2.618 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Value | List_Value | 100 | 467.76 ns | 2.420 ns | 2.146 ns | 1.03 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 860.83 ns | 4.320 ns | 4.041 ns | 1.89 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,405.26 ns | 59.048 ns | 46.101 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,357.52 ns | 10.678 ns | 9.988 ns | 0.32 | 0.00 | 0.5646 | - | - | 1,184 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,052.08 ns | 6.421 ns | 6.006 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,066.62 ns | 7.938 ns | 7.425 ns | 1.01 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,069.48 ns | 8.627 ns | 7.648 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,029.58 ns | 6.426 ns | 6.011 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,055.36 ns | 7.970 ns | 7.455 ns | 1.03 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 847.53 ns | 16.213 ns | 15.923 ns | 0.82 | 0.02 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 402.58 ns | 2.603 ns | 2.435 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,058.00 ns | 9.785 ns | 9.153 ns | 2.63 | 0.03 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 835.46 ns | 4.897 ns | 4.341 ns | 2.07 | 0.02 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,655.55 ns | 27.495 ns | 24.373 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,145.23 ns | 10.203 ns | 9.044 ns | 0.41 | 0.00 | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/SelectToListBenchmarks.md b/Benchmarks/SelectToListBenchmarks.md index af4b1c5ed..e2a0dc9d1 100644 --- a/Benchmarks/SelectToListBenchmarks.md +++ b/Benchmarks/SelectToListBenchmarks.md @@ -18,44 +18,44 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|-----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 318.54 ns | 2.104 ns | 1.968 ns | 319.01 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | -| StructLinq_Array | Array | 100 | 274.49 ns | 5.546 ns | 10.552 ns | 268.35 ns | 0.90 | 0.03 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 263.28 ns | 1.527 ns | 1.275 ns | 263.23 ns | 0.83 | 0.01 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array_SIMD | Array | 100 | 94.63 ns | 1.226 ns | 0.958 ns | 94.58 ns | 0.30 | 0.00 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,031.86 ns | 5.098 ns | 4.769 ns | 1,032.46 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,117.67 ns | 19.198 ns | 23.577 ns | 1,130.15 ns | 1.08 | 0.03 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 656.82 ns | 2.735 ns | 2.424 ns | 657.04 ns | 0.64 | 0.00 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,039.83 ns | 4.234 ns | 3.536 ns | 1,039.80 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,073.25 ns | 20.361 ns | 21.786 ns | 1,062.53 ns | 1.04 | 0.02 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 335.40 ns | 1.856 ns | 1.646 ns | 335.36 ns | 0.32 | 0.00 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 491.66 ns | 1.910 ns | 1.787 ns | 491.87 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Value | List_Value | 100 | 433.96 ns | 2.390 ns | 2.119 ns | 433.79 ns | 0.88 | 0.01 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 877.39 ns | 16.359 ns | 14.502 ns | 881.65 ns | 1.79 | 0.03 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,728.30 ns | 25.213 ns | 22.351 ns | 7,721.39 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,401.31 ns | 7.980 ns | 6.663 ns | 2,399.46 ns | 0.31 | 0.00 | 0.5798 | - | - | 1,216 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,032.95 ns | 4.367 ns | 3.871 ns | 1,033.26 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,086.31 ns | 21.295 ns | 23.669 ns | 1,089.19 ns | 1.04 | 0.02 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,162.20 ns | 5.644 ns | 5.279 ns | 1,160.66 ns | 1.13 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,037.77 ns | 4.895 ns | 4.088 ns | 1,037.80 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,071.48 ns | 19.183 ns | 26.892 ns | 1,054.76 ns | 1.05 | 0.03 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 885.80 ns | 17.755 ns | 20.447 ns | 893.39 ns | 0.84 | 0.02 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 514.96 ns | 2.669 ns | 2.496 ns | 515.25 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,068.53 ns | 6.080 ns | 5.687 ns | 1,066.40 ns | 2.08 | 0.02 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 890.36 ns | 2.653 ns | 2.216 ns | 890.99 ns | 1.73 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,740.03 ns | 104.055 ns | 92.242 ns | 7,689.45 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,188.25 ns | 7.847 ns | 6.956 ns | 3,188.34 ns | 0.41 | 0.00 | 0.5951 | - | - | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 301.67 ns | 1.742 ns | 1.629 ns | 301.60 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | +| StructLinq_Array | Array | 100 | 266.28 ns | 2.173 ns | 2.033 ns | 265.63 ns | 0.88 | 0.01 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 263.51 ns | 2.980 ns | 2.642 ns | 262.95 ns | 0.87 | 0.01 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array_SIMD | Array | 100 | 95.55 ns | 1.976 ns | 4.619 ns | 93.11 ns | 0.31 | 0.01 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,100.41 ns | 8.612 ns | 8.056 ns | 1,096.03 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,096.06 ns | 8.405 ns | 7.019 ns | 1,092.46 ns | 1.00 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 629.32 ns | 3.621 ns | 3.210 ns | 628.59 ns | 0.57 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,025.70 ns | 7.358 ns | 7.227 ns | 1,027.30 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,091.53 ns | 7.158 ns | 6.346 ns | 1,090.35 ns | 1.06 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 283.83 ns | 1.818 ns | 1.701 ns | 284.26 ns | 0.28 | 0.00 | 0.2179 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 467.84 ns | 2.783 ns | 2.467 ns | 467.65 ns | 1.00 | 0.00 | 0.2446 | - | - | 512 B | +| StructLinq_List_Value | List_Value | 100 | 410.14 ns | 2.882 ns | 2.407 ns | 410.02 ns | 0.88 | 0.00 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 896.02 ns | 17.827 ns | 28.787 ns | 877.13 ns | 1.97 | 0.05 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,704.94 ns | 78.706 ns | 69.770 ns | 7,691.12 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,479.47 ns | 48.187 ns | 49.484 ns | 2,506.42 ns | 0.32 | 0.01 | 0.5798 | - | - | 1,216 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,148.08 ns | 11.198 ns | 9.926 ns | 1,143.88 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,141.10 ns | 7.857 ns | 7.349 ns | 1,138.74 ns | 0.99 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,136.40 ns | 18.272 ns | 18.764 ns | 1,128.53 ns | 0.99 | 0.02 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,081.12 ns | 14.883 ns | 11.619 ns | 1,076.23 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,096.40 ns | 9.292 ns | 8.237 ns | 1,093.87 ns | 1.01 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 843.01 ns | 6.280 ns | 5.567 ns | 842.28 ns | 0.78 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 511.96 ns | 3.224 ns | 2.858 ns | 511.67 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,100.45 ns | 11.915 ns | 11.145 ns | 1,098.65 ns | 2.15 | 0.03 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 894.44 ns | 17.363 ns | 17.052 ns | 898.46 ns | 1.75 | 0.04 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,508.51 ns | 29.243 ns | 24.419 ns | 7,510.76 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,196.70 ns | 14.145 ns | 12.539 ns | 3,194.85 ns | 0.43 | 0.00 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/ToArrayBenchmarks.md b/Benchmarks/ToArrayBenchmarks.md index de4f83bc9..023d182fb 100644 --- a/Benchmarks/ToArrayBenchmarks.md +++ b/Benchmarks/ToArrayBenchmarks.md @@ -18,41 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-KNWJOT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 59.88 ns | 1.195 ns | 1.227 ns | 60.23 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Array | Array | 100 | 85.69 ns | 1.549 ns | 1.449 ns | 85.96 ns | 1.43 | 0.04 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 38.84 ns | 0.832 ns | 0.925 ns | 38.72 ns | 0.65 | 0.02 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 964.16 ns | 19.141 ns | 22.786 ns | 969.43 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 940.39 ns | 3.655 ns | 3.419 ns | 940.89 ns | 0.98 | 0.03 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 549.45 ns | 2.348 ns | 2.197 ns | 550.01 ns | 0.57 | 0.02 | 0.2022 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 47.70 ns | 0.554 ns | 0.519 ns | 47.74 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 897.71 ns | 7.573 ns | 6.713 ns | 894.91 ns | 18.81 | 0.24 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 284.85 ns | 1.007 ns | 0.942 ns | 284.32 ns | 5.97 | 0.06 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 56.08 ns | 0.551 ns | 0.488 ns | 56.11 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Value | List_Value | 100 | 265.05 ns | 5.273 ns | 7.729 ns | 268.00 ns | 4.65 | 0.17 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 699.93 ns | 3.692 ns | 3.273 ns | 699.75 ns | 12.48 | 0.10 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 903.06 ns | 5.220 ns | 4.627 ns | 901.71 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 888.17 ns | 5.147 ns | 4.814 ns | 887.75 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,038.64 ns | 5.813 ns | 5.153 ns | 1,038.27 ns | 1.15 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 47.91 ns | 0.828 ns | 0.646 ns | 47.94 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 894.16 ns | 2.240 ns | 1.749 ns | 893.90 ns | 18.67 | 0.25 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 757.71 ns | 4.528 ns | 4.014 ns | 757.37 ns | 15.82 | 0.20 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 49.13 ns | 0.740 ns | 0.822 ns | 48.89 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Reference | List_Reference | 100 | 909.31 ns | 17.445 ns | 23.879 ns | 895.84 ns | 18.61 | 0.61 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 714.93 ns | 3.366 ns | 2.984 ns | 713.96 ns | 14.53 | 0.24 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,157.19 ns | 3.927 ns | 3.066 ns | 1,157.21 ns | ? | ? | 0.5646 | - | - | 1,184 B | -| | | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,974.38 ns | 12.564 ns | 11.137 ns | 1,974.81 ns | ? | ? | 0.5798 | - | - | 1,216 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 54.98 ns | 0.593 ns | 0.555 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Array | Array | 100 | 82.93 ns | 0.638 ns | 0.597 ns | 1.51 | 0.02 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 41.51 ns | 0.543 ns | 0.508 ns | 0.76 | 0.01 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 900.42 ns | 4.320 ns | 4.041 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 873.07 ns | 4.048 ns | 3.787 ns | 0.97 | 0.00 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 535.57 ns | 2.829 ns | 2.363 ns | 0.60 | 0.00 | 0.2213 | - | - | 464 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 46.43 ns | 0.376 ns | 0.293 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 878.77 ns | 3.930 ns | 3.282 ns | 18.93 | 0.13 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 121.55 ns | 0.846 ns | 0.791 ns | 2.62 | 0.02 | 0.2217 | - | - | 464 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 47.51 ns | 0.516 ns | 0.483 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Value | List_Value | 100 | 244.13 ns | 1.457 ns | 1.363 ns | 5.14 | 0.06 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 56.86 ns | 0.542 ns | 0.507 ns | 1.20 | 0.02 | 0.2142 | - | - | 448 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,911.13 ns | 12.300 ns | 11.505 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,158.17 ns | 3.619 ns | 3.209 ns | 0.61 | 0.00 | 0.5646 | - | - | 1,184 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 897.96 ns | 7.465 ns | 5.828 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 894.95 ns | 2.909 ns | 2.721 ns | 1.00 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 981.20 ns | 4.904 ns | 4.095 ns | 1.09 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 48.58 ns | 0.550 ns | 0.514 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 898.17 ns | 5.121 ns | 4.276 ns | 18.47 | 0.24 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 54.82 ns | 0.302 ns | 0.252 ns | 1.13 | 0.01 | 0.2142 | - | - | 448 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 47.35 ns | 0.496 ns | 0.464 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Reference | List_Reference | 100 | 870.05 ns | 2.203 ns | 2.060 ns | 18.38 | 0.19 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 56.16 ns | 1.188 ns | 1.220 ns | 1.18 | 0.03 | 0.2142 | - | - | 448 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,940.27 ns | 11.722 ns | 9.151 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,963.74 ns | 10.000 ns | 9.354 ns | 1.01 | 0.01 | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/ToListBenchmarks.md b/Benchmarks/ToListBenchmarks.md index da71d4de1..d46d70202 100644 --- a/Benchmarks/ToListBenchmarks.md +++ b/Benchmarks/ToListBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-GYHESW : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 59.28 ns | 1.254 ns | 1.288 ns | 59.79 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Array | Array | 100 | 92.73 ns | 0.843 ns | 0.747 ns | 92.66 ns | 1.56 | 0.04 | 0.2180 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 49.88 ns | 1.064 ns | 2.629 ns | 48.68 ns | 0.83 | 0.05 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 948.74 ns | 18.850 ns | 36.317 ns | 925.55 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 938.74 ns | 3.250 ns | 2.537 ns | 938.82 ns | 0.98 | 0.03 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 558.80 ns | 11.170 ns | 18.037 ns | 566.01 ns | 0.58 | 0.03 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 54.69 ns | 1.149 ns | 2.732 ns | 53.34 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 943.48 ns | 8.286 ns | 6.919 ns | 940.54 ns | 17.62 | 0.44 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 293.56 ns | 4.750 ns | 6.659 ns | 291.01 ns | 5.25 | 0.33 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 58.06 ns | 1.221 ns | 3.017 ns | 57.68 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Value | List_Value | 100 | 255.44 ns | 1.213 ns | 0.947 ns | 255.64 ns | 4.27 | 0.21 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 744.41 ns | 6.725 ns | 6.291 ns | 743.00 ns | 12.39 | 0.55 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,870.70 ns | 5.179 ns | 4.591 ns | 1,870.29 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,208.58 ns | 6.498 ns | 5.760 ns | 1,208.21 ns | 0.65 | 0.00 | 0.5798 | - | - | 1,216 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 939.71 ns | 18.708 ns | 37.361 ns | 913.84 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 992.53 ns | 7.155 ns | 5.975 ns | 991.79 ns | 1.04 | 0.04 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,009.21 ns | 8.154 ns | 7.627 ns | 1,008.90 ns | 1.05 | 0.04 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 56.80 ns | 1.201 ns | 3.144 ns | 56.97 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 932.65 ns | 7.394 ns | 5.773 ns | 931.02 ns | 16.72 | 0.80 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 706.73 ns | 12.697 ns | 19.004 ns | 716.63 ns | 12.33 | 0.53 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 54.98 ns | 1.086 ns | 0.848 ns | 55.10 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Reference | List_Reference | 100 | 969.38 ns | 14.223 ns | 18.988 ns | 975.80 ns | 17.70 | 0.40 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 743.46 ns | 3.592 ns | 2.999 ns | 743.35 ns | 13.53 | 0.23 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,983.00 ns | 13.421 ns | 12.554 ns | 1,978.37 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,033.51 ns | 12.827 ns | 10.711 ns | 2,028.62 ns | 1.03 | 0.01 | 0.5951 | - | - | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 57.37 ns | 0.391 ns | 0.347 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Array | Array | 100 | 89.36 ns | 0.638 ns | 0.533 ns | 1.56 | 0.01 | 0.2180 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 44.93 ns | 0.294 ns | 0.229 ns | 0.78 | 0.01 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 903.35 ns | 6.611 ns | 6.184 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 911.17 ns | 4.143 ns | 3.673 ns | 1.01 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 587.79 ns | 3.092 ns | 2.741 ns | 0.65 | 0.00 | 0.2365 | - | - | 496 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 51.89 ns | 0.784 ns | 0.733 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 922.14 ns | 7.969 ns | 7.454 ns | 17.78 | 0.32 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 141.96 ns | 0.786 ns | 0.656 ns | 2.73 | 0.04 | 0.2370 | - | - | 496 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 53.18 ns | 0.580 ns | 0.514 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Value | List_Value | 100 | 253.74 ns | 3.019 ns | 2.824 ns | 4.77 | 0.08 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 77.76 ns | 0.632 ns | 0.560 ns | 1.46 | 0.02 | 0.2295 | - | - | 480 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,862.15 ns | 8.393 ns | 7.851 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,210.80 ns | 4.677 ns | 3.906 ns | 0.65 | 0.00 | 0.5798 | - | - | 1,216 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 879.43 ns | 8.114 ns | 6.335 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 921.20 ns | 4.572 ns | 4.277 ns | 1.05 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,036.35 ns | 7.064 ns | 6.262 ns | 1.18 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 52.01 ns | 0.397 ns | 0.331 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 910.52 ns | 3.786 ns | 3.356 ns | 17.50 | 0.12 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 68.43 ns | 0.609 ns | 0.540 ns | 1.32 | 0.01 | 0.2295 | - | - | 480 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 52.21 ns | 0.408 ns | 0.361 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Reference | List_Reference | 100 | 914.68 ns | 6.522 ns | 6.101 ns | 17.53 | 0.15 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 77.22 ns | 1.111 ns | 0.928 ns | 1.48 | 0.02 | 0.2295 | - | - | 480 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,862.73 ns | 9.873 ns | 8.244 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,032.68 ns | 18.738 ns | 17.527 ns | 1.09 | 0.01 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/WhereToArrayBenchmarks.md b/Benchmarks/WhereToArrayBenchmarks.md index fc23b61ab..f23e15b4a 100644 --- a/Benchmarks/WhereToArrayBenchmarks.md +++ b/Benchmarks/WhereToArrayBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 508.9 ns | 23.93 ns | 70.18 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | -| StructLinq_Array | Array | 100 | 420.0 ns | 8.31 ns | 9.89 ns | 0.80 | 0.05 | 0.1144 | - | - | 240 B | -| Hyperlinq_Array | Array | 100 | 483.7 ns | 2.73 ns | 2.56 ns | 0.91 | 0.09 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,360.0 ns | 21.55 ns | 20.16 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,235.3 ns | 3.55 ns | 2.77 ns | 0.91 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 548.7 ns | 3.04 ns | 2.70 ns | 0.40 | 0.01 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,295.6 ns | 6.24 ns | 5.21 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,218.2 ns | 6.60 ns | 5.85 ns | 0.94 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 569.5 ns | 3.02 ns | 2.68 ns | 0.44 | 0.00 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,294.1 ns | 4.14 ns | 3.46 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Value | List_Value | 100 | 824.5 ns | 5.59 ns | 5.23 ns | 0.64 | 0.00 | 0.1144 | - | - | 240 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,307.7 ns | 6.50 ns | 6.08 ns | 1.01 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,111.2 ns | 34.86 ns | 30.90 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,868.6 ns | 13.02 ns | 10.87 ns | 0.56 | 0.00 | 0.3433 | - | - | 720 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,264.1 ns | 10.27 ns | 9.61 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,212.4 ns | 5.85 ns | 5.19 ns | 0.96 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,308.1 ns | 7.94 ns | 7.04 ns | 1.04 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,284.0 ns | 9.48 ns | 8.87 ns | 1.00 | 0.00 | 0.3681 | - | - | 776 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,217.6 ns | 6.08 ns | 5.08 ns | 0.95 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,292.9 ns | 5.11 ns | 4.53 ns | 1.01 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,287.8 ns | 8.44 ns | 7.48 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,268.3 ns | 4.33 ns | 3.84 ns | 0.98 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,400.0 ns | 14.89 ns | 13.20 ns | 1.09 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,972.6 ns | 62.02 ns | 54.98 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,526.4 ns | 39.59 ns | 37.04 ns | 0.71 | 0.01 | 0.3548 | - | - | 752 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 422.3 ns | 2.77 ns | 3.70 ns | 1.00 | 0.3519 | - | - | 736 B | +| StructLinq_Array | Array | 100 | 383.3 ns | 4.13 ns | 3.22 ns | 0.91 | 0.1144 | - | - | 240 B | +| Hyperlinq_Array | Array | 100 | 491.6 ns | 3.63 ns | 3.22 ns | 1.16 | 0.1144 | - | - | 240 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,199.4 ns | 6.52 ns | 6.10 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,186.0 ns | 9.77 ns | 9.14 ns | 0.99 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 537.9 ns | 4.76 ns | 4.22 ns | 0.45 | 0.1144 | - | - | 240 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,298.6 ns | 9.64 ns | 8.54 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,170.7 ns | 6.78 ns | 6.34 ns | 0.90 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 515.4 ns | 5.29 ns | 4.69 ns | 0.40 | 0.1144 | - | - | 240 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,213.6 ns | 8.77 ns | 7.32 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Value | List_Value | 100 | 780.8 ns | 3.00 ns | 2.66 ns | 0.64 | 0.1144 | - | - | 240 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,329.0 ns | 7.30 ns | 6.83 ns | 1.09 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,221.4 ns | 22.19 ns | 20.76 ns | 1.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,840.5 ns | 13.40 ns | 12.54 ns | 0.54 | 0.3357 | - | - | 720 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,233.9 ns | 13.13 ns | 11.64 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,206.8 ns | 8.06 ns | 7.54 ns | 0.98 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,302.2 ns | 6.70 ns | 5.94 ns | 1.06 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,217.6 ns | 9.87 ns | 8.25 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,277.6 ns | 7.94 ns | 7.42 ns | 1.05 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,246.8 ns | 9.89 ns | 8.77 ns | 1.02 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,284.5 ns | 11.96 ns | 11.19 ns | 1.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,205.9 ns | 9.25 ns | 8.20 ns | 0.94 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,336.7 ns | 8.06 ns | 7.54 ns | 1.04 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,142.1 ns | 42.67 ns | 39.91 ns | 1.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,482.6 ns | 11.37 ns | 10.08 ns | 0.68 | 0.3548 | - | - | 752 B | diff --git a/Benchmarks/WhereToListBenchmarks.md b/Benchmarks/WhereToListBenchmarks.md index f13a0ca13..9deaeb555 100644 --- a/Benchmarks/WhereToListBenchmarks.md +++ b/Benchmarks/WhereToListBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 395.9 ns | 1.46 ns | 2.23 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | -| StructLinq_Array | Array | 100 | 427.0 ns | 2.38 ns | 2.11 ns | 1.08 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Array | Array | 100 | 487.7 ns | 2.52 ns | 2.24 ns | 1.23 | 0.01 | 0.1297 | - | - | 272 B | +| Linq_Array | Array | 100 | 357.3 ns | 2.79 ns | 2.61 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | +| StructLinq_Array | Array | 100 | 416.0 ns | 3.34 ns | 2.96 ns | 1.16 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Array | Array | 100 | 495.6 ns | 3.58 ns | 3.34 ns | 1.39 | 0.02 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,188.2 ns | 5.73 ns | 5.36 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,223.5 ns | 15.17 ns | 22.71 ns | 1.03 | 0.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 552.2 ns | 9.09 ns | 8.06 ns | 0.46 | 0.01 | 0.1297 | - | - | 272 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,164.2 ns | 7.83 ns | 6.94 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,210.6 ns | 7.88 ns | 7.37 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 562.4 ns | 4.80 ns | 4.49 ns | 0.48 | 0.01 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,130.1 ns | 5.41 ns | 4.79 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,232.5 ns | 7.81 ns | 7.31 ns | 1.09 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 580.9 ns | 10.97 ns | 10.26 ns | 0.51 | 0.01 | 0.1297 | - | - | 272 B | +| Linq_Collection_Value | Collection_Value | 100 | 1,167.3 ns | 9.75 ns | 9.12 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,211.0 ns | 7.99 ns | 7.47 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 533.1 ns | 5.77 ns | 4.81 ns | 0.46 | 0.01 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,135.3 ns | 5.03 ns | 4.20 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Value | List_Value | 100 | 819.8 ns | 3.41 ns | 2.84 ns | 0.72 | 0.00 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,375.5 ns | 8.27 ns | 7.33 ns | 1.21 | 0.01 | 0.1450 | - | - | 304 B | +| Linq_List_Value | List_Value | 100 | 1,162.8 ns | 10.44 ns | 9.77 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Value | List_Value | 100 | 796.9 ns | 4.09 ns | 3.83 ns | 0.69 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,372.0 ns | 9.32 ns | 8.27 ns | 1.18 | 0.01 | 0.1450 | - | - | 304 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,116.5 ns | 21.33 ns | 19.95 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,956.4 ns | 44.63 ns | 41.75 ns | 0.58 | 0.01 | 0.3586 | - | - | 752 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,113.3 ns | 21.94 ns | 20.52 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,916.5 ns | 13.42 ns | 11.89 ns | 0.57 | 0.00 | 0.3586 | - | - | 752 B | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,201.5 ns | 8.47 ns | 7.08 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,200.7 ns | 4.88 ns | 4.33 ns | 1.00 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,297.9 ns | 20.30 ns | 19.94 ns | 1.08 | 0.02 | 0.1450 | - | - | 304 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,144.9 ns | 9.20 ns | 8.61 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,194.5 ns | 7.04 ns | 6.59 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,360.4 ns | 6.28 ns | 5.87 ns | 1.19 | 0.01 | 0.1450 | - | - | 304 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,165.1 ns | 3.84 ns | 3.60 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,221.9 ns | 21.50 ns | 20.11 ns | 1.05 | 0.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,366.8 ns | 3.97 ns | 3.52 ns | 1.17 | 0.00 | 0.1450 | - | - | 304 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,165.1 ns | 5.31 ns | 4.44 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,228.7 ns | 24.06 ns | 21.33 ns | 1.06 | 0.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,325.4 ns | 9.43 ns | 8.36 ns | 1.14 | 0.01 | 0.1450 | - | - | 304 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,137.7 ns | 7.08 ns | 6.62 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,241.5 ns | 22.59 ns | 17.63 ns | 1.09 | 0.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,363.4 ns | 4.61 ns | 3.60 ns | 1.20 | 0.01 | 0.1450 | - | - | 304 B | +| Linq_List_Reference | List_Reference | 100 | 1,163.3 ns | 10.51 ns | 8.20 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,188.0 ns | 8.48 ns | 7.94 ns | 1.02 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,377.3 ns | 6.38 ns | 5.33 ns | 1.18 | 0.01 | 0.1450 | - | - | 304 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,112.7 ns | 20.47 ns | 18.14 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,583.1 ns | 45.80 ns | 42.84 ns | 0.70 | 0.01 | 0.3738 | - | - | 784 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,962.1 ns | 25.57 ns | 23.92 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,583.2 ns | 11.66 ns | 10.34 ns | 0.72 | 0.00 | 0.3738 | - | - | 784 B | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs index 5cc87c188..5182ff7db 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs @@ -1,5 +1,6 @@ using BenchmarkDotNet.Attributes; using System; +using System.Collections.Generic; namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks { @@ -23,11 +24,19 @@ public int[] ArrayClone() public int[] SpanToArray() => array.AsSpan().ToArray(); + [Benchmark] + public int[] SpanCopyTo() + { + var result = GC.AllocateUninitializedArray(Count); + array.AsSpan().CopyTo(result); + return result; + } + [Benchmark] public int[] CollectionCopyTo() { var result = GC.AllocateUninitializedArray(Count); - ((System.Collections.ICollection)array!).CopyTo(result, 0); + ((ICollection)array!).CopyTo(result, 0); return result; } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs index e7301dc04..b25edc3b4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs @@ -30,6 +30,12 @@ public int[] Linq_Collection_Value() public int[] Linq_List_Value() => listValue.ToArray(); + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Value() + => asyncEnumerableValue + .ToArrayAsync(); + [BenchmarkCategory("Enumerable_Reference")] [Benchmark(Baseline = true)] public int[] Linq_Enumerable_Reference() @@ -45,6 +51,12 @@ public int[] Linq_Collection_Reference() public int[] Linq_List_Reference() => listReference.ToArray(); + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public ValueTask Linq_AsyncEnumerable_Reference() + => asyncEnumerableReference + .ToArrayAsync(); + // --------------------------------------------------------------------- [BenchmarkCategory("Array")] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index f9e4f945a..ae372e243 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -51,7 +51,7 @@ public void CopyTo(Span span) using var enumerator = GetEnumerator(); checked { - for (var index = 0; enumerator.MoveNext(); index++) + for (var index = 0; enumerator.MoveNext() && index < span.Length; index++) span[index] = enumerator.Current; } } @@ -61,7 +61,7 @@ public void CopyTo(TSource[] array, int arrayIndex) { switch (source) { - case ICollection collection: + case ICollection collection: collection.CopyTo(array, arrayIndex); break; default: @@ -72,7 +72,11 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - => Count is not 0 && source.Contains(item); + => source switch + { + ICollection collection => collection.Contains(item), + _ => Count is not 0 && source.Contains(item), + }; [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs index fffaa7c49..f5dec170c 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs @@ -82,7 +82,7 @@ public void CopyTo(TSource[] array, int arrayIndex) { switch (source) { - case ICollection collection: + case ICollection collection: collection.CopyTo(array, arrayIndex); break; default: diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index a8a384767..6c4c72d8f 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -68,7 +68,11 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - => Count is not 0 && source.Contains(item); + => source switch + { + ICollection collection => collection.Contains(item), + _ => Count is not 0 && source.Contains(item), + }; [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index 84a0f3439..d9f9e8848 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -103,7 +103,11 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - => Count is not 0 && EnumerableExtensions.Contains(source, item); + => source switch + { + ICollection collection => collection.Contains(item), + _ => Count is not 0 && source.Contains(item), + }; [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index eb029adc3..e8bc1433e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -101,7 +101,7 @@ public void CopyTo(TSource[] array, int arrayIndex) { switch (source) { - case ICollection collection: + case ICollection collection: collection.CopyTo(array, arrayIndex); break; default: @@ -112,7 +112,11 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - => Count is not 0 && EnumerableExtensions.Contains(source, item); + => source switch + { + ICollection collection => collection.Contains(item), + _ => Count is not 0 && source.Contains(item), + }; [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs index 59f909aa8..658ac133a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs @@ -113,8 +113,7 @@ public void CopyTo(TSource[] array, int arrayIndex) { switch (source) { - // ReSharper disable once SuspiciousTypeConversion.Global - case ICollection collection: + case ICollection collection: collection.CopyTo(array, arrayIndex); break; default: @@ -125,7 +124,11 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Contains(TSource item) - => Count is not 0 && EnumerableExtensions.Contains(source, item); + => source switch + { + ICollection collection => collection.Contains(item), + _ => Count is not 0 && source.Contains(item), + }; public readonly int IndexOf(TSource item) { diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index 5c827f0f9..e619cecb2 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -78,19 +78,15 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => Copy(source, array.AsSpan().Slice(arrayIndex)); + => ((ICollection)source).CopyTo(array, arrayIndex); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - => source.Count switch - { - 0 => false, - _ => Array.IndexOf(source.Array!, item, source.Offset, source.Count) >= 0 - }; + => ((ICollection)source).Contains(item); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int IndexOf(TSource item) - => ArrayExtensions.IndexOf(source.AsSpan(), item); + => ((IList)source).IndexOf(item); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -161,7 +157,7 @@ public ArraySegment AsEnumerable() [MethodImpl(MethodImplOptions.AggressiveInlining)] public TSource[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArray(); + => source.AsSpan().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index 2fa65963a..14544f098 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -14,10 +14,19 @@ public static TSource[] ToArray(this TEnumera { return source switch { + ICollection collection => BuildArrayFromCollectionOfTSource(collection), + // ReSharper disable once SuspiciousTypeConversion.Global ICollection collection => BuildArrayFromCollection(collection), _ => BuildArray(source) }; + static TSource[] BuildArrayFromCollectionOfTSource(ICollection collection) + { + var result = Utils.AllocateUninitializedArray(collection.Count); + collection.CopyTo(result, 0); + return result; + } + static TSource[] BuildArrayFromCollection(ICollection collection) { var result = Utils.AllocateUninitializedArray(collection.Count); diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index f9891b6f6..8378eadd4 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -18,13 +18,24 @@ public static TSource[] ToArray(this TEnumera { { Count: 0 } => Array.Empty(), + // ReSharper disable once HeapView.PossibleBoxingAllocation + // ReSharper disable once SuspiciousTypeConversion.Global + ICollection collection => BuildArrayFromCollectionOfTSource(collection), + // ReSharper disable once HeapView.PossibleBoxingAllocation // ReSharper disable once SuspiciousTypeConversion.Global ICollection collection => BuildArrayFromCollection(collection), - + _ => BuildArray(source) }; + static TSource[] BuildArrayFromCollectionOfTSource(ICollection collection) + { + var result = Utils.AllocateUninitializedArray(collection.Count); + collection.CopyTo(result, 0); + return result; + } + static TSource[] BuildArrayFromCollection(ICollection collection) { var result = Utils.AllocateUninitializedArray(collection.Count); diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 0dfb8a746..fc28e5aa2 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -85,4 +85,8 @@ + + + + diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs index 6c5d6b827..53a7097dc 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs @@ -90,7 +90,7 @@ public void CopyTo(TSource[] array, int arrayIndex) return; // ReSharper disable once HeapView.PossibleBoxingAllocation - if (offset is 0 && Count == source.Count && source is ICollection collection) + if (offset is 0 && Count == source.Count && source is ICollection collection) collection.CopyTo(array, arrayIndex); else CopyTo(array.AsSpan().Slice(arrayIndex)); diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs index c3cb77eb2..94012f107 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs @@ -74,7 +74,8 @@ public void CopyTo(TSource[] array, int arrayIndex) if (Count is 0) return; - if (offset is 0 && Count == source.Count && source is ICollection collection) + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (offset is 0 && Count == source.Count && source is ICollection collection) collection.CopyTo(array, arrayIndex); else CopyTo(array.AsSpan().Slice(arrayIndex)); diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs index f2b1df490..87cbe3e94 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs @@ -10,11 +10,12 @@ internal static bool Contains(this TEnumerable source, TSo { if (Utils.UseDefault(comparer)) { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - return collection.Contains(value); - - return DefaultContains(source, value); + return source switch + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + ICollection collection => collection.Contains(value), + _ => DefaultContains(source, value), + }; } return ComparerContains(source, value, comparer); @@ -51,11 +52,12 @@ internal static bool Contains collection) - return collection.Contains(value); - - return DefaultContains(source, value, getEnumerator); + return source switch + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + ICollection collection => collection.Contains(value), + _ => DefaultContains(source, value, getEnumerator), + }; } return ComparerContains(source, value, comparer, getEnumerator); diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs index 991ef2274..24ee9d08b 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -10,11 +10,12 @@ public static bool Contains(this TEnumerable { if (Utils.UseDefault(comparer)) { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - return collection.Contains(value); - - return DefaultContains(source, value); + return source switch + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + ICollection collection => collection.Contains(value), + _ => DefaultContains(source, value), + }; } return ComparerContains(source, value, comparer); From d5eb3738d6d0c28b3e162225a48eb976fe9aaaf7 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sun, 6 Jun 2021 21:48:24 +0100 Subject: [PATCH 36/61] Update benchmark results --- Benchmarks/AggressiveInliningBenchmarks.md | 6 +- Benchmarks/AllBenchmarks.md | 58 +++++++-------- Benchmarks/AnyBenchmarks.md | 58 +++++++-------- Benchmarks/AnyPredicateBenchmarks.md | 58 +++++++-------- Benchmarks/ArrayIterationBenchmarks.md | 18 ++--- Benchmarks/ArrayToArrayBenchmarks.md | 34 ++++----- Benchmarks/ContainsBenchmarks.md | 40 +++++----- Benchmarks/ContainsComparerBenchmarks.md | 38 +++++----- Benchmarks/CountBenchmarks.md | 52 ++++++------- Benchmarks/DistinctBenchmarks.md | 76 +++++++++---------- Benchmarks/ElementAtBenchmarks.md | 38 +++++----- Benchmarks/EmptyBenchmarks.md | 10 +-- Benchmarks/FirstBenchmarks.md | 38 +++++----- Benchmarks/ListIterationBenchmarks.md | 18 ++--- Benchmarks/RangeBenchmarks.md | 18 ++--- Benchmarks/RangeToArrayBenchmarks.md | 20 ++--- Benchmarks/ReadOnlyFieldsBenchmarks.md | 8 +- Benchmarks/RepeatBenchmarks.md | 12 +-- Benchmarks/RepeatToArrayBenchmarks.md | 22 +++--- Benchmarks/ReturnBenchmarks.md | 10 +-- Benchmarks/SelectBenchmarks.md | 62 ++++++++-------- Benchmarks/SelectCountBenchmarks.md | 72 +++++++++--------- Benchmarks/SelectManyBenchmarks.md | 36 ++++----- Benchmarks/SelectSumBenchmarks.md | 54 +++++++------- Benchmarks/SelectToArrayBenchmarks.md | 76 +++++++++---------- Benchmarks/SelectToListBenchmarks.md | 74 +++++++++---------- Benchmarks/SingleBenchmarks.md | 34 ++++----- Benchmarks/SkipTakeBenchmarks.md | 86 +++++++++++----------- Benchmarks/SumBenchmarks.md | 74 +++++++++---------- Benchmarks/ToArrayBenchmarks.md | 72 +++++++++--------- Benchmarks/ToListBenchmarks.md | 72 +++++++++--------- Benchmarks/WhereBenchmarks.md | 76 +++++++++---------- Benchmarks/WhereCountBenchmarks.md | 76 +++++++++---------- Benchmarks/WhereFirstBenchmarks.md | 58 +++++++-------- Benchmarks/WhereSelectBenchmarks.md | 56 +++++++------- Benchmarks/WhereSelectCountBenchmarks.md | 38 +++++----- Benchmarks/WhereSingleBenchmarks.md | 54 +++++++------- Benchmarks/WhereToArrayBenchmarks.md | 72 +++++++++--------- Benchmarks/WhereToListBenchmarks.md | 72 +++++++++--------- 39 files changed, 923 insertions(+), 923 deletions(-) diff --git a/Benchmarks/AggressiveInliningBenchmarks.md b/Benchmarks/AggressiveInliningBenchmarks.md index 300f8a9cc..2da4e3e00 100644 --- a/Benchmarks/AggressiveInliningBenchmarks.md +++ b/Benchmarks/AggressiveInliningBenchmarks.md @@ -18,12 +18,12 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------- |------ |---------:|--------:|--------:|------:|------:|------:|------:|----------:| -| Baseline | 1000 | 544.3 ns | 0.85 ns | 0.67 ns | 1.00 | - | - | - | - | -| AggressiveInlining | 1000 | 544.4 ns | 1.39 ns | 1.23 ns | 1.00 | - | - | - | - | +| Baseline | 1000 | 544.6 ns | 1.40 ns | 1.31 ns | 1.00 | - | - | - | - | +| AggressiveInlining | 1000 | 544.5 ns | 1.31 ns | 1.22 ns | 1.00 | - | - | - | - | diff --git a/Benchmarks/AllBenchmarks.md b/Benchmarks/AllBenchmarks.md index afb4834e0..7bf8b624b 100644 --- a/Benchmarks/AllBenchmarks.md +++ b/Benchmarks/AllBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 591.1 ns | 11.49 ns | 10.18 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 192.5 ns | 0.77 ns | 0.60 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 770.8 ns | 2.82 ns | 2.64 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 253.3 ns | 2.04 ns | 1.81 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 721.0 ns | 3.54 ns | 3.14 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 254.7 ns | 0.98 ns | 0.87 ns | 0.35 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 752.7 ns | 12.49 ns | 9.75 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 777.2 ns | 5.69 ns | 4.44 ns | 1.03 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,709.2 ns | 3.68 ns | 3.45 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 251.1 ns | 0.52 ns | 0.46 ns | 0.15 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 721.5 ns | 3.10 ns | 2.90 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 751.9 ns | 3.21 ns | 2.84 ns | 1.04 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 769.8 ns | 2.26 ns | 2.11 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 789.2 ns | 7.33 ns | 6.12 ns | 1.03 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 775.5 ns | 6.94 ns | 6.15 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 729.0 ns | 2.96 ns | 2.77 ns | 0.94 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,709.5 ns | 4.61 ns | 3.85 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 278.8 ns | 0.94 ns | 0.88 ns | 0.16 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 572.2 ns | 1.87 ns | 1.75 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 192.5 ns | 0.42 ns | 0.32 ns | 0.34 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 747.7 ns | 3.46 ns | 3.23 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 251.7 ns | 2.46 ns | 2.06 ns | 0.34 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 718.6 ns | 2.04 ns | 1.70 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 227.8 ns | 1.26 ns | 0.98 ns | 0.32 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 748.4 ns | 2.83 ns | 2.65 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 800.2 ns | 3.46 ns | 3.06 ns | 1.07 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,704.2 ns | 4.02 ns | 3.76 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 246.4 ns | 0.99 ns | 0.93 ns | 0.14 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 796.2 ns | 4.19 ns | 3.27 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 752.0 ns | 3.58 ns | 2.80 ns | 0.94 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 769.8 ns | 2.45 ns | 2.29 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 777.8 ns | 2.36 ns | 2.21 ns | 1.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 768.8 ns | 2.81 ns | 2.63 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 727.3 ns | 2.27 ns | 1.89 ns | 0.95 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,706.0 ns | 6.93 ns | 5.79 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 278.3 ns | 4.39 ns | 3.43 ns | 0.16 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyBenchmarks.md b/Benchmarks/AnyBenchmarks.md index 6e6d7f9a6..0222a8faa 100644 --- a/Benchmarks/AnyBenchmarks.md +++ b/Benchmarks/AnyBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 8.436 ns | 0.1408 ns | 0.1176 ns | 8.406 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 7.380 ns | 0.0238 ns | 0.0223 ns | 7.380 ns | 0.88 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 22.024 ns | 0.1236 ns | 0.1156 ns | 22.052 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 10.720 ns | 0.0205 ns | 0.0181 ns | 10.720 ns | 0.49 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.119 ns | 0.0185 ns | 0.0173 ns | 4.116 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.241 ns | 0.0261 ns | 0.0245 ns | 8.247 ns | 2.00 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.525 ns | 0.0291 ns | 0.0258 ns | 5.520 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.823 ns | 0.0178 ns | 0.0158 ns | 1.820 ns | 0.33 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 56.994 ns | 0.1735 ns | 0.1623 ns | 57.011 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 50.052 ns | 0.2120 ns | 0.1983 ns | 49.988 ns | 0.88 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 20.335 ns | 0.2451 ns | 0.1914 ns | 20.339 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 13.766 ns | 0.0889 ns | 0.0788 ns | 13.778 ns | 0.68 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.552 ns | 0.0522 ns | 0.0463 ns | 4.535 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.825 ns | 0.0144 ns | 0.0135 ns | 1.830 ns | 0.40 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.502 ns | 0.0440 ns | 0.0343 ns | 5.515 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.567 ns | 0.0071 ns | 0.0063 ns | 1.568 ns | 0.28 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 58.054 ns | 0.6036 ns | 0.5646 ns | 57.922 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 55.955 ns | 1.1523 ns | 1.4983 ns | 56.983 ns | 0.95 | 0.02 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 9.590 ns | 0.0432 ns | 0.0404 ns | 1.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.353 ns | 0.0171 ns | 0.0151 ns | 0.77 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 21.520 ns | 0.0869 ns | 0.0770 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 10.790 ns | 0.0148 ns | 0.0131 ns | 0.50 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 4.489 ns | 0.0273 ns | 0.0242 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.174 ns | 0.0188 ns | 0.0157 ns | 1.82 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 5.502 ns | 0.0280 ns | 0.0262 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.805 ns | 0.0116 ns | 0.0109 ns | 0.33 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 57.348 ns | 0.1576 ns | 0.1231 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 49.700 ns | 0.1463 ns | 0.1368 ns | 0.87 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 20.285 ns | 0.1133 ns | 0.1060 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 13.271 ns | 0.0641 ns | 0.0600 ns | 0.65 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.150 ns | 0.0274 ns | 0.0256 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.805 ns | 0.0103 ns | 0.0086 ns | 0.44 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 5.473 ns | 0.0289 ns | 0.0241 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.554 ns | 0.0097 ns | 0.0076 ns | 0.28 | - | - | - | - | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 56.307 ns | 0.1674 ns | 0.1398 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 53.848 ns | 0.1764 ns | 0.1650 ns | 0.96 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyPredicateBenchmarks.md b/Benchmarks/AnyPredicateBenchmarks.md index 201bbbd87..737fce954 100644 --- a/Benchmarks/AnyPredicateBenchmarks.md +++ b/Benchmarks/AnyPredicateBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 543.31 ns | 2.697 ns | 2.522 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 168.72 ns | 0.710 ns | 0.630 ns | 0.31 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 786.29 ns | 5.005 ns | 4.437 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 252.75 ns | 1.126 ns | 1.053 ns | 0.32 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 781.50 ns | 5.224 ns | 4.362 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 255.94 ns | 1.076 ns | 1.006 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 781.62 ns | 6.332 ns | 5.287 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 782.55 ns | 2.793 ns | 2.476 ns | 1.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,715.16 ns | 3.292 ns | 2.918 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 76.40 ns | 0.203 ns | 0.180 ns | 0.04 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 782.33 ns | 5.113 ns | 4.270 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 739.43 ns | 3.734 ns | 3.310 ns | 0.95 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 732.78 ns | 3.178 ns | 2.654 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 781.34 ns | 2.436 ns | 2.159 ns | 1.07 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 734.11 ns | 2.595 ns | 2.300 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 740.49 ns | 3.347 ns | 2.967 ns | 1.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,716.97 ns | 4.259 ns | 3.776 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 77.91 ns | 0.321 ns | 0.284 ns | 0.05 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 537.58 ns | 3.047 ns | 2.701 ns | 537.74 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 166.76 ns | 0.534 ns | 0.499 ns | 166.71 ns | 0.31 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 767.35 ns | 2.732 ns | 2.422 ns | 766.53 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 249.94 ns | 0.932 ns | 0.827 ns | 249.91 ns | 0.33 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 792.83 ns | 2.970 ns | 2.480 ns | 792.78 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 227.64 ns | 0.582 ns | 0.545 ns | 227.63 ns | 0.29 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 763.82 ns | 1.738 ns | 1.541 ns | 763.47 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 779.76 ns | 3.727 ns | 3.112 ns | 779.99 ns | 1.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,702.31 ns | 2.336 ns | 2.185 ns | 1,702.68 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 73.88 ns | 0.269 ns | 0.225 ns | 73.90 ns | 0.04 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 725.40 ns | 1.927 ns | 1.708 ns | 725.53 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 723.70 ns | 2.657 ns | 2.356 ns | 723.45 ns | 1.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 724.58 ns | 2.336 ns | 2.186 ns | 724.67 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 781.68 ns | 2.340 ns | 1.954 ns | 781.48 ns | 1.08 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 749.57 ns | 2.836 ns | 2.653 ns | 749.41 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 735.02 ns | 5.117 ns | 4.536 ns | 733.78 ns | 0.98 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,744.06 ns | 34.593 ns | 63.255 ns | 1,711.18 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 76.47 ns | 0.218 ns | 0.204 ns | 76.39 ns | 0.04 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 082855f4b..ce82d807b 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -18,18 +18,18 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |----------------------------- |-------- |-----------:|---------:|---------:|-----------:|------:|--------:|------:|------:|------:|----------:| -| Foreach | 1000000 | 450.5 μs | 12.65 μs | 37.29 μs | 424.6 μs | 1.00 | 0.00 | - | - | - | - | -| For | 1000000 | 418.6 μs | 2.47 μs | 1.93 μs | 418.4 μs | 0.86 | 0.05 | - | - | - | - | -| For_Unsafe | 1000000 | 498.8 μs | 4.77 μs | 4.46 μs | 496.8 μs | 1.02 | 0.06 | - | - | - | - | -| Span | 1000000 | 421.8 μs | 2.60 μs | 2.43 μs | 421.8 μs | 0.86 | 0.05 | - | - | - | - | -| ArraySegment_Foreach | 1000000 | 2,816.0 μs | 5.71 μs | 5.06 μs | 2,816.0 μs | 5.78 | 0.30 | - | - | - | 1 B | -| ArraySegment_For | 1000000 | 815.9 μs | 2.95 μs | 5.47 μs | 814.6 μs | 1.81 | 0.15 | - | - | - | - | -| ArraySegment_Expanded_For | 1000000 | 1,327.3 μs | 5.61 μs | 4.98 μs | 1,328.7 μs | 2.72 | 0.14 | - | - | - | - | -| ArraySegment_Wrapper_Foreach | 1000000 | 1,577.4 μs | 5.57 μs | 5.21 μs | 1,577.6 μs | 3.23 | 0.16 | - | - | - | - | +| Foreach | 1000000 | 452.0 μs | 12.83 μs | 37.83 μs | 424.2 μs | 1.00 | 0.00 | - | - | - | - | +| For | 1000000 | 418.5 μs | 1.42 μs | 1.19 μs | 418.3 μs | 0.87 | 0.05 | - | - | - | - | +| For_Unsafe | 1000000 | 452.8 μs | 13.08 μs | 38.57 μs | 424.4 μs | 1.01 | 0.12 | - | - | - | - | +| Span | 1000000 | 420.1 μs | 1.63 μs | 1.36 μs | 420.3 μs | 0.87 | 0.05 | - | - | - | - | +| ArraySegment_Foreach | 1000000 | 2,936.3 μs | 36.57 μs | 34.21 μs | 2,947.8 μs | 6.07 | 0.30 | - | - | - | 1 B | +| ArraySegment_For | 1000000 | 812.7 μs | 2.33 μs | 1.95 μs | 812.6 μs | 1.69 | 0.09 | - | - | - | - | +| ArraySegment_Expanded_For | 1000000 | 1,394.2 μs | 27.67 μs | 46.99 μs | 1,424.1 μs | 3.03 | 0.31 | - | - | - | - | +| ArraySegment_Wrapper_Foreach | 1000000 | 1,466.8 μs | 5.61 μs | 4.98 μs | 1,466.3 μs | 3.04 | 0.15 | - | - | - | - | diff --git a/Benchmarks/ArrayToArrayBenchmarks.md b/Benchmarks/ArrayToArrayBenchmarks.md index 47e6917c6..5d56b6085 100644 --- a/Benchmarks/ArrayToArrayBenchmarks.md +++ b/Benchmarks/ArrayToArrayBenchmarks.md @@ -18,24 +18,24 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-ZXXAXW : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|----------------- |------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| **ArrayClone** | **10** | **131.36 ns** | **7.707 ns** | **22.724 ns** | **134.45 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | -| SpanToArray | 10 | 12.59 ns | 0.804 ns | 2.370 ns | 12.90 ns | 0.10 | 0.02 | 0.0306 | - | - | 64 B | -| SpanCopyTo | 10 | 12.86 ns | 0.750 ns | 2.212 ns | 13.18 ns | 0.10 | 0.03 | 0.0306 | - | - | 64 B | -| CollectionCopyTo | 10 | 19.71 ns | 1.111 ns | 3.276 ns | 19.25 ns | 0.16 | 0.04 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| **ArrayClone** | **100** | **131.39 ns** | **7.409 ns** | **21.846 ns** | **120.03 ns** | **1.00** | **0.00** | **0.2019** | **-** | **-** | **424 B** | -| SpanToArray | 100 | 43.71 ns | 2.028 ns | 5.979 ns | 43.53 ns | 0.34 | 0.07 | 0.2027 | - | - | 424 B | -| SpanCopyTo | 100 | 45.43 ns | 1.786 ns | 5.238 ns | 45.30 ns | 0.35 | 0.06 | 0.2027 | - | - | 424 B | -| CollectionCopyTo | 100 | 52.84 ns | 2.653 ns | 7.822 ns | 48.41 ns | 0.41 | 0.09 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| **ArrayClone** | **1000** | **339.56 ns** | **16.058 ns** | **47.348 ns** | **336.98 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | -| SpanToArray | 1000 | 342.84 ns | 12.889 ns | 38.002 ns | 359.05 ns | 1.03 | 0.18 | 1.9226 | - | - | 4,024 B | -| SpanCopyTo | 1000 | 313.68 ns | 13.129 ns | 38.710 ns | 327.16 ns | 0.94 | 0.19 | 1.9155 | - | - | 4,024 B | -| CollectionCopyTo | 1000 | 322.00 ns | 12.162 ns | 35.670 ns | 315.88 ns | 0.97 | 0.17 | 1.9155 | - | - | 4,024 B | +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|----------------- |------ |-----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| **ArrayClone** | **10** | **82.746 ns** | **0.8458 ns** | **0.7912 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | +| SpanToArray | 10 | 7.750 ns | 0.1196 ns | 0.0998 ns | 0.09 | 0.00 | 0.0306 | - | - | 64 B | +| SpanCopyTo | 10 | 9.042 ns | 0.0833 ns | 0.0739 ns | 0.11 | 0.00 | 0.0306 | - | - | 64 B | +| CollectionCopyTo | 10 | 12.964 ns | 0.3123 ns | 0.2921 ns | 0.16 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| **ArrayClone** | **100** | **93.642 ns** | **1.5195 ns** | **2.8909 ns** | **1.00** | **0.00** | **0.2021** | **-** | **-** | **424 B** | +| SpanToArray | 100 | 33.333 ns | 0.7550 ns | 2.2262 ns | 0.36 | 0.03 | 0.2027 | - | - | 424 B | +| SpanCopyTo | 100 | 33.050 ns | 0.5890 ns | 0.5510 ns | 0.35 | 0.01 | 0.2027 | - | - | 424 B | +| CollectionCopyTo | 100 | 36.857 ns | 0.7987 ns | 0.7471 ns | 0.39 | 0.02 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | +| **ArrayClone** | **1000** | **289.606 ns** | **2.5042 ns** | **2.3424 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | +| SpanToArray | 1000 | 262.557 ns | 4.3460 ns | 3.8526 ns | 0.91 | 0.02 | 1.9226 | - | - | 4,024 B | +| SpanCopyTo | 1000 | 242.143 ns | 3.5619 ns | 3.1575 ns | 0.84 | 0.01 | 1.9155 | - | - | 4,024 B | +| CollectionCopyTo | 1000 | 245.507 ns | 4.1489 ns | 3.8809 ns | 0.85 | 0.01 | 1.9155 | - | - | 4,024 B | diff --git a/Benchmarks/ContainsBenchmarks.md b/Benchmarks/ContainsBenchmarks.md index 5761e7884..345aba29f 100644 --- a/Benchmarks/ContainsBenchmarks.md +++ b/Benchmarks/ContainsBenchmarks.md @@ -18,37 +18,37 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 38.54 ns | 0.188 ns | 0.167 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 30.81 ns | 0.105 ns | 0.093 ns | 0.80 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 23.83 ns | 0.079 ns | 0.074 ns | 0.62 | - | - | - | - | +| Linq_Array | Array | 100 | 41.37 ns | 0.116 ns | 0.108 ns | 1.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 31.03 ns | 0.118 ns | 0.110 ns | 0.75 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 23.29 ns | 0.058 ns | 0.054 ns | 0.56 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 627.99 ns | 5.507 ns | 4.598 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 199.88 ns | 0.929 ns | 0.823 ns | 0.32 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 625.41 ns | 3.478 ns | 2.904 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 211.36 ns | 0.490 ns | 0.435 ns | 0.34 | 0.0191 | - | - | 40 B | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 36.85 ns | 0.196 ns | 0.183 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 39.51 ns | 0.242 ns | 0.226 ns | 1.07 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 36.54 ns | 0.153 ns | 0.144 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 36.91 ns | 0.268 ns | 0.224 ns | 1.01 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 37.52 ns | 0.208 ns | 0.184 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 39.57 ns | 0.125 ns | 0.104 ns | 1.05 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 37.84 ns | 0.165 ns | 0.147 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 40.72 ns | 0.325 ns | 0.288 ns | 1.08 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,616.30 ns | 3.258 ns | 2.888 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 942.80 ns | 2.209 ns | 2.066 ns | 0.58 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,615.47 ns | 3.955 ns | 3.506 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 942.46 ns | 2.732 ns | 2.555 ns | 0.58 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 632.57 ns | 3.394 ns | 3.174 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 687.02 ns | 6.790 ns | 5.670 ns | 1.09 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 598.60 ns | 2.790 ns | 2.610 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 683.93 ns | 5.594 ns | 4.959 ns | 1.14 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 36.59 ns | 0.167 ns | 0.148 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 38.74 ns | 0.180 ns | 0.150 ns | 1.06 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 36.50 ns | 0.223 ns | 0.198 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 36.20 ns | 0.309 ns | 0.289 ns | 0.99 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 37.41 ns | 0.140 ns | 0.131 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 40.01 ns | 0.271 ns | 0.226 ns | 1.07 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 37.80 ns | 0.243 ns | 0.228 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 40.16 ns | 0.198 ns | 0.175 ns | 1.06 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,628.33 ns | 3.355 ns | 2.975 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,742.85 ns | 7.018 ns | 6.221 ns | 1.07 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,617.73 ns | 3.651 ns | 3.236 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,711.37 ns | 4.334 ns | 3.842 ns | 1.06 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ContainsComparerBenchmarks.md b/Benchmarks/ContainsComparerBenchmarks.md index bcfde4f5f..74ca3d3e9 100644 --- a/Benchmarks/ContainsComparerBenchmarks.md +++ b/Benchmarks/ContainsComparerBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 575.8 ns | 2.05 ns | 1.71 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 199.6 ns | 0.61 ns | 0.54 ns | 0.35 | - | - | - | - | +| Linq_Array | Array | 100 | 574.1 ns | 2.33 ns | 2.18 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 198.8 ns | 0.83 ns | 0.73 ns | 0.35 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 781.4 ns | 3.23 ns | 2.86 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 277.7 ns | 1.33 ns | 1.25 ns | 0.36 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 763.6 ns | 3.44 ns | 3.22 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 279.6 ns | 0.96 ns | 0.90 ns | 0.37 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 764.8 ns | 4.02 ns | 3.76 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 283.1 ns | 1.37 ns | 1.21 ns | 0.37 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 756.8 ns | 8.41 ns | 7.02 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 281.0 ns | 1.35 ns | 1.26 ns | 0.37 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 757.7 ns | 5.42 ns | 4.81 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 784.6 ns | 2.73 ns | 2.55 ns | 1.04 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 757.7 ns | 3.27 ns | 2.90 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 767.8 ns | 4.66 ns | 4.13 ns | 1.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,724.8 ns | 4.29 ns | 4.02 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 925.7 ns | 2.06 ns | 1.82 ns | 0.54 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,718.6 ns | 4.32 ns | 3.83 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 926.7 ns | 2.75 ns | 2.57 ns | 0.54 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 757.5 ns | 3.90 ns | 3.46 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 759.2 ns | 3.28 ns | 2.90 ns | 1.00 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 762.8 ns | 4.56 ns | 4.04 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 785.2 ns | 3.60 ns | 3.36 ns | 1.03 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 780.0 ns | 2.86 ns | 2.54 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 794.5 ns | 4.30 ns | 4.02 ns | 1.02 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 757.1 ns | 2.88 ns | 2.55 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 764.0 ns | 7.84 ns | 6.95 ns | 1.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 756.6 ns | 3.25 ns | 2.88 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 810.1 ns | 2.14 ns | 1.67 ns | 1.07 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 787.4 ns | 3.83 ns | 3.40 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 766.5 ns | 4.97 ns | 4.65 ns | 0.97 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,727.3 ns | 5.91 ns | 5.24 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,719.1 ns | 4.03 ns | 3.58 ns | 1.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,718.6 ns | 4.82 ns | 4.28 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,718.5 ns | 3.97 ns | 3.71 ns | 1.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/CountBenchmarks.md b/Benchmarks/CountBenchmarks.md index 80b8c2fb6..209127532 100644 --- a/Benchmarks/CountBenchmarks.md +++ b/Benchmarks/CountBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |--------------:|----------:|----------:|-------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 9.1074 ns | 0.0784 ns | 0.0655 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Array | Array | 100 | 0.6715 ns | 0.0133 ns | 0.0125 ns | 0.07 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 7.9661 ns | 0.0225 ns | 0.0210 ns | 0.87 | 0.01 | - | - | - | - | +| Linq_Array | Array | 100 | 9.3540 ns | 0.0399 ns | 0.0353 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Array | Array | 100 | 0.7840 ns | 0.0100 ns | 0.0093 ns | 0.08 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.7322 ns | 0.0259 ns | 0.0242 ns | 0.83 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 349.7961 ns | 3.6308 ns | 3.3963 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 598.2427 ns | 2.5847 ns | 2.0180 ns | 1.71 | 0.02 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 141.0781 ns | 0.2799 ns | 0.2618 ns | 0.40 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 349.3511 ns | 2.4083 ns | 2.1349 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 597.3489 ns | 2.3495 ns | 2.1978 ns | 1.71 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 140.6946 ns | 0.3631 ns | 0.3396 ns | 0.40 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.0306 ns | 0.0247 ns | 0.0207 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Value | Collection_Value | 100 | 651.6739 ns | 4.1784 ns | 3.4892 ns | 161.69 | 1.35 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.7398 ns | 0.0236 ns | 0.0209 ns | 1.92 | 0.01 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 4.1085 ns | 0.0220 ns | 0.0195 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Value | Collection_Value | 100 | 604.9679 ns | 5.7949 ns | 5.4206 ns | 147.31 | 1.75 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.4980 ns | 0.0233 ns | 0.0206 ns | 1.83 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.0033 ns | 0.0309 ns | 0.0274 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Value | List_Value | 100 | 2.0895 ns | 0.0152 ns | 0.0143 ns | 0.42 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.7885 ns | 0.0177 ns | 0.0157 ns | 0.36 | 0.00 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 4.9597 ns | 0.0216 ns | 0.0202 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Value | List_Value | 100 | 2.3068 ns | 0.0209 ns | 0.0195 ns | 0.47 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.7986 ns | 0.0170 ns | 0.0150 ns | 0.36 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,617.7575 ns | 5.5046 ns | 4.2976 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 776.3272 ns | 2.0551 ns | 1.7161 ns | 0.48 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,631.2288 ns | 5.2514 ns | 4.9121 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 775.6346 ns | 1.3539 ns | 1.2664 ns | 0.48 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 347.5843 ns | 1.2942 ns | 1.1473 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 648.1673 ns | 3.0979 ns | 2.7462 ns | 1.86 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 382.5596 ns | 3.7097 ns | 3.2886 ns | 1.10 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 348.0530 ns | 2.2995 ns | 1.9202 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 597.0186 ns | 3.3703 ns | 2.9877 ns | 1.71 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 392.4467 ns | 2.1130 ns | 1.8731 ns | 1.13 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.1545 ns | 0.0403 ns | 0.0377 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 596.9610 ns | 1.8706 ns | 1.6583 ns | 143.75 | 1.49 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.7762 ns | 0.0103 ns | 0.0091 ns | 0.43 | 0.00 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.1574 ns | 0.0297 ns | 0.0278 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 596.4288 ns | 2.9400 ns | 2.6063 ns | 143.60 | 1.07 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.8501 ns | 0.0173 ns | 0.0153 ns | 0.45 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 4.9565 ns | 0.0651 ns | 0.0577 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Reference | List_Reference | 100 | 604.8412 ns | 3.4385 ns | 3.2164 ns | 122.05 | 1.78 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.7892 ns | 0.0157 ns | 0.0140 ns | 0.36 | 0.00 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 4.9423 ns | 0.0317 ns | 0.0281 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Reference | List_Reference | 100 | 600.4904 ns | 4.4677 ns | 3.9605 ns | 121.50 | 0.84 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.7823 ns | 0.0152 ns | 0.0135 ns | 0.36 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,617.0364 ns | 4.1368 ns | 3.8696 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,416.2269 ns | 3.3714 ns | 2.9887 ns | 0.88 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,615.1213 ns | 3.2752 ns | 2.9034 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,390.1995 ns | 3.0343 ns | 2.6898 ns | 0.86 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/DistinctBenchmarks.md b/Benchmarks/DistinctBenchmarks.md index 9500dce6b..df68f5c18 100644 --- a/Benchmarks/DistinctBenchmarks.md +++ b/Benchmarks/DistinctBenchmarks.md @@ -18,45 +18,45 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |---------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 1.902 μs | 0.0359 μs | 0.0336 μs | 1.00 | 0.00 | 1.3294 | - | - | 2,784 B | -| StructLinq_Array | Array | 100 | 1.271 μs | 0.0052 μs | 0.0046 μs | 0.67 | 0.01 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 1.476 μs | 0.0065 μs | 0.0060 μs | 0.78 | 0.01 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 1.529 μs | 0.0074 μs | 0.0065 μs | 0.80 | 0.02 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.562 μs | 0.0064 μs | 0.0057 μs | 0.82 | 0.02 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.260 μs | 0.0111 μs | 0.0093 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.186 μs | 0.0113 μs | 0.0106 μs | 0.97 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.556 μs | 0.0041 μs | 0.0037 μs | 0.69 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 2.251 μs | 0.0163 μs | 0.0144 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 2.176 μs | 0.0138 μs | 0.0129 μs | 0.97 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.518 μs | 0.0092 μs | 0.0081 μs | 0.67 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 2.205 μs | 0.0162 μs | 0.0152 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_List_Value | List_Value | 100 | 1.514 μs | 0.0065 μs | 0.0061 μs | 0.69 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 2.732 μs | 0.0129 μs | 0.0114 μs | 1.24 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.589 μs | 0.1489 μs | 0.1828 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.450 μs | 0.0323 μs | 0.0286 μs | 0.59 | 0.02 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.195 μs | 0.0094 μs | 0.0083 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.191 μs | 0.0144 μs | 0.0127 μs | 1.00 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.576 μs | 0.0078 μs | 0.0061 μs | 1.17 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 2.284 μs | 0.0135 μs | 0.0112 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 2.191 μs | 0.0158 μs | 0.0148 μs | 0.96 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.663 μs | 0.0179 μs | 0.0140 μs | 1.17 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 2.432 μs | 0.0137 μs | 0.0129 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_List_Reference | List_Reference | 100 | 2.153 μs | 0.0155 μs | 0.0130 μs | 0.89 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 2.765 μs | 0.0202 μs | 0.0179 μs | 1.14 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8.357 μs | 0.1664 μs | 0.2590 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4.899 μs | 0.0221 μs | 0.0196 μs | 0.59 | 0.02 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |---------:|----------:|----------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 1.902 μs | 0.0095 μs | 0.0084 μs | 1.901 μs | 1.00 | 0.00 | 1.3294 | - | - | 2,784 B | +| StructLinq_Array | Array | 100 | 1.277 μs | 0.0123 μs | 0.0109 μs | 1.273 μs | 0.67 | 0.01 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 1.474 μs | 0.0062 μs | 0.0058 μs | 1.472 μs | 0.77 | 0.00 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 1.515 μs | 0.0088 μs | 0.0078 μs | 1.516 μs | 0.80 | 0.01 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.593 μs | 0.0055 μs | 0.0046 μs | 1.593 μs | 0.84 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.245 μs | 0.0141 μs | 0.0117 μs | 2.241 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.232 μs | 0.0129 μs | 0.0115 μs | 2.234 μs | 0.99 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.544 μs | 0.0058 μs | 0.0054 μs | 1.544 μs | 0.69 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 2.279 μs | 0.0164 μs | 0.0137 μs | 2.275 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 2.240 μs | 0.0204 μs | 0.0181 μs | 2.241 μs | 0.98 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.532 μs | 0.0069 μs | 0.0061 μs | 1.529 μs | 0.67 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 2.252 μs | 0.0257 μs | 0.0215 μs | 2.249 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_List_Value | List_Value | 100 | 1.526 μs | 0.0071 μs | 0.0063 μs | 1.528 μs | 0.68 | 0.01 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 2.798 μs | 0.0095 μs | 0.0084 μs | 2.797 μs | 1.24 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.665 μs | 0.0404 μs | 0.0358 μs | 7.666 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.387 μs | 0.0145 μs | 0.0136 μs | 4.384 μs | 0.57 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.206 μs | 0.0067 μs | 0.0056 μs | 2.208 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.210 μs | 0.0134 μs | 0.0126 μs | 2.208 μs | 1.00 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.696 μs | 0.0103 μs | 0.0092 μs | 2.696 μs | 1.22 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 2.238 μs | 0.0134 μs | 0.0125 μs | 2.234 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 2.218 μs | 0.0162 μs | 0.0144 μs | 2.225 μs | 0.99 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.623 μs | 0.0152 μs | 0.0135 μs | 2.624 μs | 1.17 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 2.270 μs | 0.0140 μs | 0.0117 μs | 2.264 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_List_Reference | List_Reference | 100 | 2.208 μs | 0.0163 μs | 0.0152 μs | 2.204 μs | 0.97 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 2.752 μs | 0.0078 μs | 0.0069 μs | 2.754 μs | 1.21 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.447 μs | 0.1489 μs | 0.2183 μs | 7.293 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4.914 μs | 0.0167 μs | 0.0148 μs | 4.913 μs | 0.65 | 0.02 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ElementAtBenchmarks.md b/Benchmarks/ElementAtBenchmarks.md index 217b82e3e..20052259e 100644 --- a/Benchmarks/ElementAtBenchmarks.md +++ b/Benchmarks/ElementAtBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 16.195 ns | 0.1166 ns | 0.0974 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 12.970 ns | 0.0407 ns | 0.0361 ns | 0.80 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 15.961 ns | 0.0914 ns | 0.0763 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 12.948 ns | 0.0370 ns | 0.0328 ns | 0.81 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 345.293 ns | 1.8967 ns | 1.7741 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 131.154 ns | 0.4162 ns | 0.3689 ns | 0.38 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 321.713 ns | 2.1199 ns | 1.8792 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 131.208 ns | 0.4962 ns | 0.4399 ns | 0.41 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 317.201 ns | 2.3228 ns | 1.9397 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 136.510 ns | 0.4444 ns | 0.3711 ns | 0.43 | 0.00 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 316.246 ns | 0.8984 ns | 0.7014 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 136.082 ns | 0.6140 ns | 0.5443 ns | 0.43 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 9.763 ns | 0.0775 ns | 0.0687 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 344.678 ns | 4.0756 ns | 3.1819 ns | 35.30 | 0.40 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 9.747 ns | 0.0391 ns | 0.0347 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 341.010 ns | 1.4219 ns | 1.1874 ns | 34.98 | 0.16 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,623.137 ns | 6.5760 ns | 5.4913 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 801.118 ns | 1.8841 ns | 1.5733 ns | 0.49 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,617.668 ns | 4.8676 ns | 4.3150 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 804.608 ns | 3.9449 ns | 3.4970 ns | 0.50 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 343.991 ns | 5.0239 ns | 4.4535 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 340.969 ns | 1.2339 ns | 0.9633 ns | 0.99 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 315.847 ns | 1.1479 ns | 1.0176 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 336.160 ns | 3.1605 ns | 2.9564 ns | 1.07 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 343.868 ns | 1.5650 ns | 3.5325 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 353.880 ns | 2.0154 ns | 1.7866 ns | 1.04 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 316.810 ns | 1.5474 ns | 1.3718 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 361.737 ns | 1.0627 ns | 0.9421 ns | 1.14 | 0.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 9.557 ns | 0.0418 ns | 0.0371 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 318.015 ns | 1.8263 ns | 1.5250 ns | 33.27 | 0.19 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 9.761 ns | 0.0949 ns | 0.0842 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 368.868 ns | 3.0067 ns | 2.6654 ns | 37.79 | 0.44 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,615.527 ns | 3.2110 ns | 2.8465 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,408.213 ns | 5.3995 ns | 5.0507 ns | 0.87 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,617.709 ns | 5.9396 ns | 4.9599 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,435.386 ns | 5.2823 ns | 4.6827 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/EmptyBenchmarks.md b/Benchmarks/EmptyBenchmarks.md index 91ff28fd2..204e2f6ff 100644 --- a/Benchmarks/EmptyBenchmarks.md +++ b/Benchmarks/EmptyBenchmarks.md @@ -18,15 +18,15 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------------- |------------ |-----------:|----------:|----------:|------:|------:|------:|------:|----------:| -| Linq_Empty | Empty | 6.5124 ns | 0.0392 ns | 0.0366 ns | 1.000 | - | - | - | - | -| Hyperlinq_Empty | Empty | 0.0120 ns | 0.0080 ns | 0.0075 ns | 0.002 | - | - | - | - | +| Linq_Empty | Empty | 6.4999 ns | 0.0496 ns | 0.0439 ns | 1.000 | - | - | - | - | +| Hyperlinq_Empty | Empty | 0.0066 ns | 0.0055 ns | 0.0048 ns | 0.001 | - | - | - | - | | | | | | | | | | | | -| Linq_Empty_Async | Empty_Async | 42.3276 ns | 0.1002 ns | 0.0837 ns | 1.00 | - | - | - | - | -| Hyperlinq_Empty_Async | Empty_Async | 20.8454 ns | 0.0723 ns | 0.0604 ns | 0.49 | - | - | - | - | +| Linq_Empty_Async | Empty_Async | 41.3903 ns | 0.1669 ns | 0.1480 ns | 1.00 | - | - | - | - | +| Hyperlinq_Empty_Async | Empty_Async | 20.8240 ns | 0.1316 ns | 0.1099 ns | 0.50 | - | - | - | - | diff --git a/Benchmarks/FirstBenchmarks.md b/Benchmarks/FirstBenchmarks.md index fbae71c9c..d75929a9d 100644 --- a/Benchmarks/FirstBenchmarks.md +++ b/Benchmarks/FirstBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 19.24 ns | 0.078 ns | 0.073 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 13.26 ns | 0.034 ns | 0.032 ns | 0.69 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 19.32 ns | 0.133 ns | 0.118 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 13.15 ns | 0.025 ns | 0.024 ns | 0.68 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 25.00 ns | 0.127 ns | 0.112 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.57 ns | 0.040 ns | 0.033 ns | 0.62 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 25.19 ns | 0.109 ns | 0.091 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.61 ns | 0.051 ns | 0.045 ns | 0.62 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 28.18 ns | 0.592 ns | 1.127 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 18.92 ns | 0.061 ns | 0.054 ns | 0.68 | 0.02 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 26.26 ns | 0.145 ns | 0.121 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 19.36 ns | 0.038 ns | 0.033 ns | 0.74 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 12.44 ns | 0.050 ns | 0.039 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 22.00 ns | 0.120 ns | 0.172 ns | 1.77 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 12.29 ns | 0.079 ns | 0.070 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 21.07 ns | 0.107 ns | 0.100 ns | 1.72 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 103.75 ns | 0.487 ns | 0.432 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 61.99 ns | 0.117 ns | 0.098 ns | 0.60 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 101.36 ns | 0.383 ns | 0.320 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 60.98 ns | 0.182 ns | 0.170 ns | 0.60 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 26.59 ns | 0.528 ns | 0.468 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 17.38 ns | 0.114 ns | 0.101 ns | 0.65 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 26.33 ns | 0.555 ns | 1.001 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 18.44 ns | 0.142 ns | 0.126 ns | 0.71 | 0.02 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 25.97 ns | 0.191 ns | 0.178 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 20.63 ns | 0.114 ns | 0.095 ns | 0.79 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 26.37 ns | 0.280 ns | 0.248 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 18.35 ns | 0.109 ns | 0.102 ns | 0.70 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 12.52 ns | 0.091 ns | 0.081 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 20.87 ns | 0.104 ns | 0.093 ns | 1.67 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 12.28 ns | 0.036 ns | 0.032 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 23.76 ns | 0.498 ns | 0.611 ns | 1.92 | 0.06 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 103.68 ns | 2.016 ns | 2.071 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 70.01 ns | 1.326 ns | 1.240 ns | 0.67 | 0.02 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 103.29 ns | 0.420 ns | 0.372 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 67.61 ns | 0.145 ns | 0.121 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ListIterationBenchmarks.md b/Benchmarks/ListIterationBenchmarks.md index 246988644..f49c2778b 100644 --- a/Benchmarks/ListIterationBenchmarks.md +++ b/Benchmarks/ListIterationBenchmarks.md @@ -18,16 +18,16 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------- |-------------- |-------- |------------:|----------:|----------:|------:|--------:|------:|------:|------:|----------:| -| List_Enumerable | List | 1000000 | 1,344.6 μs | 7.83 μs | 6.54 μs | 1.00 | 0.00 | - | - | - | 1 B | -| List_Indexer | List | 1000000 | 1,176.2 μs | 5.95 μs | 5.56 μs | 0.87 | 0.01 | - | - | - | 1 B | -| List_Span | List | 1000000 | 459.5 μs | 6.01 μs | 5.32 μs | 0.34 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| ImmutableList_Enumerable | ImmutableList | 1000000 | 35,174.0 μs | 356.44 μs | 315.97 μs | 1.00 | 0.00 | - | - | - | 10 B | -| ImmutableList_Indexer | ImmutableList | 1000000 | 62,851.2 μs | 274.72 μs | 256.97 μs | 1.79 | 0.02 | - | - | - | 16 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------- |-------------- |-------- |------------:|------------:|------------:|------------:|------:|--------:|------:|------:|------:|----------:| +| List_Enumerable | List | 1000000 | 1,392.6 μs | 27.61 μs | 60.61 μs | 1,350.0 μs | 1.00 | 0.00 | - | - | - | - | +| List_Indexer | List | 1000000 | 1,066.9 μs | 3.64 μs | 3.04 μs | 1,067.6 μs | 0.76 | 0.03 | - | - | - | 1 B | +| List_Span | List | 1000000 | 457.8 μs | 2.98 μs | 3.32 μs | 456.8 μs | 0.32 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| ImmutableList_Enumerable | ImmutableList | 1000000 | 36,880.0 μs | 813.67 μs | 2,399.13 μs | 35,638.2 μs | 1.00 | 0.00 | - | - | - | 10 B | +| ImmutableList_Indexer | ImmutableList | 1000000 | 60,898.2 μs | 1,206.47 μs | 2,698.44 μs | 59,314.9 μs | 1.61 | 0.08 | - | - | - | 16 B | diff --git a/Benchmarks/RangeBenchmarks.md b/Benchmarks/RangeBenchmarks.md index c2566d35a..a4c4d89ac 100644 --- a/Benchmarks/RangeBenchmarks.md +++ b/Benchmarks/RangeBenchmarks.md @@ -18,16 +18,16 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------ |------ |------------:|----------:|---------:|------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 397.16 ns | 4.535 ns | 4.242 ns | 1.00 | 0.0191 | - | - | 40 B | -| StructLinq | Range | 100 | 33.81 ns | 0.143 ns | 0.126 ns | 0.09 | - | - | - | - | -| Hyperlinq | Range | 100 | 42.34 ns | 0.192 ns | 0.170 ns | 0.11 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 3,689.77 ns | 10.303 ns | 9.133 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Range_Async | 100 | 1,230.03 ns | 4.703 ns | 3.927 ns | 0.33 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------ |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq | Range | 100 | 439.33 ns | 2.995 ns | 2.655 ns | 1.00 | 0.0191 | - | - | 40 B | +| StructLinq | Range | 100 | 33.66 ns | 0.137 ns | 0.114 ns | 0.08 | - | - | - | - | +| Hyperlinq | Range | 100 | 41.83 ns | 0.164 ns | 0.145 ns | 0.10 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Async | Range_Async | 100 | 3,696.52 ns | 9.939 ns | 8.811 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Range_Async | 100 | 1,232.14 ns | 7.870 ns | 6.977 ns | 0.33 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/RangeToArrayBenchmarks.md b/Benchmarks/RangeToArrayBenchmarks.md index 28fe1aa92..43c540f27 100644 --- a/Benchmarks/RangeToArrayBenchmarks.md +++ b/Benchmarks/RangeToArrayBenchmarks.md @@ -18,17 +18,17 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------ |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 81.27 ns | 0.932 ns | 1.774 ns | 1.00 | 0.00 | 0.2218 | - | - | 464 B | -| StructLinq | Range | 100 | 85.57 ns | 0.620 ns | 0.580 ns | 1.04 | 0.03 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Range | 100 | 36.20 ns | 0.377 ns | 0.352 ns | 0.44 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq | Range | 100 | 41.93 ns | 0.655 ns | 0.580 ns | 0.51 | 0.02 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 105.20 ns | 1.541 ns | 1.366 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Range_Async | 100 | 146.42 ns | 1.256 ns | 1.175 ns | 1.39 | 0.02 | 0.2027 | - | - | 424 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------ |------ |----------:|---------:|---------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq | Range | 100 | 83.93 ns | 1.194 ns | 1.635 ns | 83.73 ns | 1.00 | 0.00 | 0.2218 | - | - | 464 B | +| StructLinq | Range | 100 | 92.26 ns | 1.910 ns | 3.859 ns | 91.20 ns | 1.10 | 0.05 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Range | 100 | 40.19 ns | 0.874 ns | 2.493 ns | 39.14 ns | 0.48 | 0.03 | 0.2027 | - | - | 424 B | +| Hyperlinq | Range | 100 | 44.88 ns | 0.802 ns | 0.711 ns | 45.15 ns | 0.53 | 0.01 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Async | Range_Async | 100 | 105.70 ns | 0.993 ns | 0.880 ns | 105.84 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Range_Async | 100 | 152.75 ns | 3.112 ns | 7.807 ns | 147.54 ns | 1.44 | 0.07 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/ReadOnlyFieldsBenchmarks.md b/Benchmarks/ReadOnlyFieldsBenchmarks.md index b830919ec..6216052dc 100644 --- a/Benchmarks/ReadOnlyFieldsBenchmarks.md +++ b/Benchmarks/ReadOnlyFieldsBenchmarks.md @@ -18,13 +18,13 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------ |---------:|--------:|--------:|------:|------:|------:|------:|----------:| -| Baseline | 1000 | 544.6 ns | 1.08 ns | 1.01 ns | 1.00 | - | - | - | - | -| ReadOnlyCurrent | 1000 | 544.2 ns | 1.28 ns | 1.20 ns | 1.00 | - | - | - | - | -| ReadOnlyField | 1000 | 546.4 ns | 1.84 ns | 1.72 ns | 1.00 | - | - | - | - | +| Baseline | 1000 | 544.1 ns | 1.03 ns | 0.96 ns | 1.00 | - | - | - | - | +| ReadOnlyCurrent | 1000 | 544.6 ns | 1.13 ns | 1.06 ns | 1.00 | - | - | - | - | +| ReadOnlyField | 1000 | 544.4 ns | 0.78 ns | 0.65 ns | 1.00 | - | - | - | - | diff --git a/Benchmarks/RepeatBenchmarks.md b/Benchmarks/RepeatBenchmarks.md index 6365b98b1..4b2a0e9ea 100644 --- a/Benchmarks/RepeatBenchmarks.md +++ b/Benchmarks/RepeatBenchmarks.md @@ -18,16 +18,16 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 388.03 ns | 2.670 ns | 2.367 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq | Repeat | 100 | 44.37 ns | 0.187 ns | 0.146 ns | 0.11 | - | - | - | - | -| Hyperlinq | Repeat | 100 | 147.12 ns | 0.422 ns | 0.395 ns | 0.38 | - | - | - | - | +| Linq | Repeat | 100 | 393.35 ns | 1.375 ns | 1.219 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq | Repeat | 100 | 44.33 ns | 0.164 ns | 0.154 ns | 0.11 | - | - | - | - | +| Hyperlinq | Repeat | 100 | 147.06 ns | 0.308 ns | 0.288 ns | 0.37 | - | - | - | - | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 4,715.35 ns | 18.267 ns | 15.253 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Repeat_Async | 100 | 795.54 ns | 1.931 ns | 1.711 ns | 0.17 | - | - | - | - | +| Linq_Async | Repeat_Async | 100 | 4,710.88 ns | 21.558 ns | 20.165 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Repeat_Async | 100 | 770.99 ns | 4.354 ns | 3.636 ns | 0.16 | - | - | - | - | diff --git a/Benchmarks/RepeatToArrayBenchmarks.md b/Benchmarks/RepeatToArrayBenchmarks.md index 547cd2a89..080e4a1a9 100644 --- a/Benchmarks/RepeatToArrayBenchmarks.md +++ b/Benchmarks/RepeatToArrayBenchmarks.md @@ -18,18 +18,18 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------- |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 75.53 ns | 0.909 ns | 0.851 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq | Repeat | 100 | 79.08 ns | 0.694 ns | 0.649 ns | 1.05 | 0.02 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Repeat | 100 | 27.64 ns | 0.234 ns | 0.195 ns | 0.37 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq | Repeat | 100 | 53.12 ns | 0.632 ns | 0.528 ns | 0.70 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_SIMD | Repeat | 100 | 37.55 ns | 0.457 ns | 0.405 ns | 0.50 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 90.23 ns | 0.866 ns | 0.723 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Repeat_Async | 100 | 117.80 ns | 1.777 ns | 1.576 ns | 1.31 | 0.02 | 0.2027 | - | - | 424 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------- |------ |----------:|---------:|---------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq | Repeat | 100 | 92.02 ns | 1.863 ns | 2.356 ns | 91.28 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq | Repeat | 100 | 82.20 ns | 0.970 ns | 0.907 ns | 81.84 ns | 0.89 | 0.03 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Repeat | 100 | 33.45 ns | 0.318 ns | 0.282 ns | 33.40 ns | 0.36 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq | Repeat | 100 | 56.99 ns | 0.730 ns | 0.683 ns | 56.87 ns | 0.62 | 0.02 | 0.2027 | - | - | 424 B | +| Hyperlinq_SIMD | Repeat | 100 | 41.44 ns | 0.897 ns | 2.266 ns | 40.31 ns | 0.45 | 0.03 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Async | Repeat_Async | 100 | 93.83 ns | 1.475 ns | 1.379 ns | 94.28 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Repeat_Async | 100 | 119.13 ns | 1.828 ns | 1.710 ns | 119.07 ns | 1.27 | 0.03 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/ReturnBenchmarks.md b/Benchmarks/ReturnBenchmarks.md index a9b9b2ee5..4e070ee5c 100644 --- a/Benchmarks/ReturnBenchmarks.md +++ b/Benchmarks/ReturnBenchmarks.md @@ -18,15 +18,15 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |----------------------- |------------- |----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Return | Return | 15.500 ns | 0.0639 ns | 0.0534 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_Return | Return | 8.722 ns | 0.0172 ns | 0.0153 ns | 0.56 | 0.00 | - | - | - | - | +| Linq_Return | Return | 15.486 ns | 0.1401 ns | 0.1311 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_Return | Return | 8.736 ns | 0.0199 ns | 0.0186 ns | 0.56 | 0.00 | - | - | - | - | | | | | | | | | | | | | -| Linq_Return_Async | Return_Async | 59.634 ns | 1.1815 ns | 1.2642 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Return_Async | Return_Async | 39.919 ns | 0.0888 ns | 0.0787 ns | 0.67 | 0.02 | - | - | - | - | +| Linq_Return_Async | Return_Async | 58.705 ns | 1.1953 ns | 2.5729 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Return_Async | Return_Async | 40.121 ns | 0.2094 ns | 0.1959 ns | 0.68 | 0.02 | - | - | - | - | diff --git a/Benchmarks/SelectBenchmarks.md b/Benchmarks/SelectBenchmarks.md index 741aabb42..67310e33c 100644 --- a/Benchmarks/SelectBenchmarks.md +++ b/Benchmarks/SelectBenchmarks.md @@ -18,48 +18,48 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 642.6 ns | 2.60 ns | 2.17 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 206.1 ns | 0.58 ns | 0.52 ns | 0.32 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 273.0 ns | 1.36 ns | 1.13 ns | 0.42 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 209.9 ns | 0.67 ns | 0.56 ns | 0.33 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 172.1 ns | 0.72 ns | 0.64 ns | 0.27 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 208.8 ns | 0.72 ns | 0.60 ns | 0.32 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 298.9 ns | 1.53 ns | 1.36 ns | 0.47 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 232.7 ns | 0.57 ns | 0.48 ns | 0.36 | - | - | - | - | +| Linq_Array | Array | 100 | 589.9 ns | 2.07 ns | 1.83 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 226.2 ns | 0.87 ns | 0.77 ns | 0.38 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 297.1 ns | 1.63 ns | 1.52 ns | 0.50 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 208.8 ns | 0.62 ns | 0.58 ns | 0.35 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 197.5 ns | 0.78 ns | 0.65 ns | 0.33 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 208.3 ns | 0.62 ns | 0.52 ns | 0.35 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 299.8 ns | 1.99 ns | 1.67 ns | 0.51 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 232.3 ns | 0.60 ns | 0.50 ns | 0.39 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,138.7 ns | 5.13 ns | 4.80 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 754.1 ns | 6.10 ns | 5.41 ns | 0.66 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 229.8 ns | 0.52 ns | 0.46 ns | 0.20 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,197.2 ns | 5.22 ns | 4.88 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 749.6 ns | 2.16 ns | 1.92 ns | 0.63 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 229.6 ns | 0.50 ns | 0.42 ns | 0.19 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,230.2 ns | 11.48 ns | 10.17 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 758.3 ns | 5.50 ns | 5.15 ns | 0.62 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 207.7 ns | 0.54 ns | 0.50 ns | 0.17 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,230.5 ns | 15.98 ns | 13.34 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 777.3 ns | 3.24 ns | 2.87 ns | 0.63 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 206.6 ns | 0.66 ns | 0.55 ns | 0.17 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,227.2 ns | 5.49 ns | 4.58 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 438.1 ns | 0.93 ns | 0.82 ns | 0.36 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 742.3 ns | 4.22 ns | 3.74 ns | 0.60 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,183.7 ns | 4.01 ns | 3.56 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 439.6 ns | 1.84 ns | 1.63 ns | 0.37 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 759.3 ns | 3.40 ns | 3.01 ns | 0.64 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,756.0 ns | 28.27 ns | 26.45 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,746.1 ns | 31.36 ns | 29.34 ns | 0.70 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,848.7 ns | 33.67 ns | 29.85 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,724.6 ns | 19.11 ns | 16.94 ns | 0.69 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,170.2 ns | 4.51 ns | 4.00 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 703.7 ns | 4.61 ns | 4.08 ns | 0.60 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 785.8 ns | 7.09 ns | 6.28 ns | 0.67 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,168.8 ns | 5.61 ns | 5.25 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 699.4 ns | 1.85 ns | 1.54 ns | 0.60 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 775.8 ns | 5.45 ns | 5.35 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,173.1 ns | 5.95 ns | 5.27 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 758.6 ns | 4.39 ns | 3.89 ns | 0.65 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 755.6 ns | 3.61 ns | 3.38 ns | 0.64 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,172.4 ns | 6.69 ns | 5.93 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 756.2 ns | 2.48 ns | 2.20 ns | 0.65 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 754.2 ns | 2.39 ns | 1.99 ns | 0.64 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,130.5 ns | 7.47 ns | 6.24 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 753.1 ns | 4.04 ns | 3.58 ns | 0.67 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 753.5 ns | 4.30 ns | 3.81 ns | 0.67 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,180.1 ns | 9.98 ns | 8.85 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 755.6 ns | 5.35 ns | 4.74 ns | 0.64 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 752.5 ns | 3.45 ns | 3.06 ns | 0.64 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,635.0 ns | 40.24 ns | 35.67 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,152.2 ns | 20.92 ns | 18.54 ns | 0.78 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,323.5 ns | 41.43 ns | 38.76 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,159.2 ns | 19.05 ns | 16.88 ns | 0.70 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectCountBenchmarks.md b/Benchmarks/SelectCountBenchmarks.md index 498f006ee..0db3da73d 100644 --- a/Benchmarks/SelectCountBenchmarks.md +++ b/Benchmarks/SelectCountBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-------------:|-----------:|-----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 219.711 ns | 4.1739 ns | 3.9042 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 10.184 ns | 0.0370 ns | 0.0328 ns | 0.05 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 15.418 ns | 0.0369 ns | 0.0345 ns | 0.07 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 812.967 ns | 5.9923 ns | 5.3121 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 784.076 ns | 4.0677 ns | 3.6059 ns | 0.96 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 144.744 ns | 0.2739 ns | 0.2562 ns | 0.18 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 801.510 ns | 5.9916 ns | 5.3114 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 769.218 ns | 4.4604 ns | 3.9541 ns | 0.96 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 16.540 ns | 0.0370 ns | 0.0328 ns | 0.02 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 402.821 ns | 0.5863 ns | 0.4895 ns | 1.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Value | List_Value | 100 | 10.144 ns | 0.0241 ns | 0.0225 ns | 0.03 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 4.959 ns | 0.0321 ns | 0.0268 ns | 0.01 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,802.309 ns | 15.9078 ns | 14.8802 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 786.096 ns | 1.0756 ns | 1.0061 ns | 0.10 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 779.795 ns | 5.2856 ns | 4.9441 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 755.027 ns | 3.7415 ns | 3.1243 ns | 0.97 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 373.832 ns | 3.4209 ns | 2.6708 ns | 0.48 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 764.223 ns | 3.1207 ns | 2.7664 ns | 1.000 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 785.206 ns | 4.3773 ns | 3.8804 ns | 1.027 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.343 ns | 0.0194 ns | 0.0172 ns | 0.006 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 414.345 ns | 3.3147 ns | 2.9384 ns | 1.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Reference | List_Reference | 100 | 754.097 ns | 2.5777 ns | 2.1525 ns | 1.82 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 4.476 ns | 0.0161 ns | 0.0143 ns | 0.01 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,958.364 ns | 21.2835 ns | 17.7727 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,428.854 ns | 6.0499 ns | 5.3631 ns | 0.21 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-------------:|-----------:|-----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 225.909 ns | 0.4993 ns | 0.3898 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 10.203 ns | 0.0223 ns | 0.0198 ns | 0.05 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 15.432 ns | 0.0342 ns | 0.0320 ns | 0.07 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 802.029 ns | 2.6396 ns | 2.3399 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 761.393 ns | 3.4969 ns | 3.2710 ns | 0.95 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 144.689 ns | 0.3393 ns | 0.3174 ns | 0.18 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 827.683 ns | 4.5779 ns | 3.8227 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 762.567 ns | 1.9828 ns | 1.6557 ns | 0.92 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 16.523 ns | 0.0372 ns | 0.0329 ns | 0.02 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 445.413 ns | 1.9880 ns | 1.7623 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Value | List_Value | 100 | 10.183 ns | 0.0367 ns | 0.0343 ns | 0.02 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 4.708 ns | 0.0297 ns | 0.0278 ns | 0.01 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,929.070 ns | 28.1569 ns | 23.5123 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 788.419 ns | 2.0581 ns | 1.8244 ns | 0.11 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 776.714 ns | 4.4453 ns | 3.9406 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 754.998 ns | 4.7763 ns | 3.9884 ns | 0.97 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 394.936 ns | 1.9683 ns | 1.5367 ns | 0.51 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 767.129 ns | 4.2155 ns | 3.7370 ns | 1.000 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 789.990 ns | 5.2898 ns | 4.9481 ns | 1.031 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.680 ns | 0.0220 ns | 0.0184 ns | 0.006 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 406.865 ns | 2.2082 ns | 2.0656 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Reference | List_Reference | 100 | 786.466 ns | 7.8552 ns | 6.5595 ns | 1.93 | 0.02 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 4.550 ns | 0.0163 ns | 0.0144 ns | 0.01 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,970.239 ns | 23.5447 ns | 19.6609 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,397.486 ns | 3.5906 ns | 3.1830 ns | 0.20 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectManyBenchmarks.md b/Benchmarks/SelectManyBenchmarks.md index d5b410e65..b911362e6 100644 --- a/Benchmarks/SelectManyBenchmarks.md +++ b/Benchmarks/SelectManyBenchmarks.md @@ -18,35 +18,35 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------- |-------------------------- |------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 2.815 μs | 0.0153 μs | 0.0128 μs | 2.812 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Array | Array | 100 | 1.221 μs | 0.0032 μs | 0.0028 μs | 1.221 μs | 0.43 | 0.00 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.382 μs | 0.0040 μs | 0.0037 μs | 1.382 μs | 0.49 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 2.830 μs | 0.0174 μs | 0.0155 μs | 2.829 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Array | Array | 100 | 1.226 μs | 0.0027 μs | 0.0024 μs | 1.225 μs | 0.43 | 0.00 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.377 μs | 0.0030 μs | 0.0028 μs | 1.377 μs | 0.49 | 0.00 | - | - | - | - | | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.976 μs | 0.0218 μs | 0.0182 μs | 2.970 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.251 μs | 0.0315 μs | 0.0263 μs | 3.239 μs | 1.09 | 0.01 | 2.3575 | - | - | 4,936 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.236 μs | 0.0128 μs | 0.0120 μs | 3.236 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.398 μs | 0.0678 μs | 0.1416 μs | 3.308 μs | 1.06 | 0.04 | 2.3575 | - | - | 4,936 B | | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 3.073 μs | 0.0543 μs | 0.0965 μs | 3.030 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.328 μs | 0.0194 μs | 0.0182 μs | 3.324 μs | 1.06 | 0.04 | 2.3575 | - | - | 4,936 B | +| Linq_Collection_Value | Collection_Value | 100 | 3.003 μs | 0.0124 μs | 0.0110 μs | 3.000 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.304 μs | 0.0110 μs | 0.0103 μs | 3.305 μs | 1.10 | 0.01 | 2.3575 | - | - | 4,936 B | | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 3.178 μs | 0.0422 μs | 0.0374 μs | 3.186 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_List_Value | List_Value | 100 | 3.391 μs | 0.0676 μs | 0.1318 μs | 3.306 μs | 1.13 | 0.01 | 2.3499 | - | - | 4,920 B | +| Linq_List_Value | List_Value | 100 | 3.117 μs | 0.0619 μs | 0.1292 μs | 3.049 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_List_Value | List_Value | 100 | 3.453 μs | 0.0682 μs | 0.1409 μs | 3.353 μs | 1.11 | 0.03 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 11.623 μs | 0.0643 μs | 0.0601 μs | 11.616 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 11.580 μs | 0.0486 μs | 0.0431 μs | 11.586 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.999 μs | 0.0136 μs | 0.0128 μs | 3.001 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 3.308 μs | 0.0185 μs | 0.0164 μs | 3.308 μs | 1.10 | 0.01 | 2.3499 | - | - | 4,920 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.973 μs | 0.0111 μs | 0.0098 μs | 2.973 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 3.334 μs | 0.0154 μs | 0.0129 μs | 3.332 μs | 1.12 | 0.00 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 3.249 μs | 0.0358 μs | 0.0317 μs | 3.249 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 3.677 μs | 0.0255 μs | 0.0238 μs | 3.670 μs | 1.13 | 0.01 | 2.3499 | - | - | 4,920 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 3.263 μs | 0.0191 μs | 0.0159 μs | 3.266 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 3.481 μs | 0.0174 μs | 0.0163 μs | 3.484 μs | 1.07 | 0.01 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 2.939 μs | 0.0252 μs | 0.0224 μs | 2.930 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 3.302 μs | 0.0110 μs | 0.0092 μs | 3.301 μs | 1.12 | 0.01 | 2.3499 | - | - | 4,920 B | +| Linq_List_Reference | List_Reference | 100 | 3.024 μs | 0.0145 μs | 0.0128 μs | 3.026 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 3.416 μs | 0.0151 μs | 0.0134 μs | 3.415 μs | 1.13 | 0.01 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 11.592 μs | 0.0238 μs | 0.0199 μs | 11.595 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 11.583 μs | 0.0268 μs | 0.0224 μs | 11.582 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | diff --git a/Benchmarks/SelectSumBenchmarks.md b/Benchmarks/SelectSumBenchmarks.md index 9348240e3..e5ce327fb 100644 --- a/Benchmarks/SelectSumBenchmarks.md +++ b/Benchmarks/SelectSumBenchmarks.md @@ -18,44 +18,44 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 646.61 ns | 3.030 ns | 2.686 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 224.11 ns | 0.872 ns | 0.728 ns | 0.35 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 198.38 ns | 0.554 ns | 0.491 ns | 0.31 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 66.40 ns | 0.203 ns | 0.190 ns | 0.10 | - | - | - | - | +| Linq_Array | Array | 100 | 657.60 ns | 4.578 ns | 4.282 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 224.13 ns | 0.642 ns | 0.569 ns | 0.34 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 198.21 ns | 0.524 ns | 0.464 ns | 0.30 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 64.92 ns | 0.260 ns | 0.243 ns | 0.10 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,164.53 ns | 12.105 ns | 11.323 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 761.98 ns | 3.117 ns | 2.763 ns | 0.65 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 226.80 ns | 0.409 ns | 0.362 ns | 0.19 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,170.10 ns | 3.796 ns | 2.964 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 789.21 ns | 4.604 ns | 4.307 ns | 0.67 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 203.36 ns | 0.654 ns | 0.580 ns | 0.17 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,151.16 ns | 4.268 ns | 3.784 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 757.00 ns | 3.107 ns | 2.755 ns | 0.66 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 209.40 ns | 0.830 ns | 0.648 ns | 0.18 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,159.29 ns | 4.584 ns | 4.288 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 784.62 ns | 5.638 ns | 4.998 ns | 0.68 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 232.75 ns | 0.688 ns | 0.610 ns | 0.20 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,160.97 ns | 3.731 ns | 3.490 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 366.61 ns | 1.448 ns | 1.284 ns | 0.32 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 772.26 ns | 3.474 ns | 3.250 ns | 0.67 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,171.90 ns | 7.967 ns | 7.452 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 367.04 ns | 3.394 ns | 3.009 ns | 0.31 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 770.35 ns | 4.159 ns | 3.890 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,088.46 ns | 25.657 ns | 22.744 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,998.94 ns | 4.643 ns | 4.343 ns | 0.28 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,928.20 ns | 14.613 ns | 12.202 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,994.54 ns | 2.713 ns | 2.537 ns | 0.29 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,154.50 ns | 3.956 ns | 3.507 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 787.50 ns | 4.158 ns | 3.686 ns | 0.68 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 756.37 ns | 4.099 ns | 3.634 ns | 0.66 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,180.52 ns | 6.566 ns | 5.821 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 787.10 ns | 4.083 ns | 3.819 ns | 0.67 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 758.40 ns | 3.926 ns | 3.480 ns | 0.64 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,205.65 ns | 11.671 ns | 9.746 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 781.71 ns | 3.806 ns | 3.374 ns | 0.65 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 783.24 ns | 3.150 ns | 2.947 ns | 0.65 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,254.95 ns | 8.594 ns | 7.619 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 755.09 ns | 1.902 ns | 1.779 ns | 0.60 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 763.83 ns | 3.592 ns | 3.184 ns | 0.61 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,211.02 ns | 10.733 ns | 9.515 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 756.32 ns | 3.160 ns | 2.801 ns | 0.62 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 818.50 ns | 2.569 ns | 2.145 ns | 0.68 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,248.97 ns | 4.253 ns | 3.770 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 757.15 ns | 3.574 ns | 3.343 ns | 0.61 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 813.48 ns | 1.671 ns | 1.563 ns | 0.65 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,124.15 ns | 20.434 ns | 18.114 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,821.11 ns | 6.822 ns | 5.697 ns | 0.40 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,076.05 ns | 16.861 ns | 14.947 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,834.07 ns | 6.980 ns | 6.529 ns | 0.40 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectToArrayBenchmarks.md b/Benchmarks/SelectToArrayBenchmarks.md index dfe9dc745..ce63cd1c0 100644 --- a/Benchmarks/SelectToArrayBenchmarks.md +++ b/Benchmarks/SelectToArrayBenchmarks.md @@ -18,45 +18,45 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 240.17 ns | 1.474 ns | 1.306 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | -| StructLinq_Array | Array | 100 | 228.00 ns | 1.364 ns | 1.276 ns | 0.95 | 0.01 | 0.2027 | - | - | 424 B | -| LinqFasterSIMD_Array | Array | 100 | 63.28 ns | 0.716 ns | 0.635 ns | 0.26 | 0.00 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 250.31 ns | 1.640 ns | 1.370 ns | 1.04 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array_SIMD | Array | 100 | 80.24 ns | 0.918 ns | 0.859 ns | 0.33 | 0.00 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,061.43 ns | 11.789 ns | 9.844 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,056.96 ns | 11.352 ns | 8.863 ns | 1.00 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 601.80 ns | 5.579 ns | 4.659 ns | 0.57 | 0.01 | 0.2022 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,093.15 ns | 6.813 ns | 6.373 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,059.03 ns | 8.171 ns | 7.643 ns | 0.97 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 330.50 ns | 1.925 ns | 1.706 ns | 0.30 | 0.00 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 454.75 ns | 2.799 ns | 2.618 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Value | List_Value | 100 | 467.76 ns | 2.420 ns | 2.146 ns | 1.03 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 860.83 ns | 4.320 ns | 4.041 ns | 1.89 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,405.26 ns | 59.048 ns | 46.101 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,357.52 ns | 10.678 ns | 9.988 ns | 0.32 | 0.00 | 0.5646 | - | - | 1,184 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,052.08 ns | 6.421 ns | 6.006 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,066.62 ns | 7.938 ns | 7.425 ns | 1.01 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,069.48 ns | 8.627 ns | 7.648 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,029.58 ns | 6.426 ns | 6.011 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,055.36 ns | 7.970 ns | 7.455 ns | 1.03 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 847.53 ns | 16.213 ns | 15.923 ns | 0.82 | 0.02 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 402.58 ns | 2.603 ns | 2.435 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,058.00 ns | 9.785 ns | 9.153 ns | 2.63 | 0.03 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 835.46 ns | 4.897 ns | 4.341 ns | 2.07 | 0.02 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,655.55 ns | 27.495 ns | 24.373 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,145.23 ns | 10.203 ns | 9.044 ns | 0.41 | 0.00 | 0.5798 | - | - | 1,216 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 263.39 ns | 1.174 ns | 1.041 ns | 263.24 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | +| StructLinq_Array | Array | 100 | 233.94 ns | 4.618 ns | 8.787 ns | 229.90 ns | 0.93 | 0.04 | 0.2027 | - | - | 424 B | +| LinqFasterSIMD_Array | Array | 100 | 66.14 ns | 0.757 ns | 0.671 ns | 66.26 ns | 0.25 | 0.00 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 272.16 ns | 1.452 ns | 1.358 ns | 271.94 ns | 1.03 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array_SIMD | Array | 100 | 83.63 ns | 0.812 ns | 0.720 ns | 83.73 ns | 0.32 | 0.00 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,043.22 ns | 4.723 ns | 4.187 ns | 1,043.66 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,067.19 ns | 7.687 ns | 6.814 ns | 1,066.65 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 592.14 ns | 2.533 ns | 2.369 ns | 592.28 ns | 0.57 | 0.00 | 0.2022 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,044.28 ns | 4.906 ns | 4.589 ns | 1,042.96 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,070.18 ns | 7.330 ns | 6.121 ns | 1,069.23 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 300.70 ns | 1.466 ns | 1.300 ns | 300.77 ns | 0.29 | 0.00 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 474.07 ns | 9.454 ns | 17.988 ns | 461.17 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Value | List_Value | 100 | 496.84 ns | 8.562 ns | 8.009 ns | 499.34 ns | 1.06 | 0.04 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 926.74 ns | 18.420 ns | 24.590 ns | 933.41 ns | 1.94 | 0.07 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,448.67 ns | 26.093 ns | 23.131 ns | 7,454.25 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,347.19 ns | 6.148 ns | 5.450 ns | 2,347.48 ns | 0.32 | 0.00 | 0.5646 | - | - | 1,184 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,039.00 ns | 5.957 ns | 5.573 ns | 1,038.81 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,068.03 ns | 5.654 ns | 5.012 ns | 1,066.01 ns | 1.03 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,066.39 ns | 4.384 ns | 3.886 ns | 1,066.37 ns | 1.03 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,038.34 ns | 6.737 ns | 5.972 ns | 1,037.87 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,061.14 ns | 7.619 ns | 6.754 ns | 1,058.89 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 852.00 ns | 16.759 ns | 13.994 ns | 855.63 ns | 0.82 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 441.69 ns | 8.744 ns | 15.542 ns | 432.00 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,071.63 ns | 5.571 ns | 5.211 ns | 1,069.65 ns | 2.33 | 0.06 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 831.73 ns | 2.493 ns | 1.946 ns | 831.83 ns | 1.80 | 0.02 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,684.56 ns | 48.657 ns | 45.514 ns | 7,685.18 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,149.51 ns | 8.486 ns | 7.523 ns | 3,149.03 ns | 0.41 | 0.00 | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/SelectToListBenchmarks.md b/Benchmarks/SelectToListBenchmarks.md index e2a0dc9d1..ab920775e 100644 --- a/Benchmarks/SelectToListBenchmarks.md +++ b/Benchmarks/SelectToListBenchmarks.md @@ -18,44 +18,44 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 301.67 ns | 1.742 ns | 1.629 ns | 301.60 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | -| StructLinq_Array | Array | 100 | 266.28 ns | 2.173 ns | 2.033 ns | 265.63 ns | 0.88 | 0.01 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 263.51 ns | 2.980 ns | 2.642 ns | 262.95 ns | 0.87 | 0.01 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array_SIMD | Array | 100 | 95.55 ns | 1.976 ns | 4.619 ns | 93.11 ns | 0.31 | 0.01 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,100.41 ns | 8.612 ns | 8.056 ns | 1,096.03 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,096.06 ns | 8.405 ns | 7.019 ns | 1,092.46 ns | 1.00 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 629.32 ns | 3.621 ns | 3.210 ns | 628.59 ns | 0.57 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,025.70 ns | 7.358 ns | 7.227 ns | 1,027.30 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,091.53 ns | 7.158 ns | 6.346 ns | 1,090.35 ns | 1.06 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 283.83 ns | 1.818 ns | 1.701 ns | 284.26 ns | 0.28 | 0.00 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 467.84 ns | 2.783 ns | 2.467 ns | 467.65 ns | 1.00 | 0.00 | 0.2446 | - | - | 512 B | -| StructLinq_List_Value | List_Value | 100 | 410.14 ns | 2.882 ns | 2.407 ns | 410.02 ns | 0.88 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 896.02 ns | 17.827 ns | 28.787 ns | 877.13 ns | 1.97 | 0.05 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,704.94 ns | 78.706 ns | 69.770 ns | 7,691.12 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,479.47 ns | 48.187 ns | 49.484 ns | 2,506.42 ns | 0.32 | 0.01 | 0.5798 | - | - | 1,216 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,148.08 ns | 11.198 ns | 9.926 ns | 1,143.88 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,141.10 ns | 7.857 ns | 7.349 ns | 1,138.74 ns | 0.99 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,136.40 ns | 18.272 ns | 18.764 ns | 1,128.53 ns | 0.99 | 0.02 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,081.12 ns | 14.883 ns | 11.619 ns | 1,076.23 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,096.40 ns | 9.292 ns | 8.237 ns | 1,093.87 ns | 1.01 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 843.01 ns | 6.280 ns | 5.567 ns | 842.28 ns | 0.78 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 511.96 ns | 3.224 ns | 2.858 ns | 511.67 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,100.45 ns | 11.915 ns | 11.145 ns | 1,098.65 ns | 2.15 | 0.03 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 894.44 ns | 17.363 ns | 17.052 ns | 898.46 ns | 1.75 | 0.04 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,508.51 ns | 29.243 ns | 24.419 ns | 7,510.76 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,196.70 ns | 14.145 ns | 12.539 ns | 3,194.85 ns | 0.43 | 0.00 | 0.5951 | - | - | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 320.50 ns | 6.400 ns | 9.773 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | +| StructLinq_Array | Array | 100 | 289.97 ns | 5.679 ns | 7.582 ns | 0.91 | 0.03 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 261.91 ns | 0.801 ns | 0.669 ns | 0.84 | 0.03 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array_SIMD | Array | 100 | 95.19 ns | 0.595 ns | 0.465 ns | 0.31 | 0.01 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,032.92 ns | 9.620 ns | 7.511 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,067.34 ns | 5.047 ns | 4.721 ns | 1.03 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 665.69 ns | 4.053 ns | 3.384 ns | 0.64 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,083.62 ns | 20.187 ns | 33.727 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,099.09 ns | 4.668 ns | 4.367 ns | 1.03 | 0.04 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 324.91 ns | 2.071 ns | 1.729 ns | 0.30 | 0.01 | 0.2179 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 493.88 ns | 3.038 ns | 2.372 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Value | List_Value | 100 | 435.24 ns | 2.380 ns | 2.110 ns | 0.88 | 0.01 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 794.59 ns | 2.815 ns | 2.633 ns | 1.61 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,304.85 ns | 22.550 ns | 19.990 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,538.83 ns | 20.180 ns | 18.876 ns | 0.35 | 0.00 | 0.5798 | - | - | 1,216 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,033.12 ns | 7.173 ns | 5.601 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,089.03 ns | 21.115 ns | 25.931 ns | 1.04 | 0.03 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,128.37 ns | 6.318 ns | 5.910 ns | 1.09 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,111.77 ns | 6.977 ns | 6.185 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,111.52 ns | 22.062 ns | 28.687 ns | 1.01 | 0.03 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 784.16 ns | 3.117 ns | 2.763 ns | 0.71 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 509.97 ns | 2.207 ns | 1.957 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,064.95 ns | 5.469 ns | 5.116 ns | 2.09 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 885.68 ns | 2.860 ns | 2.535 ns | 1.74 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,530.75 ns | 26.527 ns | 23.515 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,319.93 ns | 26.025 ns | 23.071 ns | 0.44 | 0.00 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/SingleBenchmarks.md b/Benchmarks/SingleBenchmarks.md index 608c1a7cc..c4b065b7d 100644 --- a/Benchmarks/SingleBenchmarks.md +++ b/Benchmarks/SingleBenchmarks.md @@ -18,34 +18,34 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------- |-------------------------- |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 12.902 ns | 0.0570 ns | 0.0505 ns | 12.905 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 14.553 ns | 0.0493 ns | 0.0412 ns | 14.552 ns | 1.13 | 0.01 | - | - | - | - | +| Linq_Array | Array | 12.650 ns | 0.0619 ns | 0.0579 ns | 12.631 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 13.997 ns | 0.0338 ns | 0.0282 ns | 13.997 ns | 1.11 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 26.178 ns | 0.1226 ns | 0.1024 ns | 26.166 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 16.540 ns | 0.0497 ns | 0.0441 ns | 16.537 ns | 0.63 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 25.430 ns | 0.0973 ns | 0.0863 ns | 25.441 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 16.824 ns | 0.0445 ns | 0.0372 ns | 16.827 ns | 0.66 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 25.996 ns | 0.1079 ns | 0.0901 ns | 26.006 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 19.269 ns | 0.0717 ns | 0.0671 ns | 19.274 ns | 0.74 | 0.00 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 28.575 ns | 0.1370 ns | 0.1281 ns | 28.622 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 19.161 ns | 0.0675 ns | 0.0632 ns | 19.128 ns | 0.67 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 8.465 ns | 0.0502 ns | 0.0445 ns | 8.468 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 21.993 ns | 0.1262 ns | 0.1054 ns | 21.981 ns | 2.60 | 0.02 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 8.521 ns | 0.0541 ns | 0.0480 ns | 8.511 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 21.722 ns | 0.0978 ns | 0.0867 ns | 21.724 ns | 2.55 | 0.02 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 76.277 ns | 0.2799 ns | 0.2481 ns | 76.248 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 74.208 ns | 0.1987 ns | 0.1551 ns | 74.239 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 26.102 ns | 0.1026 ns | 0.0910 ns | 26.136 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 21.601 ns | 0.4574 ns | 0.6560 ns | 21.870 ns | 0.81 | 0.03 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 25.550 ns | 0.1125 ns | 0.1052 ns | 25.546 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 20.445 ns | 0.1046 ns | 0.0979 ns | 20.438 ns | 0.80 | 0.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 27.082 ns | 0.5695 ns | 0.9975 ns | 27.757 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 18.833 ns | 0.1737 ns | 0.1625 ns | 18.805 ns | 0.69 | 0.02 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 27.198 ns | 0.5710 ns | 0.9849 ns | 26.621 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 20.031 ns | 0.4175 ns | 1.0003 ns | 19.390 ns | 0.76 | 0.04 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 8.446 ns | 0.0465 ns | 0.0413 ns | 8.435 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 22.542 ns | 0.1073 ns | 0.0951 ns | 22.514 ns | 2.67 | 0.02 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 8.611 ns | 0.0424 ns | 0.0376 ns | 8.615 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 21.548 ns | 0.2435 ns | 0.2034 ns | 21.548 ns | 2.50 | 0.02 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 76.279 ns | 1.5123 ns | 1.6810 ns | 76.028 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 73.466 ns | 0.3094 ns | 0.2743 ns | 73.398 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SkipTakeBenchmarks.md b/Benchmarks/SkipTakeBenchmarks.md index 51d689c90..f4fc05d30 100644 --- a/Benchmarks/SkipTakeBenchmarks.md +++ b/Benchmarks/SkipTakeBenchmarks.md @@ -18,50 +18,50 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Skip | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |----- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 100 | 853.98 ns | 8.132 ns | 7.209 ns | 850.86 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| StructLinq_Array | Array | 100 | 100 | 49.84 ns | 0.203 ns | 0.180 ns | 49.85 ns | 0.06 | 0.00 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 100 | 204.17 ns | 0.634 ns | 0.593 ns | 203.91 ns | 0.24 | 0.00 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 100 | 180.97 ns | 1.274 ns | 1.192 ns | 180.47 ns | 0.21 | 0.00 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 100 | 80.31 ns | 0.330 ns | 0.293 ns | 80.27 ns | 0.09 | 0.00 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 100 | 172.94 ns | 0.375 ns | 0.351 ns | 172.94 ns | 0.20 | 0.00 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 100 | 226.21 ns | 0.971 ns | 0.908 ns | 226.01 ns | 0.26 | 0.00 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 176.05 ns | 0.528 ns | 0.441 ns | 175.99 ns | 0.21 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,480.91 ns | 16.136 ns | 14.304 ns | 1,480.87 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 943.84 ns | 3.397 ns | 3.011 ns | 943.48 ns | 0.64 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 469.67 ns | 1.231 ns | 1.091 ns | 469.61 ns | 0.32 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,508.72 ns | 5.482 ns | 4.860 ns | 1,509.01 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 984.25 ns | 6.638 ns | 6.209 ns | 985.39 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 583.37 ns | 4.036 ns | 3.578 ns | 582.54 ns | 0.39 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 100 | 806.46 ns | 4.327 ns | 3.835 ns | 805.79 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Value | List_Value | 100 | 100 | 224.47 ns | 1.092 ns | 1.021 ns | 224.42 ns | 0.28 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 612.75 ns | 2.801 ns | 2.483 ns | 611.98 ns | 0.76 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 219.77 ns | 1.651 ns | 1.464 ns | 219.57 ns | 0.27 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 8,018.11 ns | 40.874 ns | 34.131 ns | 8,007.43 ns | 1.00 | 0.00 | 0.0763 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 4,301.89 ns | 17.554 ns | 15.561 ns | 4,299.62 ns | 0.54 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,488.30 ns | 11.664 ns | 10.340 ns | 1,486.65 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 979.25 ns | 6.183 ns | 5.163 ns | 977.18 ns | 0.66 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,075.79 ns | 5.613 ns | 4.976 ns | 1,075.80 ns | 0.72 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,507.67 ns | 6.986 ns | 5.833 ns | 1,506.12 ns | 1.00 | 0.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 980.01 ns | 6.165 ns | 5.767 ns | 980.92 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 1,361.27 ns | 8.596 ns | 7.620 ns | 1,360.66 ns | 0.90 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 100 | 805.04 ns | 3.290 ns | 2.916 ns | 804.20 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Reference | List_Reference | 100 | 100 | 942.00 ns | 3.220 ns | 2.854 ns | 942.83 ns | 1.17 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 690.20 ns | 18.041 ns | 52.626 ns | 661.15 ns | 0.95 | 0.07 | - | - | - | - | -| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 242.95 ns | 0.928 ns | 0.775 ns | 243.15 ns | 0.30 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 8,025.06 ns | 43.992 ns | 41.150 ns | 8,020.88 ns | 1.00 | 0.00 | 0.0763 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 5,302.52 ns | 12.140 ns | 10.762 ns | 5,301.04 ns | 0.66 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Skip | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |----- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 100 | 917.40 ns | 6.022 ns | 5.029 ns | 1.00 | 0.0458 | - | - | 96 B | +| StructLinq_Array | Array | 100 | 100 | 50.18 ns | 0.154 ns | 0.136 ns | 0.05 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 100 | 203.23 ns | 0.551 ns | 0.515 ns | 0.22 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 100 | 179.89 ns | 0.532 ns | 0.444 ns | 0.20 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 100 | 79.62 ns | 0.389 ns | 0.344 ns | 0.09 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 100 | 169.75 ns | 0.372 ns | 0.330 ns | 0.19 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 100 | 226.10 ns | 0.736 ns | 0.575 ns | 0.25 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 179.65 ns | 1.394 ns | 1.304 ns | 0.20 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,460.61 ns | 6.434 ns | 5.024 ns | 1.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 984.29 ns | 4.626 ns | 4.101 ns | 0.67 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 444.17 ns | 1.463 ns | 1.297 ns | 0.30 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,458.69 ns | 5.730 ns | 5.079 ns | 1.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 977.11 ns | 5.175 ns | 4.321 ns | 0.67 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 582.24 ns | 1.985 ns | 1.857 ns | 0.40 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 100 | 804.69 ns | 3.999 ns | 3.741 ns | 1.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Value | List_Value | 100 | 100 | 224.84 ns | 0.738 ns | 0.616 ns | 0.28 | - | - | - | - | +| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 657.43 ns | 4.149 ns | 3.678 ns | 0.82 | - | - | - | - | +| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 219.18 ns | 1.247 ns | 1.105 ns | 0.27 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 8,311.02 ns | 26.143 ns | 21.831 ns | 1.00 | 0.0763 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 4,337.00 ns | 15.564 ns | 13.797 ns | 0.52 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,459.67 ns | 3.143 ns | 2.454 ns | 1.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 954.07 ns | 6.370 ns | 5.959 ns | 0.65 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,063.69 ns | 6.712 ns | 5.605 ns | 0.73 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,482.71 ns | 5.643 ns | 5.003 ns | 1.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 978.50 ns | 9.557 ns | 8.472 ns | 0.66 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 1,311.83 ns | 5.852 ns | 4.886 ns | 0.88 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 100 | 803.87 ns | 4.946 ns | 4.385 ns | 1.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Reference | List_Reference | 100 | 100 | 977.06 ns | 5.623 ns | 4.984 ns | 1.22 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 625.59 ns | 2.119 ns | 1.769 ns | 0.78 | - | - | - | - | +| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 244.13 ns | 2.158 ns | 1.913 ns | 0.30 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 8,244.44 ns | 37.434 ns | 35.016 ns | 1.00 | 0.0763 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 5,434.69 ns | 20.316 ns | 18.009 ns | 0.66 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SumBenchmarks.md b/Benchmarks/SumBenchmarks.md index 923aaa914..528b091f6 100644 --- a/Benchmarks/SumBenchmarks.md +++ b/Benchmarks/SumBenchmarks.md @@ -18,44 +18,44 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 439.30 ns | 2.853 ns | 2.529 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | Array | 100 | 60.82 ns | 0.115 ns | 0.096 ns | 0.14 | - | - | - | - | -| LinqFasterSIMD_Array | Array | 100 | 10.47 ns | 0.060 ns | 0.053 ns | 0.02 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 21.91 ns | 0.116 ns | 0.103 ns | 0.05 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 633.54 ns | 3.352 ns | 2.971 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 596.97 ns | 2.907 ns | 2.719 ns | 0.94 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 201.72 ns | 0.352 ns | 0.294 ns | 0.32 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 621.90 ns | 3.402 ns | 3.015 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 604.20 ns | 2.209 ns | 1.958 ns | 0.97 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 209.29 ns | 0.466 ns | 0.389 ns | 0.34 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 626.93 ns | 2.667 ns | 2.227 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Value | List_Value | 100 | 222.14 ns | 1.074 ns | 0.952 ns | 0.35 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 660.98 ns | 3.469 ns | 3.075 ns | 1.06 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,613.20 ns | 6.600 ns | 5.851 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 827.48 ns | 1.437 ns | 1.273 ns | 0.51 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 621.20 ns | 1.839 ns | 1.630 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 599.42 ns | 4.674 ns | 4.144 ns | 0.96 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 568.79 ns | 2.844 ns | 2.660 ns | 0.92 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 627.08 ns | 6.018 ns | 5.335 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 602.22 ns | 3.609 ns | 3.014 ns | 0.96 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 603.41 ns | 2.582 ns | 2.415 ns | 0.96 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 629.82 ns | 6.382 ns | 5.658 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Reference | List_Reference | 100 | 601.84 ns | 2.868 ns | 2.683 ns | 0.96 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 630.16 ns | 1.561 ns | 1.219 ns | 1.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,603.92 ns | 4.272 ns | 3.996 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,630.44 ns | 4.742 ns | 4.203 ns | 1.02 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 411.64 ns | 2.148 ns | 1.904 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 60.79 ns | 0.234 ns | 0.196 ns | 0.15 | 0.00 | - | - | - | - | +| LinqFasterSIMD_Array | Array | 100 | 10.55 ns | 0.057 ns | 0.051 ns | 0.03 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 21.71 ns | 0.050 ns | 0.047 ns | 0.05 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 627.54 ns | 3.594 ns | 3.186 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 569.81 ns | 2.575 ns | 2.409 ns | 0.91 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 200.57 ns | 0.525 ns | 0.410 ns | 0.32 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 623.95 ns | 6.534 ns | 5.792 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 596.64 ns | 1.989 ns | 1.661 ns | 0.96 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 208.77 ns | 0.537 ns | 0.448 ns | 0.33 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 620.76 ns | 2.622 ns | 2.190 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 222.64 ns | 0.895 ns | 0.747 ns | 0.36 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 637.95 ns | 5.100 ns | 4.521 ns | 1.03 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,605.31 ns | 3.396 ns | 3.011 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 827.90 ns | 0.962 ns | 0.853 ns | 0.52 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 629.08 ns | 11.723 ns | 12.039 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 568.72 ns | 3.007 ns | 2.813 ns | 0.90 | 0.02 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 626.02 ns | 2.194 ns | 2.052 ns | 1.00 | 0.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 626.42 ns | 4.324 ns | 3.833 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 569.32 ns | 3.324 ns | 3.109 ns | 0.91 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 600.52 ns | 3.186 ns | 2.981 ns | 0.96 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 621.36 ns | 3.587 ns | 2.995 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 572.35 ns | 7.993 ns | 6.674 ns | 0.92 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 631.71 ns | 2.343 ns | 2.192 ns | 1.02 | 0.00 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,614.63 ns | 5.232 ns | 4.894 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,637.74 ns | 4.182 ns | 3.912 ns | 1.01 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ToArrayBenchmarks.md b/Benchmarks/ToArrayBenchmarks.md index 023d182fb..14ac16c85 100644 --- a/Benchmarks/ToArrayBenchmarks.md +++ b/Benchmarks/ToArrayBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-KNWJOT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 54.98 ns | 0.593 ns | 0.555 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Array | Array | 100 | 82.93 ns | 0.638 ns | 0.597 ns | 1.51 | 0.02 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 41.51 ns | 0.543 ns | 0.508 ns | 0.76 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 900.42 ns | 4.320 ns | 4.041 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 873.07 ns | 4.048 ns | 3.787 ns | 0.97 | 0.00 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 535.57 ns | 2.829 ns | 2.363 ns | 0.60 | 0.00 | 0.2213 | - | - | 464 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 46.43 ns | 0.376 ns | 0.293 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 878.77 ns | 3.930 ns | 3.282 ns | 18.93 | 0.13 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 121.55 ns | 0.846 ns | 0.791 ns | 2.62 | 0.02 | 0.2217 | - | - | 464 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 47.51 ns | 0.516 ns | 0.483 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Value | List_Value | 100 | 244.13 ns | 1.457 ns | 1.363 ns | 5.14 | 0.06 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 56.86 ns | 0.542 ns | 0.507 ns | 1.20 | 0.02 | 0.2142 | - | - | 448 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,911.13 ns | 12.300 ns | 11.505 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,158.17 ns | 3.619 ns | 3.209 ns | 0.61 | 0.00 | 0.5646 | - | - | 1,184 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 897.96 ns | 7.465 ns | 5.828 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 894.95 ns | 2.909 ns | 2.721 ns | 1.00 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 981.20 ns | 4.904 ns | 4.095 ns | 1.09 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 48.58 ns | 0.550 ns | 0.514 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 898.17 ns | 5.121 ns | 4.276 ns | 18.47 | 0.24 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 54.82 ns | 0.302 ns | 0.252 ns | 1.13 | 0.01 | 0.2142 | - | - | 448 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 47.35 ns | 0.496 ns | 0.464 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Reference | List_Reference | 100 | 870.05 ns | 2.203 ns | 2.060 ns | 18.38 | 0.19 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 56.16 ns | 1.188 ns | 1.220 ns | 1.18 | 0.03 | 0.2142 | - | - | 448 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,940.27 ns | 11.722 ns | 9.151 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,963.74 ns | 10.000 ns | 9.354 ns | 1.01 | 0.01 | 0.5798 | - | - | 1,216 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 55.19 ns | 0.358 ns | 0.334 ns | 55.11 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Array | Array | 100 | 86.46 ns | 1.273 ns | 1.191 ns | 86.72 ns | 1.57 | 0.02 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 39.77 ns | 0.860 ns | 2.384 ns | 38.63 ns | 0.73 | 0.04 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 912.67 ns | 6.263 ns | 5.858 ns | 910.52 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 914.68 ns | 17.210 ns | 17.673 ns | 922.76 ns | 1.00 | 0.02 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 533.93 ns | 3.817 ns | 3.187 ns | 533.41 ns | 0.58 | 0.01 | 0.2213 | - | - | 464 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 53.90 ns | 0.362 ns | 0.339 ns | 53.84 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 912.65 ns | 6.331 ns | 4.943 ns | 912.21 ns | 16.94 | 0.13 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 123.65 ns | 2.089 ns | 1.954 ns | 123.08 ns | 2.29 | 0.04 | 0.2217 | - | - | 464 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 51.02 ns | 0.731 ns | 0.683 ns | 51.12 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Value | List_Value | 100 | 249.29 ns | 1.904 ns | 1.688 ns | 248.64 ns | 4.89 | 0.08 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 60.35 ns | 1.193 ns | 1.057 ns | 60.58 ns | 1.18 | 0.03 | 0.2142 | - | - | 448 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,909.56 ns | 8.408 ns | 7.865 ns | 1,907.95 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,230.32 ns | 24.459 ns | 27.186 ns | 1,239.69 ns | 0.64 | 0.02 | 0.5646 | - | - | 1,184 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 913.09 ns | 8.407 ns | 7.452 ns | 909.57 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 926.00 ns | 18.334 ns | 21.825 ns | 917.15 ns | 1.00 | 0.02 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,003.28 ns | 19.344 ns | 18.999 ns | 994.88 ns | 1.10 | 0.03 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 50.36 ns | 0.737 ns | 0.959 ns | 50.52 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 877.92 ns | 4.470 ns | 3.962 ns | 877.55 ns | 17.38 | 0.31 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 57.69 ns | 0.846 ns | 0.750 ns | 57.82 ns | 1.14 | 0.03 | 0.2142 | - | - | 448 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 55.39 ns | 0.772 ns | 0.684 ns | 55.34 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Reference | List_Reference | 100 | 917.81 ns | 2.756 ns | 2.152 ns | 918.00 ns | 16.58 | 0.22 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 61.65 ns | 1.291 ns | 1.326 ns | 62.07 ns | 1.11 | 0.02 | 0.2142 | - | - | 448 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,915.98 ns | 5.794 ns | 5.420 ns | 1,913.48 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,069.53 ns | 40.202 ns | 39.484 ns | 2,085.08 ns | 1.08 | 0.02 | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/ToListBenchmarks.md b/Benchmarks/ToListBenchmarks.md index d46d70202..0e51ae742 100644 --- a/Benchmarks/ToListBenchmarks.md +++ b/Benchmarks/ToListBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-GYHESW : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 57.37 ns | 0.391 ns | 0.347 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Array | Array | 100 | 89.36 ns | 0.638 ns | 0.533 ns | 1.56 | 0.01 | 0.2180 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 44.93 ns | 0.294 ns | 0.229 ns | 0.78 | 0.01 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 903.35 ns | 6.611 ns | 6.184 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 911.17 ns | 4.143 ns | 3.673 ns | 1.01 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 587.79 ns | 3.092 ns | 2.741 ns | 0.65 | 0.00 | 0.2365 | - | - | 496 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 51.89 ns | 0.784 ns | 0.733 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 922.14 ns | 7.969 ns | 7.454 ns | 17.78 | 0.32 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 141.96 ns | 0.786 ns | 0.656 ns | 2.73 | 0.04 | 0.2370 | - | - | 496 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 53.18 ns | 0.580 ns | 0.514 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Value | List_Value | 100 | 253.74 ns | 3.019 ns | 2.824 ns | 4.77 | 0.08 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 77.76 ns | 0.632 ns | 0.560 ns | 1.46 | 0.02 | 0.2295 | - | - | 480 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,862.15 ns | 8.393 ns | 7.851 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,210.80 ns | 4.677 ns | 3.906 ns | 0.65 | 0.00 | 0.5798 | - | - | 1,216 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 879.43 ns | 8.114 ns | 6.335 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 921.20 ns | 4.572 ns | 4.277 ns | 1.05 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,036.35 ns | 7.064 ns | 6.262 ns | 1.18 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 52.01 ns | 0.397 ns | 0.331 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 910.52 ns | 3.786 ns | 3.356 ns | 17.50 | 0.12 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 68.43 ns | 0.609 ns | 0.540 ns | 1.32 | 0.01 | 0.2295 | - | - | 480 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 52.21 ns | 0.408 ns | 0.361 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Reference | List_Reference | 100 | 914.68 ns | 6.522 ns | 6.101 ns | 17.53 | 0.15 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 77.22 ns | 1.111 ns | 0.928 ns | 1.48 | 0.02 | 0.2295 | - | - | 480 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,862.73 ns | 9.873 ns | 8.244 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,032.68 ns | 18.738 ns | 17.527 ns | 1.09 | 0.01 | 0.5951 | - | - | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 61.67 ns | 0.616 ns | 0.822 ns | 61.68 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Array | Array | 100 | 92.58 ns | 1.076 ns | 0.954 ns | 92.80 ns | 1.50 | 0.03 | 0.2180 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 47.53 ns | 0.750 ns | 0.626 ns | 47.56 ns | 0.77 | 0.01 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 938.37 ns | 18.802 ns | 37.550 ns | 915.59 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 923.96 ns | 4.179 ns | 3.263 ns | 924.89 ns | 0.97 | 0.04 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 598.19 ns | 4.437 ns | 3.934 ns | 596.98 ns | 0.63 | 0.03 | 0.2365 | - | - | 496 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 55.73 ns | 1.109 ns | 2.700 ns | 54.42 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 967.01 ns | 6.672 ns | 6.241 ns | 967.52 ns | 17.09 | 0.86 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 146.33 ns | 2.101 ns | 1.862 ns | 145.92 ns | 2.60 | 0.13 | 0.2370 | - | - | 496 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 58.00 ns | 1.225 ns | 2.888 ns | 56.54 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Value | List_Value | 100 | 255.08 ns | 0.820 ns | 0.685 ns | 254.91 ns | 4.23 | 0.24 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 81.62 ns | 1.424 ns | 1.262 ns | 81.68 ns | 1.35 | 0.08 | 0.2295 | - | - | 480 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,980.45 ns | 6.761 ns | 6.324 ns | 1,979.57 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,221.63 ns | 6.614 ns | 6.186 ns | 1,221.44 ns | 0.62 | 0.00 | 0.5798 | - | - | 1,216 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 885.62 ns | 5.734 ns | 4.788 ns | 884.69 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 937.51 ns | 4.458 ns | 3.723 ns | 937.76 ns | 1.06 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,073.53 ns | 4.959 ns | 4.639 ns | 1,073.45 ns | 1.21 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 54.97 ns | 0.788 ns | 0.737 ns | 55.20 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 956.73 ns | 18.374 ns | 18.869 ns | 966.16 ns | 17.38 | 0.46 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 71.90 ns | 0.683 ns | 0.533 ns | 71.88 ns | 1.31 | 0.02 | 0.2295 | - | - | 480 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 55.06 ns | 1.145 ns | 0.894 ns | 55.41 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Reference | List_Reference | 100 | 928.99 ns | 4.006 ns | 3.345 ns | 928.35 ns | 16.89 | 0.28 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 81.84 ns | 0.829 ns | 0.775 ns | 81.83 ns | 1.49 | 0.03 | 0.2295 | - | - | 480 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,981.10 ns | 13.008 ns | 12.167 ns | 1,975.18 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,018.26 ns | 6.283 ns | 5.877 ns | 2,017.38 ns | 1.02 | 0.01 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/WhereBenchmarks.md b/Benchmarks/WhereBenchmarks.md index c604309c0..f14c59ae3 100644 --- a/Benchmarks/WhereBenchmarks.md +++ b/Benchmarks/WhereBenchmarks.md @@ -18,45 +18,45 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 476.1 ns | 1.28 ns | 1.00 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 420.7 ns | 2.05 ns | 1.60 ns | 0.88 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 454.9 ns | 8.96 ns | 7.48 ns | 0.96 | 0.02 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 285.2 ns | 3.14 ns | 2.78 ns | 0.60 | 0.01 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 281.9 ns | 3.91 ns | 3.66 ns | 0.59 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,435.5 ns | 4.18 ns | 3.49 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,312.0 ns | 4.36 ns | 3.87 ns | 0.91 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 318.3 ns | 5.67 ns | 4.73 ns | 0.22 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,425.6 ns | 5.94 ns | 4.96 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,250.3 ns | 4.41 ns | 4.12 ns | 0.88 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 457.9 ns | 2.28 ns | 2.02 ns | 0.32 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,424.8 ns | 6.49 ns | 5.75 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 537.2 ns | 6.07 ns | 5.38 ns | 0.38 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1,192.8 ns | 4.17 ns | 3.69 ns | 0.84 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,588.5 ns | 28.72 ns | 25.46 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,824.0 ns | 38.62 ns | 34.24 ns | 1.05 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,472.5 ns | 9.86 ns | 9.23 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,315.8 ns | 5.21 ns | 4.35 ns | 0.89 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,323.7 ns | 12.74 ns | 10.64 ns | 0.90 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,445.5 ns | 4.36 ns | 4.08 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,281.3 ns | 7.90 ns | 7.01 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,201.4 ns | 5.52 ns | 4.90 ns | 0.83 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,486.3 ns | 3.86 ns | 3.61 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,313.5 ns | 4.98 ns | 4.41 ns | 0.88 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,239.1 ns | 5.14 ns | 4.02 ns | 0.83 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,582.2 ns | 12.88 ns | 12.04 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,766.2 ns | 26.21 ns | 20.46 ns | 1.04 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 468.6 ns | 1.69 ns | 1.41 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 293.9 ns | 5.43 ns | 4.24 ns | 0.63 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 459.4 ns | 3.21 ns | 2.84 ns | 0.98 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 281.2 ns | 3.56 ns | 3.33 ns | 0.60 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 292.9 ns | 3.54 ns | 3.31 ns | 0.63 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,316.1 ns | 6.43 ns | 5.70 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,192.8 ns | 6.54 ns | 5.80 ns | 0.91 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 454.0 ns | 5.33 ns | 4.98 ns | 0.34 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,336.9 ns | 7.84 ns | 6.95 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,188.0 ns | 4.55 ns | 4.04 ns | 0.89 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 317.1 ns | 4.24 ns | 3.96 ns | 0.24 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,335.1 ns | 10.22 ns | 9.06 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 520.6 ns | 6.76 ns | 6.00 ns | 0.39 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1,200.0 ns | 4.20 ns | 3.72 ns | 0.90 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,636.3 ns | 16.42 ns | 14.55 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,793.0 ns | 13.00 ns | 12.16 ns | 1.03 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,367.6 ns | 6.31 ns | 5.59 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,210.8 ns | 5.67 ns | 5.03 ns | 0.89 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,204.7 ns | 7.32 ns | 6.11 ns | 0.88 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,353.5 ns | 5.74 ns | 5.09 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,202.1 ns | 4.64 ns | 4.11 ns | 0.89 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,288.8 ns | 3.05 ns | 2.70 ns | 0.95 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,360.9 ns | 5.95 ns | 5.56 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,196.2 ns | 5.49 ns | 4.87 ns | 0.88 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,224.8 ns | 5.59 ns | 5.23 ns | 0.90 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,502.2 ns | 28.22 ns | 23.56 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,763.8 ns | 9.88 ns | 8.76 ns | 1.06 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereCountBenchmarks.md b/Benchmarks/WhereCountBenchmarks.md index a00d88929..4b66d372e 100644 --- a/Benchmarks/WhereCountBenchmarks.md +++ b/Benchmarks/WhereCountBenchmarks.md @@ -18,45 +18,45 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 842.3 ns | 2.02 ns | 1.69 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | Array | 100 | 239.0 ns | 1.77 ns | 1.57 ns | 0.28 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 198.2 ns | 0.82 ns | 0.73 ns | 0.24 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 172.3 ns | 0.81 ns | 0.76 ns | 0.20 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 199.3 ns | 0.45 ns | 0.40 ns | 0.24 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,059.7 ns | 4.74 ns | 4.43 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,030.2 ns | 4.70 ns | 3.92 ns | 0.97 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 223.6 ns | 0.60 ns | 0.50 ns | 0.21 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,075.4 ns | 4.71 ns | 4.17 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,057.9 ns | 4.87 ns | 4.56 ns | 0.98 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 218.1 ns | 0.77 ns | 0.65 ns | 0.20 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,091.3 ns | 7.05 ns | 6.59 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Value | List_Value | 100 | 451.4 ns | 2.28 ns | 2.02 ns | 0.41 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 826.2 ns | 2.40 ns | 2.13 ns | 0.76 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,696.3 ns | 4.29 ns | 3.58 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,488.0 ns | 3.12 ns | 2.77 ns | 1.47 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,080.9 ns | 3.99 ns | 3.54 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,030.4 ns | 4.60 ns | 4.08 ns | 0.95 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 731.4 ns | 2.25 ns | 2.00 ns | 0.68 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,083.8 ns | 6.26 ns | 5.85 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,053.2 ns | 3.79 ns | 3.36 ns | 0.97 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 714.5 ns | 7.96 ns | 6.64 ns | 0.66 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,068.2 ns | 4.53 ns | 4.01 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,045.3 ns | 6.44 ns | 5.71 ns | 0.98 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 781.7 ns | 4.09 ns | 3.62 ns | 0.73 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,689.9 ns | 3.43 ns | 3.04 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,839.4 ns | 4.06 ns | 3.60 ns | 1.68 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 873.0 ns | 2.95 ns | 2.47 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 242.0 ns | 1.88 ns | 1.76 ns | 0.28 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 196.9 ns | 0.45 ns | 0.40 ns | 0.23 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 195.8 ns | 1.04 ns | 0.97 ns | 0.22 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 199.3 ns | 0.57 ns | 0.50 ns | 0.23 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,077.2 ns | 4.67 ns | 4.36 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,041.1 ns | 3.98 ns | 3.33 ns | 0.97 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 230.1 ns | 0.81 ns | 0.72 ns | 0.21 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,076.8 ns | 4.44 ns | 3.94 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,053.5 ns | 5.57 ns | 4.94 ns | 0.98 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 217.9 ns | 0.48 ns | 0.40 ns | 0.20 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,054.6 ns | 3.68 ns | 2.87 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 390.4 ns | 3.54 ns | 3.14 ns | 0.37 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 792.8 ns | 4.47 ns | 3.96 ns | 0.75 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,694.0 ns | 8.28 ns | 6.47 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,498.1 ns | 7.76 ns | 6.88 ns | 1.47 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,051.9 ns | 4.94 ns | 4.38 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,042.0 ns | 3.95 ns | 3.69 ns | 0.99 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 785.9 ns | 4.76 ns | 4.22 ns | 0.75 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,056.8 ns | 6.61 ns | 5.86 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,060.8 ns | 2.81 ns | 2.49 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 740.2 ns | 2.78 ns | 2.47 ns | 0.70 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,081.7 ns | 3.00 ns | 2.66 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,076.2 ns | 3.74 ns | 3.32 ns | 0.99 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 821.9 ns | 4.76 ns | 3.98 ns | 0.76 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,697.4 ns | 4.25 ns | 3.77 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,859.4 ns | 23.48 ns | 19.61 ns | 1.68 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereFirstBenchmarks.md b/Benchmarks/WhereFirstBenchmarks.md index 41229396f..0e39d8e9a 100644 --- a/Benchmarks/WhereFirstBenchmarks.md +++ b/Benchmarks/WhereFirstBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 607.3 ns | 2.67 ns | 2.37 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Array | Array | 100 | 213.5 ns | 3.27 ns | 3.06 ns | 0.35 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 776.9 ns | 3.00 ns | 2.81 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 243.3 ns | 4.84 ns | 5.76 ns | 0.32 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 763.9 ns | 2.67 ns | 2.37 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 241.3 ns | 1.59 ns | 1.41 ns | 0.32 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 797.4 ns | 6.86 ns | 5.36 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Value | List_Value | 100 | 790.3 ns | 2.20 ns | 2.06 ns | 0.99 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,770.0 ns | 5.42 ns | 4.81 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,607.4 ns | 7.50 ns | 6.65 ns | 1.47 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 747.5 ns | 3.38 ns | 2.99 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 753.7 ns | 2.27 ns | 2.12 ns | 1.01 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 751.1 ns | 11.02 ns | 10.30 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 768.9 ns | 2.22 ns | 1.97 ns | 1.02 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 742.8 ns | 10.66 ns | 9.45 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 767.8 ns | 3.95 ns | 3.29 ns | 1.03 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,745.1 ns | 6.89 ns | 6.11 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,868.8 ns | 13.30 ns | 11.79 ns | 1.64 | 0.0458 | - | - | 96 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 627.5 ns | 2.33 ns | 2.18 ns | 627.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Array | Array | 100 | 212.0 ns | 2.89 ns | 5.49 ns | 208.9 ns | 0.34 | 0.01 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 797.9 ns | 5.80 ns | 5.14 ns | 798.9 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 251.0 ns | 1.11 ns | 1.04 ns | 251.2 ns | 0.31 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 765.5 ns | 3.23 ns | 2.87 ns | 765.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 241.9 ns | 1.58 ns | 1.48 ns | 242.0 ns | 0.32 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 783.9 ns | 2.64 ns | 2.21 ns | 784.0 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Value | List_Value | 100 | 793.4 ns | 2.14 ns | 1.79 ns | 793.6 ns | 1.01 | 0.00 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,766.1 ns | 2.88 ns | 2.41 ns | 1,766.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,584.0 ns | 10.26 ns | 9.09 ns | 2,582.8 ns | 1.46 | 0.01 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 797.4 ns | 2.49 ns | 2.33 ns | 796.7 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 792.2 ns | 15.30 ns | 13.56 ns | 789.9 ns | 0.99 | 0.02 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 782.5 ns | 2.91 ns | 2.58 ns | 782.5 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 786.7 ns | 13.69 ns | 31.46 ns | 779.0 ns | 1.05 | 0.07 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 785.6 ns | 2.36 ns | 2.09 ns | 785.7 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 718.2 ns | 4.76 ns | 4.22 ns | 716.3 ns | 0.91 | 0.01 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,759.0 ns | 2.68 ns | 2.38 ns | 1,758.9 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,868.9 ns | 5.06 ns | 4.22 ns | 2,869.9 ns | 1.63 | 0.00 | 0.0458 | - | - | 96 B | diff --git a/Benchmarks/WhereSelectBenchmarks.md b/Benchmarks/WhereSelectBenchmarks.md index 703081eed..ce98e92ce 100644 --- a/Benchmarks/WhereSelectBenchmarks.md +++ b/Benchmarks/WhereSelectBenchmarks.md @@ -18,45 +18,45 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 685.4 ns | 5.29 ns | 4.69 ns | 1.00 | 0.0496 | - | - | 104 B | -| StructLinq_Array | Array | 100 | 341.1 ns | 4.00 ns | 3.55 ns | 0.50 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 320.2 ns | 2.11 ns | 1.76 ns | 0.47 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 342.0 ns | 1.98 ns | 1.76 ns | 0.50 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 311.5 ns | 1.76 ns | 1.56 ns | 0.45 | - | - | - | - | +| Linq_Array | Array | 100 | 692.8 ns | 5.17 ns | 4.84 ns | 1.00 | 0.0496 | - | - | 104 B | +| StructLinq_Array | Array | 100 | 370.8 ns | 2.77 ns | 2.59 ns | 0.54 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 358.4 ns | 1.84 ns | 1.53 ns | 0.52 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 341.0 ns | 1.43 ns | 1.34 ns | 0.49 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 336.9 ns | 1.61 ns | 1.35 ns | 0.49 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,534.6 ns | 6.02 ns | 5.33 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,295.4 ns | 7.73 ns | 6.45 ns | 0.84 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 344.9 ns | 1.64 ns | 1.54 ns | 0.22 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,486.0 ns | 6.89 ns | 5.38 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,265.8 ns | 6.77 ns | 6.00 ns | 0.85 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 342.3 ns | 1.31 ns | 1.16 ns | 0.23 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,534.1 ns | 6.13 ns | 4.79 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,314.8 ns | 5.35 ns | 5.01 ns | 0.86 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 337.7 ns | 1.82 ns | 1.52 ns | 0.22 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,485.4 ns | 2.99 ns | 2.49 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,291.8 ns | 3.76 ns | 3.14 ns | 0.87 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 339.0 ns | 0.96 ns | 0.85 ns | 0.23 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,560.1 ns | 6.92 ns | 5.78 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Value | List_Value | 100 | 641.5 ns | 2.23 ns | 2.09 ns | 0.41 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1,309.6 ns | 7.32 ns | 6.49 ns | 0.84 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,519.6 ns | 24.52 ns | 21.73 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Value | List_Value | 100 | 696.3 ns | 3.43 ns | 3.04 ns | 0.46 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1,317.8 ns | 4.96 ns | 4.39 ns | 0.87 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,566.5 ns | 18.63 ns | 16.51 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,182.6 ns | 15.41 ns | 13.66 ns | 1.13 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,629.5 ns | 23.72 ns | 21.03 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,201.4 ns | 6.04 ns | 5.36 ns | 1.12 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,536.6 ns | 11.02 ns | 10.30 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,263.9 ns | 4.48 ns | 3.97 ns | 0.82 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,305.1 ns | 8.92 ns | 7.91 ns | 0.85 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,499.3 ns | 11.27 ns | 10.54 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,298.5 ns | 8.18 ns | 7.65 ns | 0.87 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,312.7 ns | 4.97 ns | 4.41 ns | 0.88 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,539.3 ns | 9.95 ns | 8.82 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,340.1 ns | 4.31 ns | 3.82 ns | 0.87 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,303.3 ns | 5.44 ns | 4.54 ns | 0.85 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,504.2 ns | 7.78 ns | 6.50 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,292.6 ns | 5.53 ns | 4.90 ns | 0.86 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,243.6 ns | 8.12 ns | 7.20 ns | 0.83 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,507.4 ns | 7.45 ns | 6.60 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,317.5 ns | 7.39 ns | 6.17 ns | 0.87 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,316.8 ns | 7.71 ns | 7.21 ns | 0.87 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,506.1 ns | 3.78 ns | 3.35 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,289.9 ns | 4.44 ns | 3.71 ns | 0.86 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,249.5 ns | 6.35 ns | 5.63 ns | 0.83 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,638.1 ns | 14.50 ns | 12.85 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,311.7 ns | 22.40 ns | 20.96 ns | 1.15 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,572.8 ns | 8.97 ns | 7.95 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,252.3 ns | 17.50 ns | 15.52 ns | 1.15 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereSelectCountBenchmarks.md b/Benchmarks/WhereSelectCountBenchmarks.md index 77fd0e860..d6dae2c74 100644 --- a/Benchmarks/WhereSelectCountBenchmarks.md +++ b/Benchmarks/WhereSelectCountBenchmarks.md @@ -18,36 +18,36 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 340.2 ns | 1.68 ns | 1.49 ns | 1.00 | 0.0496 | - | - | 104 B | -| Hyperlinq_Array | Array | 100 | 207.8 ns | 0.89 ns | 0.83 ns | 0.61 | - | - | - | - | +| Linq_Array | Array | 100 | 351.2 ns | 4.93 ns | 4.11 ns | 1.00 | 0.0496 | - | - | 104 B | +| Hyperlinq_Array | Array | 100 | 205.3 ns | 0.54 ns | 0.48 ns | 0.58 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,227.6 ns | 3.23 ns | 2.86 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 223.6 ns | 1.07 ns | 0.90 ns | 0.18 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,201.9 ns | 5.46 ns | 4.84 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 233.7 ns | 0.83 ns | 0.74 ns | 0.19 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,213.9 ns | 6.79 ns | 6.02 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 244.9 ns | 0.98 ns | 0.82 ns | 0.20 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,163.1 ns | 6.69 ns | 6.26 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 226.7 ns | 1.15 ns | 1.02 ns | 0.19 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,217.0 ns | 8.90 ns | 7.43 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Value | List_Value | 100 | 825.4 ns | 3.13 ns | 2.93 ns | 0.68 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,190.5 ns | 3.39 ns | 3.17 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Value | List_Value | 100 | 790.1 ns | 5.03 ns | 4.46 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,807.9 ns | 13.21 ns | 11.71 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,502.3 ns | 4.88 ns | 4.57 ns | 0.52 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,784.1 ns | 15.70 ns | 13.92 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,498.6 ns | 5.24 ns | 4.90 ns | 0.52 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,161.1 ns | 7.68 ns | 6.80 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 736.1 ns | 2.98 ns | 2.79 ns | 0.63 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,238.5 ns | 4.32 ns | 3.83 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 743.7 ns | 3.76 ns | 3.52 ns | 0.60 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,238.9 ns | 7.04 ns | 5.88 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 756.8 ns | 2.86 ns | 2.53 ns | 0.61 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,219.2 ns | 5.79 ns | 5.42 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 766.8 ns | 4.34 ns | 3.85 ns | 0.63 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,218.8 ns | 5.17 ns | 4.58 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 798.9 ns | 2.40 ns | 2.00 ns | 0.66 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,207.0 ns | 3.77 ns | 3.53 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 743.7 ns | 2.69 ns | 2.51 ns | 0.62 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,858.8 ns | 17.22 ns | 13.44 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,826.6 ns | 7.05 ns | 5.89 ns | 0.58 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,810.9 ns | 21.97 ns | 19.47 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,827.4 ns | 7.57 ns | 7.08 ns | 0.59 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereSingleBenchmarks.md b/Benchmarks/WhereSingleBenchmarks.md index c08836cfa..9fab9546e 100644 --- a/Benchmarks/WhereSingleBenchmarks.md +++ b/Benchmarks/WhereSingleBenchmarks.md @@ -18,34 +18,34 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-SUCOWF : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------- |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 594.5 ns | 5.05 ns | 4.72 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Array | Array | 100 | 189.5 ns | 2.34 ns | 1.95 ns | 0.32 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 717.0 ns | 3.46 ns | 3.07 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 261.6 ns | 4.08 ns | 4.00 ns | 0.37 | 0.01 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 784.2 ns | 5.06 ns | 4.73 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 269.9 ns | 1.43 ns | 1.27 ns | 0.34 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 754.6 ns | 3.91 ns | 3.06 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Value | List_Value | 100 | 751.4 ns | 3.06 ns | 2.86 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,727.5 ns | 5.56 ns | 4.92 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 756.5 ns | 2.78 ns | 2.46 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 775.9 ns | 7.57 ns | 6.71 ns | 1.03 | 0.01 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 730.3 ns | 6.58 ns | 6.15 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 880.0 ns | 17.50 ns | 39.87 ns | 1.20 | 0.04 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 780.9 ns | 3.25 ns | 2.88 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,351.5 ns | 24.31 ns | 22.74 ns | 1.73 | 0.03 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,721.3 ns | 5.21 ns | 4.87 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------- |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 581.4 ns | 3.08 ns | 2.73 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Array | Array | 100 | 206.9 ns | 0.43 ns | 0.36 ns | 0.36 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 772.8 ns | 3.58 ns | 2.99 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 272.4 ns | 3.12 ns | 2.92 ns | 0.35 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 768.0 ns | 4.02 ns | 3.56 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 266.1 ns | 4.52 ns | 4.01 ns | 0.35 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 782.0 ns | 4.00 ns | 3.55 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Value | List_Value | 100 | 774.0 ns | 2.94 ns | 2.61 ns | 0.99 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,741.8 ns | 5.26 ns | 4.67 ns | 1.00 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 779.5 ns | 2.88 ns | 2.69 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 763.2 ns | 3.25 ns | 2.88 ns | 0.98 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 795.6 ns | 3.08 ns | 2.73 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 749.0 ns | 2.92 ns | 2.59 ns | 0.94 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 807.1 ns | 5.97 ns | 5.29 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 824.7 ns | 3.38 ns | 3.00 ns | 1.02 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,714.4 ns | 2.55 ns | 1.99 ns | 1.00 | 0.0458 | - | - | 96 B | diff --git a/Benchmarks/WhereToArrayBenchmarks.md b/Benchmarks/WhereToArrayBenchmarks.md index f23e15b4a..af1af5720 100644 --- a/Benchmarks/WhereToArrayBenchmarks.md +++ b/Benchmarks/WhereToArrayBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 422.3 ns | 2.77 ns | 3.70 ns | 1.00 | 0.3519 | - | - | 736 B | -| StructLinq_Array | Array | 100 | 383.3 ns | 4.13 ns | 3.22 ns | 0.91 | 0.1144 | - | - | 240 B | -| Hyperlinq_Array | Array | 100 | 491.6 ns | 3.63 ns | 3.22 ns | 1.16 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,199.4 ns | 6.52 ns | 6.10 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,186.0 ns | 9.77 ns | 9.14 ns | 0.99 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 537.9 ns | 4.76 ns | 4.22 ns | 0.45 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,298.6 ns | 9.64 ns | 8.54 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,170.7 ns | 6.78 ns | 6.34 ns | 0.90 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 515.4 ns | 5.29 ns | 4.69 ns | 0.40 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,213.6 ns | 8.77 ns | 7.32 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Value | List_Value | 100 | 780.8 ns | 3.00 ns | 2.66 ns | 0.64 | 0.1144 | - | - | 240 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,329.0 ns | 7.30 ns | 6.83 ns | 1.09 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,221.4 ns | 22.19 ns | 20.76 ns | 1.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,840.5 ns | 13.40 ns | 12.54 ns | 0.54 | 0.3357 | - | - | 720 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,233.9 ns | 13.13 ns | 11.64 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,206.8 ns | 8.06 ns | 7.54 ns | 0.98 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,302.2 ns | 6.70 ns | 5.94 ns | 1.06 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,217.6 ns | 9.87 ns | 8.25 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,277.6 ns | 7.94 ns | 7.42 ns | 1.05 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,246.8 ns | 9.89 ns | 8.77 ns | 1.02 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,284.5 ns | 11.96 ns | 11.19 ns | 1.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,205.9 ns | 9.25 ns | 8.20 ns | 0.94 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,336.7 ns | 8.06 ns | 7.54 ns | 1.04 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,142.1 ns | 42.67 ns | 39.91 ns | 1.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,482.6 ns | 11.37 ns | 10.08 ns | 0.68 | 0.3548 | - | - | 752 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 428.2 ns | 2.40 ns | 1.87 ns | 428.3 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | +| StructLinq_Array | Array | 100 | 407.5 ns | 2.14 ns | 1.79 ns | 407.6 ns | 0.95 | 0.01 | 0.1144 | - | - | 240 B | +| Hyperlinq_Array | Array | 100 | 479.2 ns | 9.36 ns | 12.50 ns | 486.3 ns | 1.10 | 0.03 | 0.1144 | - | - | 240 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,263.4 ns | 5.52 ns | 5.16 ns | 1,262.6 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,214.8 ns | 8.79 ns | 7.34 ns | 1,215.2 ns | 0.96 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 521.3 ns | 3.21 ns | 3.00 ns | 522.0 ns | 0.41 | 0.00 | 0.1144 | - | - | 240 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,198.9 ns | 6.14 ns | 5.13 ns | 1,197.5 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,219.9 ns | 7.23 ns | 6.77 ns | 1,219.3 ns | 1.02 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 511.7 ns | 3.86 ns | 3.22 ns | 511.4 ns | 0.43 | 0.00 | 0.1144 | - | - | 240 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,204.2 ns | 11.07 ns | 9.81 ns | 1,201.8 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Value | List_Value | 100 | 784.4 ns | 4.47 ns | 3.73 ns | 782.6 ns | 0.65 | 0.01 | 0.1144 | - | - | 240 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,378.5 ns | 7.58 ns | 7.09 ns | 1,377.8 ns | 1.14 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,166.4 ns | 63.82 ns | 56.57 ns | 5,169.3 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,864.9 ns | 6.51 ns | 5.77 ns | 2,864.0 ns | 0.55 | 0.01 | 0.3433 | - | - | 720 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,272.1 ns | 23.51 ns | 20.84 ns | 1,276.1 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,213.1 ns | 3.32 ns | 2.94 ns | 1,213.4 ns | 0.95 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,276.6 ns | 5.85 ns | 5.19 ns | 1,275.2 ns | 1.00 | 0.02 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,209.8 ns | 7.05 ns | 6.25 ns | 1,208.3 ns | 1.00 | 0.00 | 0.3681 | - | - | 776 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,256.2 ns | 13.17 ns | 12.32 ns | 1,259.2 ns | 1.04 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,253.4 ns | 4.26 ns | 3.55 ns | 1,253.6 ns | 1.04 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,250.0 ns | 24.34 ns | 25.00 ns | 1,259.9 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,227.7 ns | 23.37 ns | 22.95 ns | 1,215.7 ns | 0.98 | 0.04 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,378.1 ns | 15.40 ns | 14.41 ns | 1,380.6 ns | 1.11 | 0.02 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,982.8 ns | 81.41 ns | 76.15 ns | 4,932.3 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,509.2 ns | 9.72 ns | 7.59 ns | 3,509.3 ns | 0.70 | 0.01 | 0.3548 | - | - | 752 B | diff --git a/Benchmarks/WhereToListBenchmarks.md b/Benchmarks/WhereToListBenchmarks.md index 9deaeb555..7d7895144 100644 --- a/Benchmarks/WhereToListBenchmarks.md +++ b/Benchmarks/WhereToListBenchmarks.md @@ -18,43 +18,43 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.4.21255.9 [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-DUCAQD : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT + Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 357.3 ns | 2.79 ns | 2.61 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | -| StructLinq_Array | Array | 100 | 416.0 ns | 3.34 ns | 2.96 ns | 1.16 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Array | Array | 100 | 495.6 ns | 3.58 ns | 3.34 ns | 1.39 | 0.02 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,164.2 ns | 7.83 ns | 6.94 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,210.6 ns | 7.88 ns | 7.37 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 562.4 ns | 4.80 ns | 4.49 ns | 0.48 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,167.3 ns | 9.75 ns | 9.12 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,211.0 ns | 7.99 ns | 7.47 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 533.1 ns | 5.77 ns | 4.81 ns | 0.46 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,162.8 ns | 10.44 ns | 9.77 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Value | List_Value | 100 | 796.9 ns | 4.09 ns | 3.83 ns | 0.69 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,372.0 ns | 9.32 ns | 8.27 ns | 1.18 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,113.3 ns | 21.94 ns | 20.52 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,916.5 ns | 13.42 ns | 11.89 ns | 0.57 | 0.00 | 0.3586 | - | - | 752 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,144.9 ns | 9.20 ns | 8.61 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,194.5 ns | 7.04 ns | 6.59 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,360.4 ns | 6.28 ns | 5.87 ns | 1.19 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,165.1 ns | 5.31 ns | 4.44 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,228.7 ns | 24.06 ns | 21.33 ns | 1.06 | 0.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,325.4 ns | 9.43 ns | 8.36 ns | 1.14 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,163.3 ns | 10.51 ns | 8.20 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,188.0 ns | 8.48 ns | 7.94 ns | 1.02 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,377.3 ns | 6.38 ns | 5.33 ns | 1.18 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,962.1 ns | 25.57 ns | 23.92 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,583.2 ns | 11.66 ns | 10.34 ns | 0.72 | 0.00 | 0.3738 | - | - | 784 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 373.3 ns | 2.27 ns | 2.01 ns | 372.5 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | +| StructLinq_Array | Array | 100 | 433.8 ns | 8.41 ns | 10.94 ns | 437.8 ns | 1.15 | 0.03 | 0.1297 | - | - | 272 B | +| Hyperlinq_Array | Array | 100 | 505.5 ns | 4.81 ns | 4.26 ns | 505.0 ns | 1.35 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,214.5 ns | 24.06 ns | 32.12 ns | 1,229.1 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,215.9 ns | 4.24 ns | 3.76 ns | 1,217.0 ns | 1.02 | 0.03 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 595.6 ns | 11.89 ns | 15.03 ns | 601.2 ns | 0.49 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,134.4 ns | 17.77 ns | 16.62 ns | 1,129.1 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,204.6 ns | 5.24 ns | 4.64 ns | 1,204.5 ns | 1.06 | 0.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 547.6 ns | 10.83 ns | 14.83 ns | 539.4 ns | 0.49 | 0.01 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,185.0 ns | 5.28 ns | 4.94 ns | 1,186.8 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Value | List_Value | 100 | 833.5 ns | 12.80 ns | 11.35 ns | 838.7 ns | 0.70 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,341.0 ns | 4.99 ns | 4.16 ns | 1,340.4 ns | 1.13 | 0.01 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,001.7 ns | 12.64 ns | 11.83 ns | 4,997.4 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,917.6 ns | 8.45 ns | 7.90 ns | 2,916.6 ns | 0.58 | 0.00 | 0.3586 | - | - | 752 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,195.3 ns | 5.12 ns | 4.54 ns | 1,194.5 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,209.6 ns | 4.29 ns | 3.81 ns | 1,208.7 ns | 1.01 | 0.00 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,340.5 ns | 15.32 ns | 14.33 ns | 1,343.2 ns | 1.12 | 0.01 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,130.9 ns | 6.35 ns | 5.63 ns | 1,130.3 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,282.0 ns | 15.81 ns | 14.02 ns | 1,283.2 ns | 1.13 | 0.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,328.9 ns | 6.41 ns | 5.35 ns | 1,328.5 ns | 1.18 | 0.01 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,136.4 ns | 5.65 ns | 5.28 ns | 1,135.3 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,239.8 ns | 23.55 ns | 22.03 ns | 1,246.9 ns | 1.09 | 0.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,323.3 ns | 3.51 ns | 3.11 ns | 1,323.2 ns | 1.16 | 0.01 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,943.3 ns | 23.97 ns | 21.25 ns | 4,938.7 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,667.0 ns | 34.22 ns | 30.34 ns | 3,672.5 ns | 0.74 | 0.01 | 0.3738 | - | - | 784 B | From 4d75ba9bec5338851ee6c1cfc586ab8e1eaf0d12 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Fri, 18 Jun 2021 08:30:48 +0100 Subject: [PATCH 37/61] Update benchmark results for .NET 6.0 Preview 5 --- Benchmarks/AggressiveInliningBenchmarks.md | 14 ++-- Benchmarks/AllBenchmarks.md | 46 ++++++------ Benchmarks/AnyBenchmarks.md | 66 ++++++++--------- Benchmarks/AnyPredicateBenchmarks.md | 66 ++++++++--------- Benchmarks/ArrayIterationBenchmarks.md | 26 +++---- Benchmarks/ArrayToArrayBenchmarks.md | 34 ++++----- Benchmarks/ContainsBenchmarks.md | 48 ++++++------- Benchmarks/ContainsComparerBenchmarks.md | 46 ++++++------ Benchmarks/CountBenchmarks.md | 60 ++++++++-------- Benchmarks/DistinctBenchmarks.md | 84 +++++++++++----------- Benchmarks/ElementAtBenchmarks.md | 46 ++++++------ Benchmarks/EmptyBenchmarks.md | 24 +++---- Benchmarks/FirstBenchmarks.md | 46 ++++++------ Benchmarks/ListIterationBenchmarks.md | 26 +++---- Benchmarks/RangeBenchmarks.md | 26 +++---- Benchmarks/RangeToArrayBenchmarks.md | 22 +++--- Benchmarks/ReadOnlyFieldsBenchmarks.md | 16 ++--- Benchmarks/RepeatBenchmarks.md | 20 +++--- Benchmarks/RepeatToArrayBenchmarks.md | 24 +++---- Benchmarks/ReturnBenchmarks.md | 18 ++--- Benchmarks/SelectBenchmarks.md | 70 +++++++++--------- Benchmarks/SelectCountBenchmarks.md | 60 ++++++++-------- Benchmarks/SelectManyBenchmarks.md | 44 ++++++------ Benchmarks/SelectSumBenchmarks.md | 62 ++++++++-------- Benchmarks/SelectToArrayBenchmarks.md | 84 +++++++++++----------- Benchmarks/SelectToListBenchmarks.md | 82 ++++++++++----------- Benchmarks/SingleBenchmarks.md | 42 +++++------ Benchmarks/SkipTakeBenchmarks.md | 74 +++++++++---------- Benchmarks/SumBenchmarks.md | 82 ++++++++++----------- Benchmarks/ToArrayBenchmarks.md | 60 ++++++++-------- Benchmarks/ToListBenchmarks.md | 60 ++++++++-------- Benchmarks/WhereBenchmarks.md | 64 ++++++++--------- Benchmarks/WhereCountBenchmarks.md | 64 ++++++++--------- Benchmarks/WhereFirstBenchmarks.md | 66 ++++++++--------- Benchmarks/WhereSelectBenchmarks.md | 64 ++++++++--------- Benchmarks/WhereSelectCountBenchmarks.md | 46 ++++++------ Benchmarks/WhereSingleBenchmarks.md | 62 ++++++++-------- Benchmarks/WhereToArrayBenchmarks.md | 60 ++++++++-------- Benchmarks/WhereToListBenchmarks.md | 80 ++++++++++----------- 39 files changed, 992 insertions(+), 992 deletions(-) diff --git a/Benchmarks/AggressiveInliningBenchmarks.md b/Benchmarks/AggressiveInliningBenchmarks.md index 2da4e3e00..c9c638a13 100644 --- a/Benchmarks/AggressiveInliningBenchmarks.md +++ b/Benchmarks/AggressiveInliningBenchmarks.md @@ -4,7 +4,7 @@ [AggressiveInliningBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AggressiveInliningBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,16 +14,16 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------- |------ |---------:|--------:|--------:|------:|------:|------:|------:|----------:| -| Baseline | 1000 | 544.6 ns | 1.40 ns | 1.31 ns | 1.00 | - | - | - | - | -| AggressiveInlining | 1000 | 544.5 ns | 1.31 ns | 1.22 ns | 1.00 | - | - | - | - | +| Baseline | 1000 | 545.7 ns | 1.04 ns | 0.97 ns | 1.00 | - | - | - | - | +| AggressiveInlining | 1000 | 544.8 ns | 1.32 ns | 1.24 ns | 1.00 | - | - | - | - | diff --git a/Benchmarks/AllBenchmarks.md b/Benchmarks/AllBenchmarks.md index 7bf8b624b..e8de02988 100644 --- a/Benchmarks/AllBenchmarks.md +++ b/Benchmarks/AllBenchmarks.md @@ -4,7 +4,7 @@ [AllBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AllBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 572.2 ns | 1.87 ns | 1.75 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 192.5 ns | 0.42 ns | 0.32 ns | 0.34 | - | - | - | - | +| Linq_Array | Array | 100 | 594.4 ns | 2.87 ns | 2.24 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 193.1 ns | 0.79 ns | 0.66 ns | 0.32 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 747.7 ns | 3.46 ns | 3.23 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 251.7 ns | 2.46 ns | 2.06 ns | 0.34 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 778.5 ns | 2.27 ns | 1.77 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 226.0 ns | 1.07 ns | 0.95 ns | 0.29 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 718.6 ns | 2.04 ns | 1.70 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 227.8 ns | 1.26 ns | 0.98 ns | 0.32 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 792.8 ns | 3.27 ns | 2.73 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 228.5 ns | 1.08 ns | 1.01 ns | 0.29 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 748.4 ns | 2.83 ns | 2.65 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 800.2 ns | 3.46 ns | 3.06 ns | 1.07 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 795.6 ns | 3.95 ns | 3.69 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 783.9 ns | 8.51 ns | 7.10 ns | 0.99 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,704.2 ns | 4.02 ns | 3.76 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 246.4 ns | 0.99 ns | 0.93 ns | 0.14 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,713.6 ns | 7.04 ns | 5.88 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 248.1 ns | 1.01 ns | 0.95 ns | 0.14 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 796.2 ns | 4.19 ns | 3.27 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 752.0 ns | 3.58 ns | 2.80 ns | 0.94 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 787.9 ns | 3.26 ns | 2.89 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 779.3 ns | 6.61 ns | 5.86 ns | 0.99 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 769.8 ns | 2.45 ns | 2.29 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 777.8 ns | 2.36 ns | 2.21 ns | 1.01 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 746.7 ns | 2.31 ns | 2.16 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 806.8 ns | 3.82 ns | 3.19 ns | 1.08 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 768.8 ns | 2.81 ns | 2.63 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 727.3 ns | 2.27 ns | 1.89 ns | 0.95 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 749.4 ns | 5.37 ns | 4.49 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 728.0 ns | 1.89 ns | 1.58 ns | 0.97 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,706.0 ns | 6.93 ns | 5.79 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 278.3 ns | 4.39 ns | 3.43 ns | 0.16 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,712.4 ns | 6.90 ns | 6.45 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 296.8 ns | 5.57 ns | 4.94 ns | 0.17 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyBenchmarks.md b/Benchmarks/AnyBenchmarks.md index 0222a8faa..86b323c10 100644 --- a/Benchmarks/AnyBenchmarks.md +++ b/Benchmarks/AnyBenchmarks.md @@ -4,7 +4,7 @@ [AnyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 9.590 ns | 0.0432 ns | 0.0404 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 7.353 ns | 0.0171 ns | 0.0151 ns | 0.77 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 21.520 ns | 0.0869 ns | 0.0770 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 10.790 ns | 0.0148 ns | 0.0131 ns | 0.50 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.489 ns | 0.0273 ns | 0.0242 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.174 ns | 0.0188 ns | 0.0157 ns | 1.82 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 5.502 ns | 0.0280 ns | 0.0262 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.805 ns | 0.0116 ns | 0.0109 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 57.348 ns | 0.1576 ns | 0.1231 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 49.700 ns | 0.1463 ns | 0.1368 ns | 0.87 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 20.285 ns | 0.1133 ns | 0.1060 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 13.271 ns | 0.0641 ns | 0.0600 ns | 0.65 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.150 ns | 0.0274 ns | 0.0256 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.805 ns | 0.0103 ns | 0.0086 ns | 0.44 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 5.473 ns | 0.0289 ns | 0.0241 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.554 ns | 0.0097 ns | 0.0076 ns | 0.28 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 56.307 ns | 0.1674 ns | 0.1398 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 53.848 ns | 0.1764 ns | 0.1650 ns | 0.96 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 8.522 ns | 0.1072 ns | 0.0950 ns | 8.489 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 8.337 ns | 0.1458 ns | 0.2591 ns | 8.220 ns | 0.99 | 0.04 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 20.939 ns | 0.3606 ns | 0.3196 ns | 20.920 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 10.763 ns | 0.0420 ns | 0.0372 ns | 10.761 ns | 0.51 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 4.172 ns | 0.0261 ns | 0.0232 ns | 4.170 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 8.238 ns | 0.0348 ns | 0.0308 ns | 8.232 ns | 1.97 | 0.02 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 5.244 ns | 0.0159 ns | 0.0141 ns | 5.245 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.570 ns | 0.0114 ns | 0.0101 ns | 1.570 ns | 0.30 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 56.214 ns | 0.3040 ns | 0.2539 ns | 56.183 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 50.317 ns | 0.1716 ns | 0.1433 ns | 50.332 ns | 0.90 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 20.843 ns | 0.2172 ns | 0.1814 ns | 20.827 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 13.088 ns | 0.0794 ns | 0.0704 ns | 13.070 ns | 0.63 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.156 ns | 0.0202 ns | 0.0189 ns | 4.153 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.564 ns | 0.0159 ns | 0.0141 ns | 1.562 ns | 0.38 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 5.329 ns | 0.1381 ns | 0.1224 ns | 5.288 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.811 ns | 0.0220 ns | 0.0195 ns | 1.804 ns | 0.34 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 56.362 ns | 0.1850 ns | 0.1640 ns | 56.408 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 54.655 ns | 0.1620 ns | 0.1436 ns | 54.680 ns | 0.97 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/AnyPredicateBenchmarks.md b/Benchmarks/AnyPredicateBenchmarks.md index 737fce954..c579f5e28 100644 --- a/Benchmarks/AnyPredicateBenchmarks.md +++ b/Benchmarks/AnyPredicateBenchmarks.md @@ -4,7 +4,7 @@ [AnyPredicateBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 537.58 ns | 3.047 ns | 2.701 ns | 537.74 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 166.76 ns | 0.534 ns | 0.499 ns | 166.71 ns | 0.31 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 767.35 ns | 2.732 ns | 2.422 ns | 766.53 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 249.94 ns | 0.932 ns | 0.827 ns | 249.91 ns | 0.33 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 792.83 ns | 2.970 ns | 2.480 ns | 792.78 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 227.64 ns | 0.582 ns | 0.545 ns | 227.63 ns | 0.29 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 763.82 ns | 1.738 ns | 1.541 ns | 763.47 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 779.76 ns | 3.727 ns | 3.112 ns | 779.99 ns | 1.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,702.31 ns | 2.336 ns | 2.185 ns | 1,702.68 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 73.88 ns | 0.269 ns | 0.225 ns | 73.90 ns | 0.04 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 725.40 ns | 1.927 ns | 1.708 ns | 725.53 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 723.70 ns | 2.657 ns | 2.356 ns | 723.45 ns | 1.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 724.58 ns | 2.336 ns | 2.186 ns | 724.67 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 781.68 ns | 2.340 ns | 1.954 ns | 781.48 ns | 1.08 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 749.57 ns | 2.836 ns | 2.653 ns | 749.41 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 735.02 ns | 5.117 ns | 4.536 ns | 733.78 ns | 0.98 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,744.06 ns | 34.593 ns | 63.255 ns | 1,711.18 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 76.47 ns | 0.218 ns | 0.204 ns | 76.39 ns | 0.04 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 552.35 ns | 3.072 ns | 2.873 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 193.02 ns | 0.522 ns | 0.488 ns | 0.35 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 728.49 ns | 1.738 ns | 1.540 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 227.33 ns | 1.183 ns | 1.107 ns | 0.31 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 773.24 ns | 2.739 ns | 2.287 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 231.23 ns | 0.944 ns | 0.837 ns | 0.30 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 781.35 ns | 6.770 ns | 6.001 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 787.16 ns | 6.048 ns | 4.722 ns | 1.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,719.18 ns | 4.384 ns | 3.661 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 74.65 ns | 0.616 ns | 0.546 ns | 0.04 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 776.80 ns | 3.107 ns | 2.906 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 786.45 ns | 6.334 ns | 5.615 ns | 1.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 730.96 ns | 4.551 ns | 4.257 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 764.02 ns | 7.369 ns | 6.153 ns | 1.05 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 735.80 ns | 4.364 ns | 3.868 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 741.53 ns | 3.903 ns | 3.259 ns | 1.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,717.84 ns | 3.838 ns | 3.402 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 77.00 ns | 1.529 ns | 1.761 ns | 0.05 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index ce82d807b..5b123b3c6 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -4,7 +4,7 @@ [ArrayIterationBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,22 +14,22 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |----------------------------- |-------- |-----------:|---------:|---------:|-----------:|------:|--------:|------:|------:|------:|----------:| -| Foreach | 1000000 | 452.0 μs | 12.83 μs | 37.83 μs | 424.2 μs | 1.00 | 0.00 | - | - | - | - | -| For | 1000000 | 418.5 μs | 1.42 μs | 1.19 μs | 418.3 μs | 0.87 | 0.05 | - | - | - | - | -| For_Unsafe | 1000000 | 452.8 μs | 13.08 μs | 38.57 μs | 424.4 μs | 1.01 | 0.12 | - | - | - | - | -| Span | 1000000 | 420.1 μs | 1.63 μs | 1.36 μs | 420.3 μs | 0.87 | 0.05 | - | - | - | - | -| ArraySegment_Foreach | 1000000 | 2,936.3 μs | 36.57 μs | 34.21 μs | 2,947.8 μs | 6.07 | 0.30 | - | - | - | 1 B | -| ArraySegment_For | 1000000 | 812.7 μs | 2.33 μs | 1.95 μs | 812.6 μs | 1.69 | 0.09 | - | - | - | - | -| ArraySegment_Expanded_For | 1000000 | 1,394.2 μs | 27.67 μs | 46.99 μs | 1,424.1 μs | 3.03 | 0.31 | - | - | - | - | -| ArraySegment_Wrapper_Foreach | 1000000 | 1,466.8 μs | 5.61 μs | 4.98 μs | 1,466.3 μs | 3.04 | 0.15 | - | - | - | - | +| Foreach | 1000000 | 421.7 μs | 2.74 μs | 2.43 μs | 421.4 μs | 1.00 | 0.00 | - | - | - | - | +| For | 1000000 | 453.3 μs | 13.53 μs | 39.90 μs | 424.0 μs | 1.08 | 0.08 | - | - | - | - | +| For_Unsafe | 1000000 | 499.3 μs | 2.06 μs | 1.72 μs | 499.4 μs | 1.19 | 0.01 | - | - | - | - | +| Span | 1000000 | 423.4 μs | 2.07 μs | 1.94 μs | 423.7 μs | 1.00 | 0.01 | - | - | - | - | +| ArraySegment_Foreach | 1000000 | 2,826.5 μs | 9.76 μs | 9.13 μs | 2,824.3 μs | 6.70 | 0.05 | - | - | - | 1 B | +| ArraySegment_For | 1000000 | 817.4 μs | 3.78 μs | 6.71 μs | 815.1 μs | 1.94 | 0.02 | - | - | - | - | +| ArraySegment_Expanded_For | 1000000 | 1,403.9 μs | 27.63 μs | 40.50 μs | 1,425.7 μs | 3.27 | 0.10 | - | - | - | 1 B | +| ArraySegment_Wrapper_Foreach | 1000000 | 1,468.3 μs | 4.87 μs | 4.32 μs | 1,466.8 μs | 3.48 | 0.02 | - | - | - | - | diff --git a/Benchmarks/ArrayToArrayBenchmarks.md b/Benchmarks/ArrayToArrayBenchmarks.md index 5d56b6085..3b22c8010 100644 --- a/Benchmarks/ArrayToArrayBenchmarks.md +++ b/Benchmarks/ArrayToArrayBenchmarks.md @@ -4,7 +4,7 @@ [ArrayToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,28 +14,28 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |----------------- |------ |-----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| **ArrayClone** | **10** | **82.746 ns** | **0.8458 ns** | **0.7912 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | -| SpanToArray | 10 | 7.750 ns | 0.1196 ns | 0.0998 ns | 0.09 | 0.00 | 0.0306 | - | - | 64 B | -| SpanCopyTo | 10 | 9.042 ns | 0.0833 ns | 0.0739 ns | 0.11 | 0.00 | 0.0306 | - | - | 64 B | -| CollectionCopyTo | 10 | 12.964 ns | 0.3123 ns | 0.2921 ns | 0.16 | 0.00 | 0.0305 | - | - | 64 B | +| **ArrayClone** | **10** | **92.985 ns** | **1.9170 ns** | **2.4926 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | +| SpanToArray | 10 | 7.493 ns | 0.1325 ns | 0.1175 ns | 0.08 | 0.00 | 0.0306 | - | - | 64 B | +| SpanCopyTo | 10 | 8.646 ns | 0.1475 ns | 0.1307 ns | 0.09 | 0.00 | 0.0306 | - | - | 64 B | +| CollectionCopyTo | 10 | 14.323 ns | 0.1582 ns | 0.1403 ns | 0.16 | 0.01 | 0.0305 | - | - | 64 B | | | | | | | | | | | | | -| **ArrayClone** | **100** | **93.642 ns** | **1.5195 ns** | **2.8909 ns** | **1.00** | **0.00** | **0.2021** | **-** | **-** | **424 B** | -| SpanToArray | 100 | 33.333 ns | 0.7550 ns | 2.2262 ns | 0.36 | 0.03 | 0.2027 | - | - | 424 B | -| SpanCopyTo | 100 | 33.050 ns | 0.5890 ns | 0.5510 ns | 0.35 | 0.01 | 0.2027 | - | - | 424 B | -| CollectionCopyTo | 100 | 36.857 ns | 0.7987 ns | 0.7471 ns | 0.39 | 0.02 | 0.2027 | - | - | 424 B | +| **ArrayClone** | **100** | **92.451 ns** | **1.1867 ns** | **1.1101 ns** | **1.00** | **0.00** | **0.2021** | **-** | **-** | **424 B** | +| SpanToArray | 100 | 31.352 ns | 0.6448 ns | 0.6031 ns | 0.34 | 0.01 | 0.2027 | - | - | 424 B | +| SpanCopyTo | 100 | 33.141 ns | 0.8588 ns | 2.4914 ns | 0.36 | 0.02 | 0.2027 | - | - | 424 B | +| CollectionCopyTo | 100 | 34.238 ns | 0.5767 ns | 0.5394 ns | 0.37 | 0.01 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | -| **ArrayClone** | **1000** | **289.606 ns** | **2.5042 ns** | **2.3424 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | -| SpanToArray | 1000 | 262.557 ns | 4.3460 ns | 3.8526 ns | 0.91 | 0.02 | 1.9226 | - | - | 4,024 B | -| SpanCopyTo | 1000 | 242.143 ns | 3.5619 ns | 3.1575 ns | 0.84 | 0.01 | 1.9155 | - | - | 4,024 B | -| CollectionCopyTo | 1000 | 245.507 ns | 4.1489 ns | 3.8809 ns | 0.85 | 0.01 | 1.9155 | - | - | 4,024 B | +| **ArrayClone** | **1000** | **286.609 ns** | **2.1636 ns** | **1.8067 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | +| SpanToArray | 1000 | 269.321 ns | 4.8332 ns | 4.5210 ns | 0.94 | 0.01 | 1.9226 | - | - | 4,024 B | +| SpanCopyTo | 1000 | 242.775 ns | 3.5268 ns | 3.2990 ns | 0.85 | 0.01 | 1.9155 | - | - | 4,024 B | +| CollectionCopyTo | 1000 | 243.677 ns | 4.2879 ns | 4.0109 ns | 0.85 | 0.02 | 1.9155 | - | - | 4,024 B | diff --git a/Benchmarks/ContainsBenchmarks.md b/Benchmarks/ContainsBenchmarks.md index 345aba29f..2efe03098 100644 --- a/Benchmarks/ContainsBenchmarks.md +++ b/Benchmarks/ContainsBenchmarks.md @@ -4,7 +4,7 @@ [ContainsBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,41 +14,41 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 41.37 ns | 0.116 ns | 0.108 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 31.03 ns | 0.118 ns | 0.110 ns | 0.75 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 23.29 ns | 0.058 ns | 0.054 ns | 0.56 | - | - | - | - | +| Linq_Array | Array | 100 | 39.09 ns | 0.295 ns | 0.262 ns | 1.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 30.28 ns | 0.204 ns | 0.181 ns | 0.77 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 23.08 ns | 0.070 ns | 0.066 ns | 0.59 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 625.41 ns | 3.478 ns | 2.904 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 211.36 ns | 0.490 ns | 0.435 ns | 0.34 | 0.0191 | - | - | 40 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 630.38 ns | 3.890 ns | 3.449 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 213.68 ns | 2.687 ns | 2.382 ns | 0.34 | 0.0191 | - | - | 40 B | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 36.54 ns | 0.153 ns | 0.144 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 36.91 ns | 0.268 ns | 0.224 ns | 1.01 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 36.47 ns | 0.259 ns | 0.230 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 37.04 ns | 0.240 ns | 0.200 ns | 1.02 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 37.84 ns | 0.165 ns | 0.147 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 40.72 ns | 0.325 ns | 0.288 ns | 1.08 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 37.53 ns | 0.226 ns | 0.201 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 40.39 ns | 0.201 ns | 0.178 ns | 1.08 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,615.47 ns | 3.955 ns | 3.506 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 942.46 ns | 2.732 ns | 2.555 ns | 0.58 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,633.17 ns | 6.551 ns | 6.128 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 948.62 ns | 2.231 ns | 1.978 ns | 0.58 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 598.60 ns | 2.790 ns | 2.610 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 683.93 ns | 5.594 ns | 4.959 ns | 1.14 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 628.50 ns | 3.975 ns | 3.719 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 758.41 ns | 6.989 ns | 6.537 ns | 1.21 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 36.50 ns | 0.223 ns | 0.198 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 36.20 ns | 0.309 ns | 0.289 ns | 0.99 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 36.32 ns | 0.205 ns | 0.192 ns | 1.00 | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 35.42 ns | 0.170 ns | 0.159 ns | 0.98 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 37.80 ns | 0.243 ns | 0.228 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 40.16 ns | 0.198 ns | 0.175 ns | 1.06 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 37.41 ns | 0.137 ns | 0.121 ns | 1.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 40.65 ns | 0.173 ns | 0.154 ns | 1.09 | - | - | - | - | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,617.73 ns | 3.651 ns | 3.236 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,711.37 ns | 4.334 ns | 3.842 ns | 1.06 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,630.05 ns | 6.055 ns | 5.368 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,749.10 ns | 5.811 ns | 4.537 ns | 1.07 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ContainsComparerBenchmarks.md b/Benchmarks/ContainsComparerBenchmarks.md index 74ca3d3e9..d231f742c 100644 --- a/Benchmarks/ContainsComparerBenchmarks.md +++ b/Benchmarks/ContainsComparerBenchmarks.md @@ -4,7 +4,7 @@ [ContainsComparerBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 574.1 ns | 2.33 ns | 2.18 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 198.8 ns | 0.83 ns | 0.73 ns | 0.35 | - | - | - | - | +| Linq_Array | Array | 100 | 572.5 ns | 2.79 ns | 2.33 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 197.9 ns | 0.70 ns | 0.55 ns | 0.35 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 763.6 ns | 3.44 ns | 3.22 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 279.6 ns | 0.96 ns | 0.90 ns | 0.37 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 793.3 ns | 4.90 ns | 4.34 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 281.1 ns | 1.73 ns | 1.54 ns | 0.35 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 756.8 ns | 8.41 ns | 7.02 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 281.0 ns | 1.35 ns | 1.26 ns | 0.37 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 786.9 ns | 3.22 ns | 2.68 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 281.9 ns | 0.96 ns | 0.80 ns | 0.36 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 757.7 ns | 3.27 ns | 2.90 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 767.8 ns | 4.66 ns | 4.13 ns | 1.01 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 781.4 ns | 5.11 ns | 4.78 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 769.3 ns | 3.61 ns | 3.37 ns | 0.98 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,718.6 ns | 4.32 ns | 3.83 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 926.7 ns | 2.75 ns | 2.57 ns | 0.54 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,720.2 ns | 3.38 ns | 3.16 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 933.5 ns | 1.89 ns | 1.67 ns | 0.54 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 762.8 ns | 4.56 ns | 4.04 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 785.2 ns | 3.60 ns | 3.36 ns | 1.03 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 797.8 ns | 8.44 ns | 7.48 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 782.4 ns | 3.13 ns | 2.77 ns | 0.98 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 757.1 ns | 2.88 ns | 2.55 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 764.0 ns | 7.84 ns | 6.95 ns | 1.01 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 781.4 ns | 3.37 ns | 3.15 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 787.2 ns | 3.71 ns | 3.29 ns | 1.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 787.4 ns | 3.83 ns | 3.40 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 766.5 ns | 4.97 ns | 4.65 ns | 0.97 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 787.1 ns | 2.73 ns | 2.42 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 774.0 ns | 6.55 ns | 5.47 ns | 0.98 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,718.6 ns | 4.82 ns | 4.28 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,718.5 ns | 3.97 ns | 3.71 ns | 1.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,728.8 ns | 3.36 ns | 2.81 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,720.0 ns | 5.65 ns | 5.28 ns | 0.99 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/CountBenchmarks.md b/Benchmarks/CountBenchmarks.md index 209127532..887ed8a21 100644 --- a/Benchmarks/CountBenchmarks.md +++ b/Benchmarks/CountBenchmarks.md @@ -4,7 +4,7 @@ [CountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |--------------:|----------:|----------:|-------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 9.3540 ns | 0.0399 ns | 0.0353 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Array | Array | 100 | 0.7840 ns | 0.0100 ns | 0.0093 ns | 0.08 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 7.7322 ns | 0.0259 ns | 0.0242 ns | 0.83 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 8.6538 ns | 0.0562 ns | 0.0498 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Array | Array | 100 | 0.7170 ns | 0.0126 ns | 0.0112 ns | 0.08 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 7.9852 ns | 0.0270 ns | 0.0253 ns | 0.92 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 349.3511 ns | 2.4083 ns | 2.1349 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 597.3489 ns | 2.3495 ns | 2.1978 ns | 1.71 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 140.6946 ns | 0.3631 ns | 0.3396 ns | 0.40 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 349.4069 ns | 2.8233 ns | 2.3575 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 619.7720 ns | 4.5373 ns | 4.0222 ns | 1.77 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 140.7260 ns | 0.2846 ns | 0.2523 ns | 0.40 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 4.1085 ns | 0.0220 ns | 0.0195 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Value | Collection_Value | 100 | 604.9679 ns | 5.7949 ns | 5.4206 ns | 147.31 | 1.75 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.4980 ns | 0.0233 ns | 0.0206 ns | 1.83 | 0.01 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 4.1117 ns | 0.0213 ns | 0.0199 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Value | Collection_Value | 100 | 618.7262 ns | 3.1791 ns | 2.6547 ns | 150.49 | 0.88 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 7.5543 ns | 0.0264 ns | 0.0247 ns | 1.84 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 4.9597 ns | 0.0216 ns | 0.0202 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Value | List_Value | 100 | 2.3068 ns | 0.0209 ns | 0.0195 ns | 0.47 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1.7986 ns | 0.0170 ns | 0.0150 ns | 0.36 | 0.00 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 4.9752 ns | 0.0545 ns | 0.0483 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Value | List_Value | 100 | 2.3856 ns | 0.0229 ns | 0.0214 ns | 0.48 | 0.01 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1.6012 ns | 0.0116 ns | 0.0109 ns | 0.32 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,631.2288 ns | 5.2514 ns | 4.9121 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 775.6346 ns | 1.3539 ns | 1.2664 ns | 0.48 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,624.5794 ns | 6.4122 ns | 5.6842 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 778.0014 ns | 2.2398 ns | 1.9856 ns | 0.48 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 348.0530 ns | 2.2995 ns | 1.9202 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 597.0186 ns | 3.3703 ns | 2.9877 ns | 1.71 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 392.4467 ns | 2.1130 ns | 1.8731 ns | 1.13 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 345.5721 ns | 1.6528 ns | 1.3802 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 622.3207 ns | 6.1665 ns | 5.4665 ns | 1.80 | 0.02 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 399.7432 ns | 3.6850 ns | 3.0771 ns | 1.16 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 4.1574 ns | 0.0297 ns | 0.0278 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 596.4288 ns | 2.9400 ns | 2.6063 ns | 143.60 | 1.07 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.8501 ns | 0.0173 ns | 0.0153 ns | 0.45 | 0.00 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 4.1547 ns | 0.0307 ns | 0.0272 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 617.2308 ns | 1.6776 ns | 1.4871 ns | 148.57 | 1.08 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1.7886 ns | 0.0117 ns | 0.0104 ns | 0.43 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 4.9423 ns | 0.0317 ns | 0.0281 ns | 1.00 | 0.00 | - | - | - | - | -| StructLinq_List_Reference | List_Reference | 100 | 600.4904 ns | 4.4677 ns | 3.9605 ns | 121.50 | 0.84 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1.7823 ns | 0.0152 ns | 0.0135 ns | 0.36 | 0.00 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 4.9597 ns | 0.0286 ns | 0.0268 ns | 1.00 | 0.00 | - | - | - | - | +| StructLinq_List_Reference | List_Reference | 100 | 620.5949 ns | 3.4575 ns | 3.2342 ns | 125.13 | 0.90 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1.7393 ns | 0.0310 ns | 0.0275 ns | 0.35 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,615.1213 ns | 3.2752 ns | 2.9034 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,390.1995 ns | 3.0343 ns | 2.6898 ns | 0.86 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,630.2851 ns | 4.5997 ns | 4.3025 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,419.2966 ns | 3.7573 ns | 3.3308 ns | 0.87 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/DistinctBenchmarks.md b/Benchmarks/DistinctBenchmarks.md index df68f5c18..0195213ec 100644 --- a/Benchmarks/DistinctBenchmarks.md +++ b/Benchmarks/DistinctBenchmarks.md @@ -4,7 +4,7 @@ [DistinctBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |---------:|----------:|----------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 1.902 μs | 0.0095 μs | 0.0084 μs | 1.901 μs | 1.00 | 0.00 | 1.3294 | - | - | 2,784 B | -| StructLinq_Array | Array | 100 | 1.277 μs | 0.0123 μs | 0.0109 μs | 1.273 μs | 0.67 | 0.01 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 1.474 μs | 0.0062 μs | 0.0058 μs | 1.472 μs | 0.77 | 0.00 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 1.515 μs | 0.0088 μs | 0.0078 μs | 1.516 μs | 0.80 | 0.01 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.593 μs | 0.0055 μs | 0.0046 μs | 1.593 μs | 0.84 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.245 μs | 0.0141 μs | 0.0117 μs | 2.241 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.232 μs | 0.0129 μs | 0.0115 μs | 2.234 μs | 0.99 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.544 μs | 0.0058 μs | 0.0054 μs | 1.544 μs | 0.69 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 2.279 μs | 0.0164 μs | 0.0137 μs | 2.275 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 2.240 μs | 0.0204 μs | 0.0181 μs | 2.241 μs | 0.98 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.532 μs | 0.0069 μs | 0.0061 μs | 1.529 μs | 0.67 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 2.252 μs | 0.0257 μs | 0.0215 μs | 2.249 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_List_Value | List_Value | 100 | 1.526 μs | 0.0071 μs | 0.0063 μs | 1.528 μs | 0.68 | 0.01 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 2.798 μs | 0.0095 μs | 0.0084 μs | 2.797 μs | 1.24 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.665 μs | 0.0404 μs | 0.0358 μs | 7.666 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.387 μs | 0.0145 μs | 0.0136 μs | 4.384 μs | 0.57 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.206 μs | 0.0067 μs | 0.0056 μs | 2.208 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.210 μs | 0.0134 μs | 0.0126 μs | 2.208 μs | 1.00 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.696 μs | 0.0103 μs | 0.0092 μs | 2.696 μs | 1.22 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 2.238 μs | 0.0134 μs | 0.0125 μs | 2.234 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 2.218 μs | 0.0162 μs | 0.0144 μs | 2.225 μs | 0.99 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.623 μs | 0.0152 μs | 0.0135 μs | 2.624 μs | 1.17 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 2.270 μs | 0.0140 μs | 0.0117 μs | 2.264 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | -| StructLinq_List_Reference | List_Reference | 100 | 2.208 μs | 0.0163 μs | 0.0152 μs | 2.204 μs | 0.97 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 2.752 μs | 0.0078 μs | 0.0069 μs | 2.754 μs | 1.21 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.447 μs | 0.1489 μs | 0.2183 μs | 7.293 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4.914 μs | 0.0167 μs | 0.0148 μs | 4.913 μs | 0.65 | 0.02 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |---------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 1.762 μs | 0.0060 μs | 0.0050 μs | 1.00 | 0.00 | 1.3294 | - | - | 2,784 B | +| StructLinq_Array | Array | 100 | 1.253 μs | 0.0074 μs | 0.0061 μs | 0.71 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 1.468 μs | 0.0061 μs | 0.0054 μs | 0.83 | 0.00 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 1.546 μs | 0.0082 μs | 0.0076 μs | 0.88 | 0.00 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.561 μs | 0.0080 μs | 0.0071 μs | 0.89 | 0.01 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.381 μs | 0.0472 μs | 0.0775 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 2.206 μs | 0.0220 μs | 0.0206 μs | 0.95 | 0.04 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1.495 μs | 0.0074 μs | 0.0069 μs | 0.65 | 0.02 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 2.249 μs | 0.0102 μs | 0.0096 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 2.210 μs | 0.0175 μs | 0.0163 μs | 0.98 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 1.472 μs | 0.0064 μs | 0.0053 μs | 0.65 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 2.305 μs | 0.0117 μs | 0.0104 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_List_Value | List_Value | 100 | 1.490 μs | 0.0110 μs | 0.0102 μs | 0.65 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 2.725 μs | 0.0121 μs | 0.0113 μs | 1.18 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7.732 μs | 0.0411 μs | 0.0364 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4.331 μs | 0.0281 μs | 0.0263 μs | 0.56 | 0.00 | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.316 μs | 0.0227 μs | 0.0189 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.209 μs | 0.0186 μs | 0.0174 μs | 0.95 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2.636 μs | 0.0155 μs | 0.0137 μs | 1.14 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 2.250 μs | 0.0091 μs | 0.0085 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 2.199 μs | 0.0201 μs | 0.0188 μs | 0.98 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 2.661 μs | 0.0150 μs | 0.0125 μs | 1.18 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 2.307 μs | 0.0134 μs | 0.0119 μs | 1.00 | 0.00 | 1.3275 | - | - | 2,784 B | +| StructLinq_List_Reference | List_Reference | 100 | 2.175 μs | 0.0134 μs | 0.0125 μs | 0.94 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 2.781 μs | 0.0236 μs | 0.0209 μs | 1.21 | 0.01 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7.339 μs | 0.1288 μs | 0.1888 μs | 1.00 | 0.00 | 2.0599 | - | - | 4,320 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5.030 μs | 0.0163 μs | 0.0152 μs | 0.68 | 0.02 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ElementAtBenchmarks.md b/Benchmarks/ElementAtBenchmarks.md index 20052259e..f0ec761d7 100644 --- a/Benchmarks/ElementAtBenchmarks.md +++ b/Benchmarks/ElementAtBenchmarks.md @@ -4,7 +4,7 @@ [ElementAtBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 15.961 ns | 0.0914 ns | 0.0763 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 12.948 ns | 0.0370 ns | 0.0328 ns | 0.81 | 0.01 | - | - | - | - | +| Linq_Array | Array | 100 | 16.456 ns | 0.0966 ns | 0.0904 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 12.952 ns | 0.0361 ns | 0.0320 ns | 0.79 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 321.713 ns | 2.1199 ns | 1.8792 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 131.208 ns | 0.4962 ns | 0.4399 ns | 0.41 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 321.772 ns | 2.7943 ns | 2.6138 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 131.436 ns | 0.4074 ns | 0.3611 ns | 0.41 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 316.246 ns | 0.8984 ns | 0.7014 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 136.082 ns | 0.6140 ns | 0.5443 ns | 0.43 | 0.00 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 320.549 ns | 5.2212 ns | 4.6284 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 136.995 ns | 0.5484 ns | 0.4861 ns | 0.43 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 9.747 ns | 0.0391 ns | 0.0347 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 341.010 ns | 1.4219 ns | 1.1874 ns | 34.98 | 0.16 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 9.673 ns | 0.0693 ns | 0.0648 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 330.177 ns | 2.9100 ns | 2.5796 ns | 34.15 | 0.38 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,617.668 ns | 4.8676 ns | 4.3150 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 804.608 ns | 3.9449 ns | 3.4970 ns | 0.50 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,620.433 ns | 4.6504 ns | 4.1224 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 805.497 ns | 3.5011 ns | 3.1036 ns | 0.50 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 315.847 ns | 1.1479 ns | 1.0176 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 336.160 ns | 3.1605 ns | 2.9564 ns | 1.07 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 322.075 ns | 1.6159 ns | 1.4324 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 335.420 ns | 2.7009 ns | 2.2554 ns | 1.04 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 316.810 ns | 1.5474 ns | 1.3718 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 361.737 ns | 1.0627 ns | 0.9421 ns | 1.14 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 319.994 ns | 3.3920 ns | 3.0069 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 364.654 ns | 1.4024 ns | 1.2432 ns | 1.14 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 9.761 ns | 0.0949 ns | 0.0842 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 368.868 ns | 3.0067 ns | 2.6654 ns | 37.79 | 0.44 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 9.695 ns | 0.0674 ns | 0.0527 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 328.172 ns | 1.9735 ns | 1.6480 ns | 33.84 | 0.28 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,617.709 ns | 5.9396 ns | 4.9599 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,435.386 ns | 5.2823 ns | 4.6827 ns | 0.89 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,627.227 ns | 6.8413 ns | 6.0646 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,412.723 ns | 7.4225 ns | 6.5799 ns | 0.87 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/EmptyBenchmarks.md b/Benchmarks/EmptyBenchmarks.md index 204e2f6ff..665678723 100644 --- a/Benchmarks/EmptyBenchmarks.md +++ b/Benchmarks/EmptyBenchmarks.md @@ -4,7 +4,7 @@ [EmptyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/EmptyBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,19 +14,19 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------------- |------------ |-----------:|----------:|----------:|------:|------:|------:|------:|----------:| -| Linq_Empty | Empty | 6.4999 ns | 0.0496 ns | 0.0439 ns | 1.000 | - | - | - | - | -| Hyperlinq_Empty | Empty | 0.0066 ns | 0.0055 ns | 0.0048 ns | 0.001 | - | - | - | - | -| | | | | | | | | | | -| Linq_Empty_Async | Empty_Async | 41.3903 ns | 0.1669 ns | 0.1480 ns | 1.00 | - | - | - | - | -| Hyperlinq_Empty_Async | Empty_Async | 20.8240 ns | 0.1316 ns | 0.1099 ns | 0.50 | - | - | - | - | +| Method | Categories | Mean | Error | StdDev | Median | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------------- |------------ |-----------:|----------:|----------:|-----------:|------:|------:|------:|------:|----------:| +| Linq_Empty | Empty | 6.4057 ns | 0.0357 ns | 0.0316 ns | 6.4039 ns | 1.000 | - | - | - | - | +| Hyperlinq_Empty | Empty | 0.0060 ns | 0.0064 ns | 0.0053 ns | 0.0044 ns | 0.001 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Empty_Async | Empty_Async | 39.8805 ns | 0.1600 ns | 0.1418 ns | 39.8955 ns | 1.00 | - | - | - | - | +| Hyperlinq_Empty_Async | Empty_Async | 20.9157 ns | 0.0982 ns | 0.0871 ns | 20.9092 ns | 0.52 | - | - | - | - | diff --git a/Benchmarks/FirstBenchmarks.md b/Benchmarks/FirstBenchmarks.md index d75929a9d..32a10096e 100644 --- a/Benchmarks/FirstBenchmarks.md +++ b/Benchmarks/FirstBenchmarks.md @@ -4,7 +4,7 @@ [FirstBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 19.32 ns | 0.133 ns | 0.118 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 13.15 ns | 0.025 ns | 0.024 ns | 0.68 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 22.02 ns | 0.200 ns | 0.187 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 13.20 ns | 0.042 ns | 0.038 ns | 0.60 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 25.19 ns | 0.109 ns | 0.091 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 15.61 ns | 0.051 ns | 0.045 ns | 0.62 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 27.38 ns | 0.087 ns | 0.073 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 16.20 ns | 0.039 ns | 0.035 ns | 0.59 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 26.26 ns | 0.145 ns | 0.121 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 19.36 ns | 0.038 ns | 0.033 ns | 0.74 | 0.00 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 26.56 ns | 0.153 ns | 0.136 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 18.73 ns | 0.053 ns | 0.047 ns | 0.71 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 12.29 ns | 0.079 ns | 0.070 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 21.07 ns | 0.107 ns | 0.100 ns | 1.72 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 12.36 ns | 0.055 ns | 0.046 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 22.47 ns | 0.132 ns | 0.117 ns | 1.82 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 101.36 ns | 0.383 ns | 0.320 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 60.98 ns | 0.182 ns | 0.170 ns | 0.60 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 109.50 ns | 0.948 ns | 0.887 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 62.59 ns | 0.160 ns | 0.141 ns | 0.57 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 26.33 ns | 0.555 ns | 1.001 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 18.44 ns | 0.142 ns | 0.126 ns | 0.71 | 0.02 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 25.50 ns | 0.148 ns | 0.139 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 18.66 ns | 0.147 ns | 0.123 ns | 0.73 | 0.01 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 26.37 ns | 0.280 ns | 0.248 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 18.35 ns | 0.109 ns | 0.102 ns | 0.70 | 0.01 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 26.59 ns | 0.091 ns | 0.076 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 18.75 ns | 0.119 ns | 0.105 ns | 0.71 | 0.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 12.28 ns | 0.036 ns | 0.032 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 23.76 ns | 0.498 ns | 0.611 ns | 1.92 | 0.06 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 12.40 ns | 0.064 ns | 0.060 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 23.48 ns | 0.499 ns | 0.594 ns | 1.88 | 0.06 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 103.29 ns | 0.420 ns | 0.372 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 67.61 ns | 0.145 ns | 0.121 ns | 0.65 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 106.75 ns | 0.246 ns | 0.219 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 68.68 ns | 0.392 ns | 0.367 ns | 0.64 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ListIterationBenchmarks.md b/Benchmarks/ListIterationBenchmarks.md index f49c2778b..5e8bbd81b 100644 --- a/Benchmarks/ListIterationBenchmarks.md +++ b/Benchmarks/ListIterationBenchmarks.md @@ -4,7 +4,7 @@ [ListIterationBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,20 +14,20 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------- |-------------- |-------- |------------:|------------:|------------:|------------:|------:|--------:|------:|------:|------:|----------:| -| List_Enumerable | List | 1000000 | 1,392.6 μs | 27.61 μs | 60.61 μs | 1,350.0 μs | 1.00 | 0.00 | - | - | - | - | -| List_Indexer | List | 1000000 | 1,066.9 μs | 3.64 μs | 3.04 μs | 1,067.6 μs | 0.76 | 0.03 | - | - | - | 1 B | -| List_Span | List | 1000000 | 457.8 μs | 2.98 μs | 3.32 μs | 456.8 μs | 0.32 | 0.01 | - | - | - | - | -| | | | | | | | | | | | | | -| ImmutableList_Enumerable | ImmutableList | 1000000 | 36,880.0 μs | 813.67 μs | 2,399.13 μs | 35,638.2 μs | 1.00 | 0.00 | - | - | - | 10 B | -| ImmutableList_Indexer | ImmutableList | 1000000 | 60,898.2 μs | 1,206.47 μs | 2,698.44 μs | 59,314.9 μs | 1.61 | 0.08 | - | - | - | 16 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------- |-------------- |-------- |------------:|----------:|----------:|------------:|------:|--------:|------:|------:|------:|----------:| +| List_Enumerable | List | 1000000 | 1,406.4 μs | 27.92 μs | 57.66 μs | 1,373.8 μs | 1.00 | 0.00 | - | - | - | - | +| List_Indexer | List | 1000000 | 1,071.0 μs | 3.83 μs | 3.20 μs | 1,070.7 μs | 0.77 | 0.03 | - | - | - | 1 B | +| List_Span | List | 1000000 | 487.5 μs | 15.26 μs | 44.99 μs | 459.3 μs | 0.35 | 0.03 | - | - | - | - | +| | | | | | | | | | | | | | +| ImmutableList_Enumerable | ImmutableList | 1000000 | 35,277.5 μs | 345.09 μs | 322.79 μs | 35,354.5 μs | 1.00 | 0.00 | - | - | - | 10 B | +| ImmutableList_Indexer | ImmutableList | 1000000 | 63,181.9 μs | 315.41 μs | 295.03 μs | 63,129.3 μs | 1.79 | 0.02 | - | - | - | 55 B | diff --git a/Benchmarks/RangeBenchmarks.md b/Benchmarks/RangeBenchmarks.md index a4c4d89ac..640a5a436 100644 --- a/Benchmarks/RangeBenchmarks.md +++ b/Benchmarks/RangeBenchmarks.md @@ -4,7 +4,7 @@ [RangeBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,20 +14,20 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------ |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 439.33 ns | 2.995 ns | 2.655 ns | 1.00 | 0.0191 | - | - | 40 B | -| StructLinq | Range | 100 | 33.66 ns | 0.137 ns | 0.114 ns | 0.08 | - | - | - | - | -| Hyperlinq | Range | 100 | 41.83 ns | 0.164 ns | 0.145 ns | 0.10 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 3,696.52 ns | 9.939 ns | 8.811 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Range_Async | 100 | 1,232.14 ns | 7.870 ns | 6.977 ns | 0.33 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------------ |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| +| Linq | Range | 100 | 372.51 ns | 2.888 ns | 2.254 ns | 1.00 | 0.0191 | - | - | 40 B | +| StructLinq | Range | 100 | 33.64 ns | 0.143 ns | 0.112 ns | 0.09 | - | - | - | - | +| Hyperlinq | Range | 100 | 41.45 ns | 0.259 ns | 0.318 ns | 0.11 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Async | Range_Async | 100 | 3,676.68 ns | 15.301 ns | 13.564 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Range_Async | 100 | 1,234.74 ns | 5.418 ns | 4.524 ns | 0.34 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/RangeToArrayBenchmarks.md b/Benchmarks/RangeToArrayBenchmarks.md index 43c540f27..d00219d01 100644 --- a/Benchmarks/RangeToArrayBenchmarks.md +++ b/Benchmarks/RangeToArrayBenchmarks.md @@ -4,7 +4,7 @@ [RangeToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,21 +14,21 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------ |------ |----------:|---------:|---------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 83.93 ns | 1.194 ns | 1.635 ns | 83.73 ns | 1.00 | 0.00 | 0.2218 | - | - | 464 B | -| StructLinq | Range | 100 | 92.26 ns | 1.910 ns | 3.859 ns | 91.20 ns | 1.10 | 0.05 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Range | 100 | 40.19 ns | 0.874 ns | 2.493 ns | 39.14 ns | 0.48 | 0.03 | 0.2027 | - | - | 424 B | -| Hyperlinq | Range | 100 | 44.88 ns | 0.802 ns | 0.711 ns | 45.15 ns | 0.53 | 0.01 | 0.2027 | - | - | 424 B | +| Linq | Range | 100 | 91.33 ns | 0.704 ns | 0.588 ns | 91.48 ns | 1.00 | 0.00 | 0.2218 | - | - | 464 B | +| StructLinq | Range | 100 | 86.82 ns | 1.396 ns | 1.305 ns | 86.72 ns | 0.95 | 0.01 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Range | 100 | 40.31 ns | 0.879 ns | 2.452 ns | 39.02 ns | 0.44 | 0.02 | 0.2027 | - | - | 424 B | +| Hyperlinq | Range | 100 | 45.34 ns | 0.366 ns | 0.342 ns | 45.35 ns | 0.50 | 0.01 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 105.70 ns | 0.993 ns | 0.880 ns | 105.84 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Range_Async | 100 | 152.75 ns | 3.112 ns | 7.807 ns | 147.54 ns | 1.44 | 0.07 | 0.2027 | - | - | 424 B | +| Linq_Async | Range_Async | 100 | 105.08 ns | 1.318 ns | 1.232 ns | 105.44 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Range_Async | 100 | 145.72 ns | 0.949 ns | 0.793 ns | 145.54 ns | 1.39 | 0.02 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/ReadOnlyFieldsBenchmarks.md b/Benchmarks/ReadOnlyFieldsBenchmarks.md index 6216052dc..daf553cd8 100644 --- a/Benchmarks/ReadOnlyFieldsBenchmarks.md +++ b/Benchmarks/ReadOnlyFieldsBenchmarks.md @@ -4,7 +4,7 @@ [ReadOnlyFieldsBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReadOnlyFieldsBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,17 +14,17 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------ |---------:|--------:|--------:|------:|------:|------:|------:|----------:| -| Baseline | 1000 | 544.1 ns | 1.03 ns | 0.96 ns | 1.00 | - | - | - | - | -| ReadOnlyCurrent | 1000 | 544.6 ns | 1.13 ns | 1.06 ns | 1.00 | - | - | - | - | -| ReadOnlyField | 1000 | 544.4 ns | 0.78 ns | 0.65 ns | 1.00 | - | - | - | - | +| Baseline | 1000 | 545.7 ns | 1.41 ns | 1.25 ns | 1.00 | - | - | - | - | +| ReadOnlyCurrent | 1000 | 545.6 ns | 1.20 ns | 1.12 ns | 1.00 | - | - | - | - | +| ReadOnlyField | 1000 | 545.9 ns | 1.41 ns | 1.32 ns | 1.00 | - | - | - | - | diff --git a/Benchmarks/RepeatBenchmarks.md b/Benchmarks/RepeatBenchmarks.md index 4b2a0e9ea..59c8e4232 100644 --- a/Benchmarks/RepeatBenchmarks.md +++ b/Benchmarks/RepeatBenchmarks.md @@ -4,7 +4,7 @@ [RepeatBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,20 +14,20 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 393.35 ns | 1.375 ns | 1.219 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq | Repeat | 100 | 44.33 ns | 0.164 ns | 0.154 ns | 0.11 | - | - | - | - | -| Hyperlinq | Repeat | 100 | 147.06 ns | 0.308 ns | 0.288 ns | 0.37 | - | - | - | - | +| Linq | Repeat | 100 | 392.90 ns | 4.207 ns | 3.285 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq | Repeat | 100 | 44.30 ns | 0.150 ns | 0.133 ns | 0.11 | - | - | - | - | +| Hyperlinq | Repeat | 100 | 146.99 ns | 0.322 ns | 0.302 ns | 0.37 | - | - | - | - | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 4,710.88 ns | 21.558 ns | 20.165 ns | 1.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Async | Repeat_Async | 100 | 770.99 ns | 4.354 ns | 3.636 ns | 0.16 | - | - | - | - | +| Linq_Async | Repeat_Async | 100 | 4,732.19 ns | 47.740 ns | 39.865 ns | 1.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Async | Repeat_Async | 100 | 769.57 ns | 1.426 ns | 1.265 ns | 0.16 | - | - | - | - | diff --git a/Benchmarks/RepeatToArrayBenchmarks.md b/Benchmarks/RepeatToArrayBenchmarks.md index 080e4a1a9..e8a16bea4 100644 --- a/Benchmarks/RepeatToArrayBenchmarks.md +++ b/Benchmarks/RepeatToArrayBenchmarks.md @@ -4,7 +4,7 @@ [RepeatToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,22 +14,22 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------------- |------------- |------ |----------:|---------:|---------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 92.02 ns | 1.863 ns | 2.356 ns | 91.28 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq | Repeat | 100 | 82.20 ns | 0.970 ns | 0.907 ns | 81.84 ns | 0.89 | 0.03 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Repeat | 100 | 33.45 ns | 0.318 ns | 0.282 ns | 33.40 ns | 0.36 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq | Repeat | 100 | 56.99 ns | 0.730 ns | 0.683 ns | 56.87 ns | 0.62 | 0.02 | 0.2027 | - | - | 424 B | -| Hyperlinq_SIMD | Repeat | 100 | 41.44 ns | 0.897 ns | 2.266 ns | 40.31 ns | 0.45 | 0.03 | 0.2027 | - | - | 424 B | +| Linq | Repeat | 100 | 90.72 ns | 1.491 ns | 2.450 ns | 90.20 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq | Repeat | 100 | 77.89 ns | 1.265 ns | 1.183 ns | 77.83 ns | 0.86 | 0.03 | 0.2142 | - | - | 448 B | +| LinqFaster_SIMD | Repeat | 100 | 29.47 ns | 0.658 ns | 0.808 ns | 29.45 ns | 0.32 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq | Repeat | 100 | 34.85 ns | 0.589 ns | 0.522 ns | 34.97 ns | 0.38 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_SIMD | Repeat | 100 | 42.00 ns | 0.914 ns | 2.593 ns | 40.72 ns | 0.46 | 0.03 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 93.83 ns | 1.475 ns | 1.379 ns | 94.28 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Repeat_Async | 100 | 119.13 ns | 1.828 ns | 1.710 ns | 119.07 ns | 1.27 | 0.03 | 0.2027 | - | - | 424 B | +| Linq_Async | Repeat_Async | 100 | 101.03 ns | 1.027 ns | 0.961 ns | 101.12 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | +| Hyperlinq_Async | Repeat_Async | 100 | 166.58 ns | 1.317 ns | 1.100 ns | 166.15 ns | 1.65 | 0.01 | 0.2027 | - | - | 424 B | diff --git a/Benchmarks/ReturnBenchmarks.md b/Benchmarks/ReturnBenchmarks.md index 4e070ee5c..bcf875ded 100644 --- a/Benchmarks/ReturnBenchmarks.md +++ b/Benchmarks/ReturnBenchmarks.md @@ -4,7 +4,7 @@ [ReturnBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ReturnBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,19 +14,19 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |----------------------- |------------- |----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Return | Return | 15.486 ns | 0.1401 ns | 0.1311 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | -| Hyperlinq_Return | Return | 8.736 ns | 0.0199 ns | 0.0186 ns | 0.56 | 0.00 | - | - | - | - | +| Linq_Return | Return | 15.438 ns | 0.2360 ns | 0.2208 ns | 1.00 | 0.00 | 0.0191 | - | - | 40 B | +| Hyperlinq_Return | Return | 8.734 ns | 0.0199 ns | 0.0177 ns | 0.57 | 0.01 | - | - | - | - | | | | | | | | | | | | | -| Linq_Return_Async | Return_Async | 58.705 ns | 1.1953 ns | 2.5729 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | -| Hyperlinq_Return_Async | Return_Async | 40.121 ns | 0.2094 ns | 0.1959 ns | 0.68 | 0.02 | - | - | - | - | +| Linq_Return_Async | Return_Async | 59.871 ns | 1.1818 ns | 1.2645 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | +| Hyperlinq_Return_Async | Return_Async | 40.616 ns | 0.1893 ns | 0.1678 ns | 0.68 | 0.02 | - | - | - | - | diff --git a/Benchmarks/SelectBenchmarks.md b/Benchmarks/SelectBenchmarks.md index 67310e33c..8bf271f4e 100644 --- a/Benchmarks/SelectBenchmarks.md +++ b/Benchmarks/SelectBenchmarks.md @@ -4,7 +4,7 @@ [SelectBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,52 +14,52 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 589.9 ns | 2.07 ns | 1.83 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 226.2 ns | 0.87 ns | 0.77 ns | 0.38 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 297.1 ns | 1.63 ns | 1.52 ns | 0.50 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 208.8 ns | 0.62 ns | 0.58 ns | 0.35 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 197.5 ns | 0.78 ns | 0.65 ns | 0.33 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 208.3 ns | 0.62 ns | 0.52 ns | 0.35 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 299.8 ns | 1.99 ns | 1.67 ns | 0.51 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 232.3 ns | 0.60 ns | 0.50 ns | 0.39 | - | - | - | - | +| Linq_Array | Array | 100 | 634.9 ns | 6.67 ns | 5.92 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 206.7 ns | 1.40 ns | 1.17 ns | 0.33 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 300.1 ns | 2.67 ns | 2.49 ns | 0.47 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 209.7 ns | 0.70 ns | 0.62 ns | 0.33 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 196.8 ns | 1.09 ns | 1.02 ns | 0.31 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 230.9 ns | 0.87 ns | 0.81 ns | 0.36 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 350.3 ns | 2.06 ns | 1.72 ns | 0.55 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 232.6 ns | 0.50 ns | 0.41 ns | 0.37 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,197.2 ns | 5.22 ns | 4.88 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 749.6 ns | 2.16 ns | 1.92 ns | 0.63 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 229.6 ns | 0.50 ns | 0.42 ns | 0.19 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,168.6 ns | 4.90 ns | 3.83 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 789.1 ns | 2.65 ns | 2.35 ns | 0.67 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 209.2 ns | 0.60 ns | 0.53 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,230.5 ns | 15.98 ns | 13.34 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 777.3 ns | 3.24 ns | 2.87 ns | 0.63 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 206.6 ns | 0.66 ns | 0.55 ns | 0.17 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,192.1 ns | 5.24 ns | 4.38 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 780.3 ns | 3.58 ns | 3.18 ns | 0.65 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 208.0 ns | 0.74 ns | 0.62 ns | 0.17 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,183.7 ns | 4.01 ns | 3.56 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 439.6 ns | 1.84 ns | 1.63 ns | 0.37 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 759.3 ns | 3.40 ns | 3.01 ns | 0.64 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,190.9 ns | 11.63 ns | 10.31 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 440.0 ns | 1.36 ns | 1.27 ns | 0.37 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 743.3 ns | 5.20 ns | 4.61 ns | 0.62 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,848.7 ns | 33.67 ns | 29.85 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,724.6 ns | 19.11 ns | 16.94 ns | 0.69 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,530.2 ns | 23.55 ns | 20.88 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,789.9 ns | 24.40 ns | 22.82 ns | 0.73 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,168.8 ns | 5.61 ns | 5.25 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 699.4 ns | 1.85 ns | 1.54 ns | 0.60 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 775.8 ns | 5.45 ns | 5.35 ns | 0.66 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,157.4 ns | 6.61 ns | 6.19 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 789.6 ns | 5.00 ns | 4.44 ns | 0.68 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 758.0 ns | 4.30 ns | 3.81 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,172.4 ns | 6.69 ns | 5.93 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 756.2 ns | 2.48 ns | 2.20 ns | 0.65 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 754.2 ns | 2.39 ns | 1.99 ns | 0.64 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,158.5 ns | 4.83 ns | 3.77 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 789.2 ns | 4.96 ns | 4.40 ns | 0.68 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 761.8 ns | 3.01 ns | 2.81 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,180.1 ns | 9.98 ns | 8.85 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 755.6 ns | 5.35 ns | 4.74 ns | 0.64 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 752.5 ns | 3.45 ns | 3.06 ns | 0.64 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,178.0 ns | 8.81 ns | 8.24 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 778.2 ns | 2.60 ns | 2.43 ns | 0.66 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 782.6 ns | 3.64 ns | 3.04 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,323.5 ns | 41.43 ns | 38.76 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,159.2 ns | 19.05 ns | 16.88 ns | 0.70 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,551.7 ns | 31.19 ns | 29.17 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,147.7 ns | 14.49 ns | 12.85 ns | 0.79 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectCountBenchmarks.md b/Benchmarks/SelectCountBenchmarks.md index 0db3da73d..93d15f732 100644 --- a/Benchmarks/SelectCountBenchmarks.md +++ b/Benchmarks/SelectCountBenchmarks.md @@ -4,7 +4,7 @@ [SelectCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectCountBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-------------:|-----------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 225.909 ns | 0.4993 ns | 0.3898 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 10.203 ns | 0.0223 ns | 0.0198 ns | 0.05 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 15.432 ns | 0.0342 ns | 0.0320 ns | 0.07 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 196.867 ns | 1.2466 ns | 1.1051 ns | 1.00 | 0.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 10.218 ns | 0.0308 ns | 0.0273 ns | 0.05 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 15.495 ns | 0.0355 ns | 0.0314 ns | 0.08 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 802.029 ns | 2.6396 ns | 2.3399 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 761.393 ns | 3.4969 ns | 3.2710 ns | 0.95 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 144.689 ns | 0.3393 ns | 0.3174 ns | 0.18 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 817.248 ns | 4.7910 ns | 4.0007 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 763.890 ns | 5.3349 ns | 4.7292 ns | 0.94 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 146.331 ns | 0.3951 ns | 0.3696 ns | 0.18 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 827.683 ns | 4.5779 ns | 3.8227 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 762.567 ns | 1.9828 ns | 1.6557 ns | 0.92 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 16.523 ns | 0.0372 ns | 0.0329 ns | 0.02 | 0.00 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 809.252 ns | 4.1536 ns | 3.6821 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 736.884 ns | 1.7281 ns | 1.6165 ns | 0.91 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 16.493 ns | 0.0749 ns | 0.0625 ns | 0.02 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 445.413 ns | 1.9880 ns | 1.7623 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Value | List_Value | 100 | 10.183 ns | 0.0367 ns | 0.0343 ns | 0.02 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 4.708 ns | 0.0297 ns | 0.0278 ns | 0.01 | 0.00 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 439.698 ns | 2.2291 ns | 2.0851 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Value | List_Value | 100 | 10.504 ns | 0.0398 ns | 0.0372 ns | 0.02 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 4.450 ns | 0.0275 ns | 0.0244 ns | 0.01 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,929.070 ns | 28.1569 ns | 23.5123 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 788.419 ns | 2.0581 ns | 1.8244 ns | 0.11 | 0.00 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,285.015 ns | 19.6921 ns | 17.4565 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 790.400 ns | 2.4782 ns | 2.1968 ns | 0.11 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 776.714 ns | 4.4453 ns | 3.9406 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 754.998 ns | 4.7763 ns | 3.9884 ns | 0.97 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 394.936 ns | 1.9683 ns | 1.5367 ns | 0.51 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 809.637 ns | 4.1360 ns | 3.8688 ns | 1.00 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 761.509 ns | 3.4922 ns | 3.2666 ns | 0.94 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 397.099 ns | 1.3983 ns | 1.2395 ns | 0.49 | 0.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 767.129 ns | 4.2155 ns | 3.7370 ns | 1.000 | 0.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 789.990 ns | 5.2898 ns | 4.9481 ns | 1.031 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.680 ns | 0.0220 ns | 0.0184 ns | 0.006 | 0.00 | - | - | - | - | +| Linq_Collection_Reference | Collection_Reference | 100 | 809.793 ns | 6.4629 ns | 5.3968 ns | 1.000 | 0.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 738.381 ns | 2.5787 ns | 2.1533 ns | 0.912 | 0.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 4.726 ns | 0.0338 ns | 0.0299 ns | 0.006 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 406.865 ns | 2.2082 ns | 2.0656 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | -| StructLinq_List_Reference | List_Reference | 100 | 786.466 ns | 7.8552 ns | 6.5595 ns | 1.93 | 0.02 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 4.550 ns | 0.0163 ns | 0.0144 ns | 0.01 | 0.00 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 430.338 ns | 4.9343 ns | 4.1204 ns | 1.00 | 0.00 | 0.0267 | - | - | 56 B | +| StructLinq_List_Reference | List_Reference | 100 | 765.248 ns | 5.5823 ns | 4.9486 ns | 1.78 | 0.03 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 4.693 ns | 0.0246 ns | 0.0230 ns | 0.01 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,970.239 ns | 23.5447 ns | 19.6609 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,397.486 ns | 3.5906 ns | 3.1830 ns | 0.20 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,910.703 ns | 32.3418 ns | 30.2525 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,432.868 ns | 2.7418 ns | 2.5647 ns | 0.21 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectManyBenchmarks.md b/Benchmarks/SelectManyBenchmarks.md index b911362e6..affe992dc 100644 --- a/Benchmarks/SelectManyBenchmarks.md +++ b/Benchmarks/SelectManyBenchmarks.md @@ -4,7 +4,7 @@ [SelectManyBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectManyBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,39 +14,39 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------- |-------------------------- |------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 2.830 μs | 0.0174 μs | 0.0155 μs | 2.829 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Array | Array | 100 | 1.226 μs | 0.0027 μs | 0.0024 μs | 1.225 μs | 0.43 | 0.00 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 1.377 μs | 0.0030 μs | 0.0028 μs | 1.377 μs | 0.49 | 0.00 | - | - | - | - | +| Linq_Array | Array | 100 | 2.756 μs | 0.0184 μs | 0.0163 μs | 2.753 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Array | Array | 100 | 1.225 μs | 0.0035 μs | 0.0033 μs | 1.224 μs | 0.44 | 0.00 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 1.381 μs | 0.0050 μs | 0.0042 μs | 1.380 μs | 0.50 | 0.00 | - | - | - | - | | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 3.236 μs | 0.0128 μs | 0.0120 μs | 3.236 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.398 μs | 0.0678 μs | 0.1416 μs | 3.308 μs | 1.06 | 0.04 | 2.3575 | - | - | 4,936 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 2.968 μs | 0.0281 μs | 0.0262 μs | 2.964 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 3.670 μs | 0.0176 μs | 0.0147 μs | 3.668 μs | 1.24 | 0.01 | 2.3575 | - | - | 4,936 B | | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 3.003 μs | 0.0124 μs | 0.0110 μs | 3.000 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.304 μs | 0.0110 μs | 0.0103 μs | 3.305 μs | 1.10 | 0.01 | 2.3575 | - | - | 4,936 B | +| Linq_Collection_Value | Collection_Value | 100 | 3.216 μs | 0.0163 μs | 0.0144 μs | 3.217 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 3.312 μs | 0.0209 μs | 0.0185 μs | 3.308 μs | 1.03 | 0.01 | 2.3575 | - | - | 4,936 B | | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 3.117 μs | 0.0619 μs | 0.1292 μs | 3.049 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_List_Value | List_Value | 100 | 3.453 μs | 0.0682 μs | 0.1409 μs | 3.353 μs | 1.11 | 0.03 | 2.3499 | - | - | 4,920 B | +| Linq_List_Value | List_Value | 100 | 2.993 μs | 0.0211 μs | 0.0187 μs | 2.989 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_List_Value | List_Value | 100 | 3.341 μs | 0.0109 μs | 0.0091 μs | 3.343 μs | 1.12 | 0.01 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 11.580 μs | 0.0486 μs | 0.0431 μs | 11.586 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 11.621 μs | 0.0627 μs | 0.0587 μs | 11.609 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2.973 μs | 0.0111 μs | 0.0098 μs | 2.973 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 3.334 μs | 0.0154 μs | 0.0129 μs | 3.332 μs | 1.12 | 0.00 | 2.3499 | - | - | 4,920 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 3.008 μs | 0.0336 μs | 0.0298 μs | 2.996 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 3.409 μs | 0.0669 μs | 0.1322 μs | 3.331 μs | 1.19 | 0.04 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 3.263 μs | 0.0191 μs | 0.0159 μs | 3.266 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 3.481 μs | 0.0174 μs | 0.0163 μs | 3.484 μs | 1.07 | 0.01 | 2.3499 | - | - | 4,920 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 3.076 μs | 0.0604 μs | 0.1120 μs | 3.004 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 3.482 μs | 0.0154 μs | 0.0206 μs | 3.476 μs | 1.11 | 0.04 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 3.024 μs | 0.0145 μs | 0.0128 μs | 3.026 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 3.416 μs | 0.0151 μs | 0.0134 μs | 3.415 μs | 1.13 | 0.01 | 2.3499 | - | - | 4,920 B | +| Linq_List_Reference | List_Reference | 100 | 3.222 μs | 0.0175 μs | 0.0163 μs | 3.216 μs | 1.00 | 0.00 | 1.9569 | - | - | 4,096 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 3.599 μs | 0.0149 μs | 0.0140 μs | 3.599 μs | 1.12 | 0.01 | 2.3499 | - | - | 4,920 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 11.583 μs | 0.0268 μs | 0.0224 μs | 11.582 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 11.918 μs | 0.0477 μs | 0.0423 μs | 11.915 μs | 1.00 | 0.00 | 2.3346 | - | - | 4,904 B | diff --git a/Benchmarks/SelectSumBenchmarks.md b/Benchmarks/SelectSumBenchmarks.md index e5ce327fb..6df38da3a 100644 --- a/Benchmarks/SelectSumBenchmarks.md +++ b/Benchmarks/SelectSumBenchmarks.md @@ -4,7 +4,7 @@ [SelectSumBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectSumBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,48 +14,48 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 657.60 ns | 4.578 ns | 4.282 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 224.13 ns | 0.642 ns | 0.569 ns | 0.34 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 198.21 ns | 0.524 ns | 0.464 ns | 0.30 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 64.92 ns | 0.260 ns | 0.243 ns | 0.10 | - | - | - | - | +| Linq_Array | Array | 100 | 649.45 ns | 5.100 ns | 4.770 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 215.68 ns | 0.939 ns | 0.784 ns | 0.33 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 222.11 ns | 0.351 ns | 0.311 ns | 0.34 | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 64.66 ns | 0.289 ns | 0.271 ns | 0.10 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,170.10 ns | 3.796 ns | 2.964 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 789.21 ns | 4.604 ns | 4.307 ns | 0.67 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 203.36 ns | 0.654 ns | 0.580 ns | 0.17 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,153.23 ns | 5.437 ns | 4.820 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 760.14 ns | 6.392 ns | 5.666 ns | 0.66 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 203.58 ns | 0.543 ns | 0.454 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,159.29 ns | 4.584 ns | 4.288 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 784.62 ns | 5.638 ns | 4.998 ns | 0.68 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 232.75 ns | 0.688 ns | 0.610 ns | 0.20 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,188.28 ns | 11.234 ns | 10.509 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 733.31 ns | 3.357 ns | 3.140 ns | 0.62 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 210.94 ns | 1.034 ns | 0.807 ns | 0.18 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,171.90 ns | 7.967 ns | 7.452 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 367.04 ns | 3.394 ns | 3.009 ns | 0.31 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 770.35 ns | 4.159 ns | 3.890 ns | 0.66 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,170.55 ns | 10.191 ns | 7.957 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 392.49 ns | 1.152 ns | 1.021 ns | 0.34 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 767.69 ns | 2.820 ns | 2.638 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,928.20 ns | 14.613 ns | 12.202 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,994.54 ns | 2.713 ns | 2.537 ns | 0.29 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 6,939.54 ns | 31.039 ns | 27.515 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,004.69 ns | 7.381 ns | 6.543 ns | 0.29 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,180.52 ns | 6.566 ns | 5.821 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 787.10 ns | 4.083 ns | 3.819 ns | 0.67 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 758.40 ns | 3.926 ns | 3.480 ns | 0.64 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,201.44 ns | 6.594 ns | 5.845 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 762.89 ns | 3.737 ns | 3.312 ns | 0.63 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 788.19 ns | 4.610 ns | 4.312 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,254.95 ns | 8.594 ns | 7.619 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 755.09 ns | 1.902 ns | 1.779 ns | 0.60 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 763.83 ns | 3.592 ns | 3.184 ns | 0.61 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,201.80 ns | 6.314 ns | 5.906 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 733.73 ns | 4.762 ns | 4.221 ns | 0.61 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 792.80 ns | 3.573 ns | 3.167 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,248.97 ns | 4.253 ns | 3.770 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 757.15 ns | 3.574 ns | 3.343 ns | 0.61 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 813.48 ns | 1.671 ns | 1.563 ns | 0.65 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,225.54 ns | 14.180 ns | 12.571 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 758.23 ns | 4.108 ns | 3.207 ns | 0.62 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 771.48 ns | 4.268 ns | 3.784 ns | 0.63 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,076.05 ns | 16.861 ns | 14.947 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,834.07 ns | 6.980 ns | 6.529 ns | 0.40 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,894.63 ns | 27.438 ns | 24.323 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,798.15 ns | 4.396 ns | 3.897 ns | 0.41 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SelectToArrayBenchmarks.md b/Benchmarks/SelectToArrayBenchmarks.md index ce63cd1c0..7253ae362 100644 --- a/Benchmarks/SelectToArrayBenchmarks.md +++ b/Benchmarks/SelectToArrayBenchmarks.md @@ -4,7 +4,7 @@ [SelectToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 263.39 ns | 1.174 ns | 1.041 ns | 263.24 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | -| StructLinq_Array | Array | 100 | 233.94 ns | 4.618 ns | 8.787 ns | 229.90 ns | 0.93 | 0.04 | 0.2027 | - | - | 424 B | -| LinqFasterSIMD_Array | Array | 100 | 66.14 ns | 0.757 ns | 0.671 ns | 66.26 ns | 0.25 | 0.00 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 272.16 ns | 1.452 ns | 1.358 ns | 271.94 ns | 1.03 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array_SIMD | Array | 100 | 83.63 ns | 0.812 ns | 0.720 ns | 83.73 ns | 0.32 | 0.00 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,043.22 ns | 4.723 ns | 4.187 ns | 1,043.66 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,067.19 ns | 7.687 ns | 6.814 ns | 1,066.65 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 592.14 ns | 2.533 ns | 2.369 ns | 592.28 ns | 0.57 | 0.00 | 0.2022 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,044.28 ns | 4.906 ns | 4.589 ns | 1,042.96 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,070.18 ns | 7.330 ns | 6.121 ns | 1,069.23 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 300.70 ns | 1.466 ns | 1.300 ns | 300.77 ns | 0.29 | 0.00 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 474.07 ns | 9.454 ns | 17.988 ns | 461.17 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Value | List_Value | 100 | 496.84 ns | 8.562 ns | 8.009 ns | 499.34 ns | 1.06 | 0.04 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 926.74 ns | 18.420 ns | 24.590 ns | 933.41 ns | 1.94 | 0.07 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,448.67 ns | 26.093 ns | 23.131 ns | 7,454.25 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,347.19 ns | 6.148 ns | 5.450 ns | 2,347.48 ns | 0.32 | 0.00 | 0.5646 | - | - | 1,184 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,039.00 ns | 5.957 ns | 5.573 ns | 1,038.81 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,068.03 ns | 5.654 ns | 5.012 ns | 1,066.01 ns | 1.03 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,066.39 ns | 4.384 ns | 3.886 ns | 1,066.37 ns | 1.03 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,038.34 ns | 6.737 ns | 5.972 ns | 1,037.87 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,061.14 ns | 7.619 ns | 6.754 ns | 1,058.89 ns | 1.02 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 852.00 ns | 16.759 ns | 13.994 ns | 855.63 ns | 0.82 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 441.69 ns | 8.744 ns | 15.542 ns | 432.00 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,071.63 ns | 5.571 ns | 5.211 ns | 1,069.65 ns | 2.33 | 0.06 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 831.73 ns | 2.493 ns | 1.946 ns | 831.83 ns | 1.80 | 0.02 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,684.56 ns | 48.657 ns | 45.514 ns | 7,685.18 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,149.51 ns | 8.486 ns | 7.523 ns | 3,149.03 ns | 0.41 | 0.00 | 0.5798 | - | - | 1,216 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 240.54 ns | 1.365 ns | 1.210 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | +| StructLinq_Array | Array | 100 | 273.57 ns | 1.555 ns | 1.454 ns | 1.14 | 0.01 | 0.2027 | - | - | 424 B | +| LinqFasterSIMD_Array | Array | 100 | 64.64 ns | 1.071 ns | 1.002 ns | 0.27 | 0.00 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 251.62 ns | 0.888 ns | 0.831 ns | 1.05 | 0.01 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array_SIMD | Array | 100 | 85.58 ns | 1.113 ns | 1.041 ns | 0.36 | 0.01 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,071.24 ns | 5.051 ns | 4.725 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,052.71 ns | 5.609 ns | 4.972 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 610.37 ns | 7.465 ns | 6.233 ns | 0.57 | 0.01 | 0.2022 | - | - | 424 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,152.86 ns | 6.149 ns | 5.752 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,057.94 ns | 3.803 ns | 3.175 ns | 0.92 | 0.00 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 366.46 ns | 2.656 ns | 2.355 ns | 0.32 | 0.00 | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 481.36 ns | 2.718 ns | 2.270 ns | 1.00 | 0.00 | 0.2289 | - | - | 480 B | +| StructLinq_List_Value | List_Value | 100 | 420.23 ns | 8.393 ns | 12.037 ns | 0.86 | 0.03 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 860.09 ns | 3.344 ns | 2.792 ns | 1.79 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,727.46 ns | 38.027 ns | 31.754 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,347.46 ns | 8.091 ns | 7.568 ns | 0.30 | 0.00 | 0.5646 | - | - | 1,184 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,181.79 ns | 7.270 ns | 6.801 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,059.90 ns | 3.879 ns | 3.439 ns | 0.90 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,137.82 ns | 7.782 ns | 6.898 ns | 0.96 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,091.31 ns | 6.064 ns | 5.375 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,064.82 ns | 5.197 ns | 4.607 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 778.34 ns | 3.808 ns | 3.376 ns | 0.71 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 446.99 ns | 1.802 ns | 1.407 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,092.56 ns | 6.810 ns | 6.037 ns | 2.44 | 0.02 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 841.76 ns | 3.431 ns | 3.042 ns | 1.88 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,716.34 ns | 35.734 ns | 29.840 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,145.91 ns | 8.983 ns | 8.403 ns | 0.41 | 0.00 | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/SelectToListBenchmarks.md b/Benchmarks/SelectToListBenchmarks.md index ab920775e..b0d3fb5f6 100644 --- a/Benchmarks/SelectToListBenchmarks.md +++ b/Benchmarks/SelectToListBenchmarks.md @@ -4,7 +4,7 @@ [SelectToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,48 +14,48 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 320.50 ns | 6.400 ns | 9.773 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | -| StructLinq_Array | Array | 100 | 289.97 ns | 5.679 ns | 7.582 ns | 0.91 | 0.03 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 261.91 ns | 0.801 ns | 0.669 ns | 0.84 | 0.03 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array_SIMD | Array | 100 | 95.19 ns | 0.595 ns | 0.465 ns | 0.31 | 0.01 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,032.92 ns | 9.620 ns | 7.511 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,067.34 ns | 5.047 ns | 4.721 ns | 1.03 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 665.69 ns | 4.053 ns | 3.384 ns | 0.64 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,083.62 ns | 20.187 ns | 33.727 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,099.09 ns | 4.668 ns | 4.367 ns | 1.03 | 0.04 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 324.91 ns | 2.071 ns | 1.729 ns | 0.30 | 0.01 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 493.88 ns | 3.038 ns | 2.372 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Value | List_Value | 100 | 435.24 ns | 2.380 ns | 2.110 ns | 0.88 | 0.01 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 794.59 ns | 2.815 ns | 2.633 ns | 1.61 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,304.85 ns | 22.550 ns | 19.990 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,538.83 ns | 20.180 ns | 18.876 ns | 0.35 | 0.00 | 0.5798 | - | - | 1,216 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,033.12 ns | 7.173 ns | 5.601 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,089.03 ns | 21.115 ns | 25.931 ns | 1.04 | 0.03 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,128.37 ns | 6.318 ns | 5.910 ns | 1.09 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,111.77 ns | 6.977 ns | 6.185 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,111.52 ns | 22.062 ns | 28.687 ns | 1.01 | 0.03 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 784.16 ns | 3.117 ns | 2.763 ns | 0.71 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 509.97 ns | 2.207 ns | 1.957 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,064.95 ns | 5.469 ns | 5.116 ns | 2.09 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 885.68 ns | 2.860 ns | 2.535 ns | 1.74 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,530.75 ns | 26.527 ns | 23.515 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,319.93 ns | 26.025 ns | 23.071 ns | 0.44 | 0.00 | 0.5951 | - | - | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 338.38 ns | 2.006 ns | 1.876 ns | 338.43 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | +| StructLinq_Array | Array | 100 | 263.67 ns | 5.286 ns | 7.056 ns | 265.41 ns | 0.77 | 0.03 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 285.53 ns | 1.874 ns | 1.565 ns | 285.41 ns | 0.84 | 0.01 | 0.2179 | - | - | 456 B | +| Hyperlinq_Array_SIMD | Array | 100 | 91.48 ns | 1.203 ns | 1.126 ns | 91.78 ns | 0.27 | 0.00 | 0.2180 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,033.64 ns | 5.686 ns | 5.318 ns | 1,033.44 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,083.62 ns | 5.790 ns | 5.416 ns | 1,083.91 ns | 1.05 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 627.44 ns | 9.992 ns | 20.185 ns | 618.87 ns | 0.59 | 0.01 | 0.2174 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,035.14 ns | 7.299 ns | 6.470 ns | 1,033.06 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,068.83 ns | 5.827 ns | 5.165 ns | 1,069.30 ns | 1.03 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 282.33 ns | 0.968 ns | 0.858 ns | 282.33 ns | 0.27 | 0.00 | 0.2179 | - | - | 456 B | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 464.89 ns | 1.236 ns | 1.096 ns | 464.88 ns | 1.00 | 0.00 | 0.2446 | - | - | 512 B | +| StructLinq_List_Value | List_Value | 100 | 443.45 ns | 2.158 ns | 1.913 ns | 443.73 ns | 0.95 | 0.00 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 844.44 ns | 5.911 ns | 5.240 ns | 845.39 ns | 1.82 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,488.02 ns | 54.654 ns | 51.124 ns | 7,503.97 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,433.89 ns | 20.006 ns | 18.713 ns | 2,437.28 ns | 0.33 | 0.00 | 0.5798 | - | - | 1,216 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,043.46 ns | 4.850 ns | 4.050 ns | 1,042.38 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,080.29 ns | 4.157 ns | 3.685 ns | 1,079.25 ns | 1.04 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,144.40 ns | 7.280 ns | 6.810 ns | 1,145.30 ns | 1.10 | 0.01 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,044.52 ns | 4.615 ns | 4.317 ns | 1,043.08 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,062.79 ns | 6.705 ns | 5.944 ns | 1,061.99 ns | 1.02 | 0.01 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 837.38 ns | 3.721 ns | 3.107 ns | 836.64 ns | 0.80 | 0.00 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 508.62 ns | 2.907 ns | 2.720 ns | 507.65 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,083.30 ns | 6.355 ns | 4.962 ns | 1,082.39 ns | 2.13 | 0.02 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 838.80 ns | 16.450 ns | 20.804 ns | 849.94 ns | 1.63 | 0.05 | 0.2327 | - | - | 488 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,339.88 ns | 20.278 ns | 16.933 ns | 7,342.17 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,191.47 ns | 11.989 ns | 10.628 ns | 3,191.26 ns | 0.43 | 0.00 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/SingleBenchmarks.md b/Benchmarks/SingleBenchmarks.md index c4b065b7d..b11f4ae92 100644 --- a/Benchmarks/SingleBenchmarks.md +++ b/Benchmarks/SingleBenchmarks.md @@ -4,7 +4,7 @@ [SingleBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SingleBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,38 +14,38 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------- |-------------------------- |----------:|----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 12.650 ns | 0.0619 ns | 0.0579 ns | 12.631 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 13.997 ns | 0.0338 ns | 0.0282 ns | 13.997 ns | 1.11 | 0.00 | - | - | - | - | +| Linq_Array | Array | 12.526 ns | 0.0206 ns | 0.0172 ns | 12.529 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_Array | Array | 14.608 ns | 0.0273 ns | 0.0228 ns | 14.603 ns | 1.17 | 0.00 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 25.430 ns | 0.0973 ns | 0.0863 ns | 25.441 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 16.824 ns | 0.0445 ns | 0.0372 ns | 16.827 ns | 0.66 | 0.00 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 27.451 ns | 0.5681 ns | 0.9174 ns | 26.928 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 16.618 ns | 0.0609 ns | 0.0540 ns | 16.613 ns | 0.59 | 0.02 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 28.575 ns | 0.1370 ns | 0.1281 ns | 28.622 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 19.161 ns | 0.0675 ns | 0.0632 ns | 19.128 ns | 0.67 | 0.00 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 27.694 ns | 0.5846 ns | 1.0690 ns | 27.020 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 19.865 ns | 0.0745 ns | 0.0697 ns | 19.860 ns | 0.68 | 0.01 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 8.521 ns | 0.0541 ns | 0.0480 ns | 8.511 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 21.722 ns | 0.0978 ns | 0.0867 ns | 21.724 ns | 2.55 | 0.02 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 8.626 ns | 0.0731 ns | 0.0684 ns | 8.596 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 21.742 ns | 0.1679 ns | 0.1488 ns | 21.691 ns | 2.52 | 0.03 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 74.208 ns | 0.1987 ns | 0.1551 ns | 74.239 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 75.792 ns | 0.5077 ns | 0.4749 ns | 75.774 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 25.550 ns | 0.1125 ns | 0.1052 ns | 25.546 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 20.445 ns | 0.1046 ns | 0.0979 ns | 20.438 ns | 0.80 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 26.768 ns | 0.2276 ns | 0.2018 ns | 26.724 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 22.935 ns | 0.4758 ns | 0.7266 ns | 23.214 ns | 0.84 | 0.03 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 27.198 ns | 0.5710 ns | 0.9849 ns | 26.621 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 20.031 ns | 0.4175 ns | 1.0003 ns | 19.390 ns | 0.76 | 0.04 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 28.074 ns | 0.5883 ns | 1.1334 ns | 27.380 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 18.836 ns | 0.4056 ns | 0.3596 ns | 18.713 ns | 0.68 | 0.02 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 8.611 ns | 0.0424 ns | 0.0376 ns | 8.615 ns | 1.00 | 0.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 21.548 ns | 0.2435 ns | 0.2034 ns | 21.548 ns | 2.50 | 0.02 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 8.563 ns | 0.0461 ns | 0.0408 ns | 8.560 ns | 1.00 | 0.00 | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 24.796 ns | 0.5120 ns | 0.5478 ns | 24.930 ns | 2.89 | 0.08 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 73.466 ns | 0.3094 ns | 0.2743 ns | 73.398 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 79.490 ns | 0.3291 ns | 0.2917 ns | 79.473 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SkipTakeBenchmarks.md b/Benchmarks/SkipTakeBenchmarks.md index f4fc05d30..c0b7c0148 100644 --- a/Benchmarks/SkipTakeBenchmarks.md +++ b/Benchmarks/SkipTakeBenchmarks.md @@ -4,7 +4,7 @@ [SkipTakeBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SkipTakeBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,54 +14,54 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Skip | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |----- |------ |------------:|----------:|----------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 100 | 917.40 ns | 6.022 ns | 5.029 ns | 1.00 | 0.0458 | - | - | 96 B | -| StructLinq_Array | Array | 100 | 100 | 50.18 ns | 0.154 ns | 0.136 ns | 0.05 | - | - | - | - | -| Hyperlinq_Array_For | Array | 100 | 100 | 203.23 ns | 0.551 ns | 0.515 ns | 0.22 | - | - | - | - | -| Hyperlinq_Array_Foreach | Array | 100 | 100 | 179.89 ns | 0.532 ns | 0.444 ns | 0.20 | - | - | - | - | -| Hyperlinq_Span_For | Array | 100 | 100 | 79.62 ns | 0.389 ns | 0.344 ns | 0.09 | - | - | - | - | -| Hyperlinq_Span_Foreach | Array | 100 | 100 | 169.75 ns | 0.372 ns | 0.330 ns | 0.19 | - | - | - | - | -| Hyperlinq_Memory_For | Array | 100 | 100 | 226.10 ns | 0.736 ns | 0.575 ns | 0.25 | - | - | - | - | -| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 179.65 ns | 1.394 ns | 1.304 ns | 0.20 | - | - | - | - | +| Linq_Array | Array | 100 | 100 | 845.25 ns | 3.560 ns | 3.330 ns | 1.00 | 0.0458 | - | - | 96 B | +| StructLinq_Array | Array | 100 | 100 | 50.19 ns | 0.296 ns | 0.262 ns | 0.06 | - | - | - | - | +| Hyperlinq_Array_For | Array | 100 | 100 | 227.75 ns | 0.798 ns | 0.707 ns | 0.27 | - | - | - | - | +| Hyperlinq_Array_Foreach | Array | 100 | 100 | 181.95 ns | 0.795 ns | 0.744 ns | 0.22 | - | - | - | - | +| Hyperlinq_Span_For | Array | 100 | 100 | 81.07 ns | 0.268 ns | 0.237 ns | 0.10 | - | - | - | - | +| Hyperlinq_Span_Foreach | Array | 100 | 100 | 172.28 ns | 0.457 ns | 0.427 ns | 0.20 | - | - | - | - | +| Hyperlinq_Memory_For | Array | 100 | 100 | 227.28 ns | 1.257 ns | 1.115 ns | 0.27 | - | - | - | - | +| Hyperlinq_Memory_Foreach | Array | 100 | 100 | 177.62 ns | 1.639 ns | 1.533 ns | 0.21 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,460.61 ns | 6.434 ns | 5.024 ns | 1.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 984.29 ns | 4.626 ns | 4.101 ns | 0.67 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 444.17 ns | 1.463 ns | 1.297 ns | 0.30 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,451.84 ns | 4.117 ns | 3.649 ns | 1.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 1,044.34 ns | 10.380 ns | 9.202 ns | 0.72 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 100 | 444.77 ns | 1.408 ns | 1.317 ns | 0.31 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,458.69 ns | 5.730 ns | 5.079 ns | 1.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 977.11 ns | 5.175 ns | 4.321 ns | 0.67 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 582.24 ns | 1.985 ns | 1.857 ns | 0.40 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 100 | 1,456.82 ns | 8.496 ns | 7.531 ns | 1.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 100 | 1,009.74 ns | 6.760 ns | 5.992 ns | 0.69 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 100 | 599.00 ns | 2.087 ns | 1.743 ns | 0.41 | - | - | - | - | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 100 | 804.69 ns | 3.999 ns | 3.741 ns | 1.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Value | List_Value | 100 | 100 | 224.84 ns | 0.738 ns | 0.616 ns | 0.28 | - | - | - | - | -| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 657.43 ns | 4.149 ns | 3.678 ns | 0.82 | - | - | - | - | -| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 219.18 ns | 1.247 ns | 1.105 ns | 0.27 | - | - | - | - | +| Linq_List_Value | List_Value | 100 | 100 | 795.57 ns | 8.248 ns | 7.312 ns | 1.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Value | List_Value | 100 | 100 | 224.50 ns | 0.712 ns | 0.594 ns | 0.28 | - | - | - | - | +| Hyperlinq_List_Value_For | List_Value | 100 | 100 | 652.01 ns | 3.322 ns | 2.944 ns | 0.82 | - | - | - | - | +| Hyperlinq_List_Value_Foreach | List_Value | 100 | 100 | 219.90 ns | 0.867 ns | 0.769 ns | 0.28 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 8,311.02 ns | 26.143 ns | 21.831 ns | 1.00 | 0.0763 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 4,337.00 ns | 15.564 ns | 13.797 ns | 0.52 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 8,059.23 ns | 34.660 ns | 30.725 ns | 1.00 | 0.0763 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 100 | 4,271.00 ns | 11.989 ns | 10.628 ns | 0.53 | - | - | - | - | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,459.67 ns | 3.143 ns | 2.454 ns | 1.00 | 0.0687 | - | - | 144 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 954.07 ns | 6.370 ns | 5.959 ns | 0.65 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,063.69 ns | 6.712 ns | 5.605 ns | 0.73 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,497.90 ns | 5.207 ns | 4.616 ns | 1.00 | 0.0687 | - | - | 144 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,047.97 ns | 6.071 ns | 5.679 ns | 0.70 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 100 | 1,103.82 ns | 4.664 ns | 4.362 ns | 0.74 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,482.71 ns | 5.643 ns | 5.003 ns | 1.00 | 0.0687 | - | - | 144 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 978.50 ns | 9.557 ns | 8.472 ns | 0.66 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 1,311.83 ns | 5.852 ns | 4.886 ns | 0.88 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 100 | 1,450.03 ns | 5.975 ns | 5.296 ns | 1.00 | 0.0687 | - | - | 144 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 100 | 1,016.30 ns | 6.790 ns | 6.352 ns | 0.70 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 100 | 1,271.16 ns | 6.107 ns | 5.100 ns | 0.88 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 100 | 803.87 ns | 4.946 ns | 4.385 ns | 1.00 | 0.0458 | - | - | 96 B | -| StructLinq_List_Reference | List_Reference | 100 | 100 | 977.06 ns | 5.623 ns | 4.984 ns | 1.22 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 625.59 ns | 2.119 ns | 1.769 ns | 0.78 | - | - | - | - | -| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 244.13 ns | 2.158 ns | 1.913 ns | 0.30 | - | - | - | - | +| Linq_List_Reference | List_Reference | 100 | 100 | 846.45 ns | 3.989 ns | 3.536 ns | 1.00 | 0.0458 | - | - | 96 B | +| StructLinq_List_Reference | List_Reference | 100 | 100 | 1,040.79 ns | 3.616 ns | 3.206 ns | 1.23 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference_For | List_Reference | 100 | 100 | 651.21 ns | 3.925 ns | 3.672 ns | 0.77 | - | - | - | - | +| Hyperlinq_List_Reference_Foreach | List_Reference | 100 | 100 | 219.32 ns | 1.068 ns | 0.892 ns | 0.26 | - | - | - | - | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 8,244.44 ns | 37.434 ns | 35.016 ns | 1.00 | 0.0763 | - | - | 176 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 5,434.69 ns | 20.316 ns | 18.009 ns | 0.66 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 8,265.76 ns | 36.451 ns | 30.438 ns | 1.00 | 0.0763 | - | - | 176 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 100 | 5,275.23 ns | 18.599 ns | 17.397 ns | 0.64 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/SumBenchmarks.md b/Benchmarks/SumBenchmarks.md index 528b091f6..b9fbe9ee0 100644 --- a/Benchmarks/SumBenchmarks.md +++ b/Benchmarks/SumBenchmarks.md @@ -4,7 +4,7 @@ [SumBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SumBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,48 +14,48 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 411.64 ns | 2.148 ns | 1.904 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | Array | 100 | 60.79 ns | 0.234 ns | 0.196 ns | 0.15 | 0.00 | - | - | - | - | -| LinqFasterSIMD_Array | Array | 100 | 10.55 ns | 0.057 ns | 0.051 ns | 0.03 | 0.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 21.71 ns | 0.050 ns | 0.047 ns | 0.05 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 627.54 ns | 3.594 ns | 3.186 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 569.81 ns | 2.575 ns | 2.409 ns | 0.91 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 200.57 ns | 0.525 ns | 0.410 ns | 0.32 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 623.95 ns | 6.534 ns | 5.792 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 596.64 ns | 1.989 ns | 1.661 ns | 0.96 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 208.77 ns | 0.537 ns | 0.448 ns | 0.33 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 620.76 ns | 2.622 ns | 2.190 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Value | List_Value | 100 | 222.64 ns | 0.895 ns | 0.747 ns | 0.36 | 0.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 637.95 ns | 5.100 ns | 4.521 ns | 1.03 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,605.31 ns | 3.396 ns | 3.011 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 827.90 ns | 0.962 ns | 0.853 ns | 0.52 | 0.00 | - | - | - | - | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 629.08 ns | 11.723 ns | 12.039 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 568.72 ns | 3.007 ns | 2.813 ns | 0.90 | 0.02 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 626.02 ns | 2.194 ns | 2.052 ns | 1.00 | 0.02 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 626.42 ns | 4.324 ns | 3.833 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 569.32 ns | 3.324 ns | 3.109 ns | 0.91 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 600.52 ns | 3.186 ns | 2.981 ns | 0.96 | 0.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 621.36 ns | 3.587 ns | 2.995 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Reference | List_Reference | 100 | 572.35 ns | 7.993 ns | 6.674 ns | 0.92 | 0.01 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 631.71 ns | 2.343 ns | 2.192 ns | 1.02 | 0.00 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,614.63 ns | 5.232 ns | 4.894 ns | 1.00 | 0.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,637.74 ns | 4.182 ns | 3.912 ns | 1.01 | 0.00 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 413.92 ns | 2.660 ns | 2.221 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 60.74 ns | 0.200 ns | 0.187 ns | 0.15 | - | - | - | - | +| LinqFasterSIMD_Array | Array | 100 | 10.63 ns | 0.075 ns | 0.071 ns | 0.03 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 22.32 ns | 0.077 ns | 0.068 ns | 0.05 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 624.83 ns | 5.028 ns | 4.457 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 574.83 ns | 2.941 ns | 2.607 ns | 0.92 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 202.11 ns | 0.557 ns | 0.493 ns | 0.32 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 616.91 ns | 4.091 ns | 3.627 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 573.70 ns | 4.680 ns | 3.908 ns | 0.93 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 208.10 ns | 0.371 ns | 0.347 ns | 0.34 | - | - | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 607.47 ns | 3.830 ns | 3.198 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 223.68 ns | 0.839 ns | 0.744 ns | 0.37 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 635.26 ns | 2.463 ns | 2.057 ns | 1.05 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,612.14 ns | 6.534 ns | 5.793 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 830.85 ns | 2.255 ns | 1.999 ns | 0.52 | - | - | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 616.47 ns | 2.313 ns | 2.164 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 573.38 ns | 2.951 ns | 2.616 ns | 0.93 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 597.88 ns | 3.175 ns | 2.814 ns | 0.97 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 616.39 ns | 3.075 ns | 2.726 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 575.50 ns | 3.010 ns | 2.514 ns | 0.93 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 627.72 ns | 2.465 ns | 2.306 ns | 1.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 620.51 ns | 3.599 ns | 3.191 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 574.04 ns | 2.878 ns | 2.551 ns | 0.93 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 634.92 ns | 2.786 ns | 2.606 ns | 1.02 | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,606.77 ns | 2.223 ns | 1.856 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,641.25 ns | 3.209 ns | 2.680 ns | 1.02 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ToArrayBenchmarks.md b/Benchmarks/ToArrayBenchmarks.md index 14ac16c85..44bf8d0f7 100644 --- a/Benchmarks/ToArrayBenchmarks.md +++ b/Benchmarks/ToArrayBenchmarks.md @@ -4,7 +4,7 @@ [ToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 55.19 ns | 0.358 ns | 0.334 ns | 55.11 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Array | Array | 100 | 86.46 ns | 1.273 ns | 1.191 ns | 86.72 ns | 1.57 | 0.02 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 39.77 ns | 0.860 ns | 2.384 ns | 38.63 ns | 0.73 | 0.04 | 0.2027 | - | - | 424 B | +| Linq_Array | Array | 100 | 51.99 ns | 0.388 ns | 0.344 ns | 51.98 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Array | Array | 100 | 88.24 ns | 1.817 ns | 3.671 ns | 86.44 ns | 1.80 | 0.05 | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 38.94 ns | 0.855 ns | 2.222 ns | 37.84 ns | 0.72 | 0.03 | 0.2027 | - | - | 424 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 912.67 ns | 6.263 ns | 5.858 ns | 910.52 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 914.68 ns | 17.210 ns | 17.673 ns | 922.76 ns | 1.00 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 533.93 ns | 3.817 ns | 3.187 ns | 533.41 ns | 0.58 | 0.01 | 0.2213 | - | - | 464 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 938.66 ns | 5.905 ns | 5.523 ns | 939.96 ns | 1.00 | 0.00 | 0.5646 | - | - | 1,184 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 914.83 ns | 18.130 ns | 20.152 ns | 926.03 ns | 0.97 | 0.03 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 553.19 ns | 2.745 ns | 2.433 ns | 553.33 ns | 0.59 | 0.00 | 0.2213 | - | - | 464 B | | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 53.90 ns | 0.362 ns | 0.339 ns | 53.84 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 912.65 ns | 6.331 ns | 4.943 ns | 912.21 ns | 16.94 | 0.13 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 123.65 ns | 2.089 ns | 1.954 ns | 123.08 ns | 2.29 | 0.04 | 0.2217 | - | - | 464 B | +| Linq_Collection_Value | Collection_Value | 100 | 50.42 ns | 0.667 ns | 0.591 ns | 50.51 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 893.83 ns | 4.701 ns | 3.926 ns | 893.72 ns | 17.75 | 0.21 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 122.53 ns | 2.136 ns | 1.998 ns | 121.88 ns | 2.43 | 0.05 | 0.2217 | - | - | 464 B | | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 51.02 ns | 0.731 ns | 0.683 ns | 51.12 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Value | List_Value | 100 | 249.29 ns | 1.904 ns | 1.688 ns | 248.64 ns | 4.89 | 0.08 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 60.35 ns | 1.193 ns | 1.057 ns | 60.58 ns | 1.18 | 0.03 | 0.2142 | - | - | 448 B | +| Linq_List_Value | List_Value | 100 | 47.30 ns | 0.782 ns | 0.732 ns | 47.49 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Value | List_Value | 100 | 248.65 ns | 1.309 ns | 1.225 ns | 248.55 ns | 5.26 | 0.08 | 0.2027 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 64.00 ns | 0.635 ns | 0.594 ns | 64.08 ns | 1.35 | 0.02 | 0.2142 | - | - | 448 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,909.56 ns | 8.408 ns | 7.865 ns | 1,907.95 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,230.32 ns | 24.459 ns | 27.186 ns | 1,239.69 ns | 0.64 | 0.02 | 0.5646 | - | - | 1,184 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,936.42 ns | 7.609 ns | 6.745 ns | 1,934.24 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,163.24 ns | 4.662 ns | 4.133 ns | 1,162.48 ns | 0.60 | 0.00 | 0.5646 | - | - | 1,184 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 913.09 ns | 8.407 ns | 7.452 ns | 909.57 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 926.00 ns | 18.334 ns | 21.825 ns | 917.15 ns | 1.00 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,003.28 ns | 19.344 ns | 18.999 ns | 994.88 ns | 1.10 | 0.03 | 0.2174 | - | - | 456 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,010.97 ns | 7.290 ns | 6.819 ns | 1,009.86 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 892.07 ns | 4.902 ns | 3.827 ns | 891.46 ns | 0.88 | 0.01 | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 983.87 ns | 4.211 ns | 3.733 ns | 983.44 ns | 0.97 | 0.01 | 0.2174 | - | - | 456 B | | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 50.36 ns | 0.737 ns | 0.959 ns | 50.52 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 877.92 ns | 4.470 ns | 3.962 ns | 877.55 ns | 17.38 | 0.31 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 57.69 ns | 0.846 ns | 0.750 ns | 57.82 ns | 1.14 | 0.03 | 0.2142 | - | - | 448 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 45.61 ns | 0.839 ns | 0.784 ns | 45.79 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 933.35 ns | 14.980 ns | 13.279 ns | 937.10 ns | 20.49 | 0.49 | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 57.47 ns | 1.221 ns | 2.973 ns | 57.08 ns | 1.28 | 0.06 | 0.2142 | - | - | 448 B | | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 55.39 ns | 0.772 ns | 0.684 ns | 55.34 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Reference | List_Reference | 100 | 917.81 ns | 2.756 ns | 2.152 ns | 918.00 ns | 16.58 | 0.22 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 61.65 ns | 1.291 ns | 1.326 ns | 62.07 ns | 1.11 | 0.02 | 0.2142 | - | - | 448 B | +| Linq_List_Reference | List_Reference | 100 | 46.85 ns | 0.781 ns | 0.731 ns | 46.91 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | +| StructLinq_List_Reference | List_Reference | 100 | 894.50 ns | 5.397 ns | 4.784 ns | 894.58 ns | 19.05 | 0.28 | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 58.53 ns | 0.781 ns | 0.730 ns | 58.43 ns | 1.25 | 0.02 | 0.2142 | - | - | 448 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,915.98 ns | 5.794 ns | 5.420 ns | 1,913.48 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,069.53 ns | 40.202 ns | 39.484 ns | 2,085.08 ns | 1.08 | 0.02 | 0.5798 | - | - | 1,216 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,937.50 ns | 6.890 ns | 5.379 ns | 1,938.36 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,987.66 ns | 5.304 ns | 4.702 ns | 1,987.87 ns | 1.03 | 0.00 | 0.5798 | - | - | 1,216 B | diff --git a/Benchmarks/ToListBenchmarks.md b/Benchmarks/ToListBenchmarks.md index 0e51ae742..643030fa9 100644 --- a/Benchmarks/ToListBenchmarks.md +++ b/Benchmarks/ToListBenchmarks.md @@ -4,7 +4,7 @@ [ToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 61.67 ns | 0.616 ns | 0.822 ns | 61.68 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Array | Array | 100 | 92.58 ns | 1.076 ns | 0.954 ns | 92.80 ns | 1.50 | 0.03 | 0.2180 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 47.53 ns | 0.750 ns | 0.626 ns | 47.56 ns | 0.77 | 0.01 | 0.2180 | - | - | 456 B | +| Linq_Array | Array | 100 | 58.81 ns | 0.505 ns | 0.473 ns | 58.83 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Array | Array | 100 | 94.06 ns | 1.231 ns | 1.151 ns | 93.99 ns | 1.60 | 0.02 | 0.2180 | - | - | 456 B | +| Hyperlinq_Array | Array | 100 | 48.82 ns | 1.053 ns | 2.661 ns | 47.60 ns | 0.85 | 0.05 | 0.2180 | - | - | 456 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 938.37 ns | 18.802 ns | 37.550 ns | 915.59 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 923.96 ns | 4.179 ns | 3.263 ns | 924.89 ns | 0.97 | 0.04 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 598.19 ns | 4.437 ns | 3.934 ns | 596.98 ns | 0.63 | 0.03 | 0.2365 | - | - | 496 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 859.60 ns | 17.141 ns | 34.625 ns | 837.18 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 972.46 ns | 7.019 ns | 6.565 ns | 973.93 ns | 1.09 | 0.04 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 618.71 ns | 4.105 ns | 3.428 ns | 618.72 ns | 0.68 | 0.01 | 0.2365 | - | - | 496 B | | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 55.73 ns | 1.109 ns | 2.700 ns | 54.42 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 967.01 ns | 6.672 ns | 6.241 ns | 967.52 ns | 17.09 | 0.86 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 146.33 ns | 2.101 ns | 1.862 ns | 145.92 ns | 2.60 | 0.13 | 0.2370 | - | - | 496 B | +| Linq_Collection_Value | Collection_Value | 100 | 57.86 ns | 0.921 ns | 0.816 ns | 57.93 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 919.81 ns | 4.114 ns | 3.849 ns | 921.58 ns | 15.91 | 0.20 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 147.30 ns | 2.179 ns | 2.038 ns | 146.28 ns | 2.54 | 0.06 | 0.2370 | - | - | 496 B | | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 58.00 ns | 1.225 ns | 2.888 ns | 56.54 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Value | List_Value | 100 | 255.08 ns | 0.820 ns | 0.685 ns | 254.91 ns | 4.23 | 0.24 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 81.62 ns | 1.424 ns | 1.262 ns | 81.68 ns | 1.35 | 0.08 | 0.2295 | - | - | 480 B | +| Linq_List_Value | List_Value | 100 | 54.34 ns | 0.603 ns | 0.535 ns | 54.40 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Value | List_Value | 100 | 257.40 ns | 1.623 ns | 1.518 ns | 257.40 ns | 4.74 | 0.06 | 0.2179 | - | - | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 78.38 ns | 1.240 ns | 1.099 ns | 78.55 ns | 1.44 | 0.02 | 0.2295 | - | - | 480 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,980.45 ns | 6.761 ns | 6.324 ns | 1,979.57 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,221.63 ns | 6.614 ns | 6.186 ns | 1,221.44 ns | 0.62 | 0.00 | 0.5798 | - | - | 1,216 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,933.29 ns | 37.450 ns | 48.695 ns | 1,962.87 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,218.93 ns | 6.225 ns | 5.198 ns | 1,219.33 ns | 0.64 | 0.02 | 0.5798 | - | - | 1,216 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 885.62 ns | 5.734 ns | 4.788 ns | 884.69 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 937.51 ns | 4.458 ns | 3.723 ns | 937.76 ns | 1.06 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,073.53 ns | 4.959 ns | 4.639 ns | 1,073.45 ns | 1.21 | 0.01 | 0.2327 | - | - | 488 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 836.68 ns | 3.132 ns | 2.776 ns | 836.44 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 919.99 ns | 5.034 ns | 4.462 ns | 919.05 ns | 1.10 | 0.00 | 0.2327 | - | - | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,041.93 ns | 20.075 ns | 24.653 ns | 1,046.08 ns | 1.24 | 0.03 | 0.2327 | - | - | 488 B | | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 54.97 ns | 0.788 ns | 0.737 ns | 55.20 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 956.73 ns | 18.374 ns | 18.869 ns | 966.16 ns | 17.38 | 0.46 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 71.90 ns | 0.683 ns | 0.533 ns | 71.88 ns | 1.31 | 0.02 | 0.2295 | - | - | 480 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 52.49 ns | 0.880 ns | 0.780 ns | 52.71 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 943.89 ns | 17.853 ns | 23.215 ns | 931.73 ns | 18.19 | 0.41 | 0.2327 | - | - | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 68.72 ns | 0.533 ns | 0.655 ns | 68.60 ns | 1.31 | 0.02 | 0.2295 | - | - | 480 B | | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 55.06 ns | 1.145 ns | 0.894 ns | 55.41 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Reference | List_Reference | 100 | 928.99 ns | 4.006 ns | 3.345 ns | 928.35 ns | 16.89 | 0.28 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 81.84 ns | 0.829 ns | 0.775 ns | 81.83 ns | 1.49 | 0.03 | 0.2295 | - | - | 480 B | +| Linq_List_Reference | List_Reference | 100 | 56.89 ns | 1.213 ns | 3.280 ns | 54.95 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | +| StructLinq_List_Reference | List_Reference | 100 | 929.09 ns | 3.788 ns | 3.358 ns | 929.08 ns | 15.78 | 0.64 | 0.2327 | - | - | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 84.47 ns | 1.761 ns | 4.252 ns | 82.38 ns | 1.48 | 0.13 | 0.2295 | - | - | 480 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,981.10 ns | 13.008 ns | 12.167 ns | 1,975.18 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,018.26 ns | 6.283 ns | 5.877 ns | 2,017.38 ns | 1.02 | 0.01 | 0.5951 | - | - | 1,248 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,954.13 ns | 37.510 ns | 36.840 ns | 1,969.88 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,041.94 ns | 11.426 ns | 10.688 ns | 2,039.66 ns | 1.05 | 0.02 | 0.5951 | - | - | 1,248 B | diff --git a/Benchmarks/WhereBenchmarks.md b/Benchmarks/WhereBenchmarks.md index f14c59ae3..c3616afcf 100644 --- a/Benchmarks/WhereBenchmarks.md +++ b/Benchmarks/WhereBenchmarks.md @@ -4,7 +4,7 @@ [WhereBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 468.6 ns | 1.69 ns | 1.41 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 293.9 ns | 5.43 ns | 4.24 ns | 0.63 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 459.4 ns | 3.21 ns | 2.84 ns | 0.98 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 281.2 ns | 3.56 ns | 3.33 ns | 0.60 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 292.9 ns | 3.54 ns | 3.31 ns | 0.63 | - | - | - | - | +| Linq_Array | Array | 100 | 472.6 ns | 3.25 ns | 2.71 ns | 1.00 | 0.0229 | - | - | 48 B | +| StructLinq_Array | Array | 100 | 284.5 ns | 5.02 ns | 4.70 ns | 0.60 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 456.0 ns | 2.66 ns | 2.49 ns | 0.97 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 275.9 ns | 3.54 ns | 3.32 ns | 0.58 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 293.9 ns | 3.16 ns | 2.80 ns | 0.62 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,316.1 ns | 6.43 ns | 5.70 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,192.8 ns | 6.54 ns | 5.80 ns | 0.91 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 454.0 ns | 5.33 ns | 4.98 ns | 0.34 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,360.8 ns | 11.11 ns | 9.85 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,245.3 ns | 4.40 ns | 3.90 ns | 0.92 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 317.4 ns | 3.56 ns | 3.15 ns | 0.23 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,336.9 ns | 7.84 ns | 6.95 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,188.0 ns | 4.55 ns | 4.04 ns | 0.89 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 317.1 ns | 4.24 ns | 3.96 ns | 0.24 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,351.8 ns | 5.37 ns | 4.76 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,266.1 ns | 6.69 ns | 5.93 ns | 0.94 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 262.3 ns | 2.27 ns | 2.01 ns | 0.19 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,335.1 ns | 10.22 ns | 9.06 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 520.6 ns | 6.76 ns | 6.00 ns | 0.39 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1,200.0 ns | 4.20 ns | 3.72 ns | 0.90 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,355.8 ns | 7.63 ns | 7.14 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Value | List_Value | 100 | 647.4 ns | 4.18 ns | 3.70 ns | 0.48 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1,209.3 ns | 6.51 ns | 5.43 ns | 0.89 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,636.3 ns | 16.42 ns | 14.55 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,793.0 ns | 13.00 ns | 12.16 ns | 1.03 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,643.9 ns | 27.76 ns | 25.96 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,781.5 ns | 14.49 ns | 12.85 ns | 1.03 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,367.6 ns | 6.31 ns | 5.59 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,210.8 ns | 5.67 ns | 5.03 ns | 0.89 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,204.7 ns | 7.32 ns | 6.11 ns | 0.88 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,311.4 ns | 5.54 ns | 4.91 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,241.9 ns | 8.64 ns | 7.66 ns | 0.95 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,213.4 ns | 5.06 ns | 4.74 ns | 0.93 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,353.5 ns | 5.74 ns | 5.09 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,202.1 ns | 4.64 ns | 4.11 ns | 0.89 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,288.8 ns | 3.05 ns | 2.70 ns | 0.95 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,364.9 ns | 6.06 ns | 5.06 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,263.3 ns | 7.59 ns | 6.73 ns | 0.93 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,222.9 ns | 5.99 ns | 5.60 ns | 0.90 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,360.9 ns | 5.95 ns | 5.56 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,196.2 ns | 5.49 ns | 4.87 ns | 0.88 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,224.8 ns | 5.59 ns | 5.23 ns | 0.90 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,316.6 ns | 7.06 ns | 6.61 ns | 1.00 | 0.0420 | - | - | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,274.7 ns | 7.04 ns | 6.59 ns | 0.97 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,205.3 ns | 9.70 ns | 15.38 ns | 0.91 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,502.2 ns | 28.22 ns | 23.56 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,763.8 ns | 9.88 ns | 8.76 ns | 1.06 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,492.6 ns | 31.99 ns | 28.36 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,754.4 ns | 17.22 ns | 16.11 ns | 1.06 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereCountBenchmarks.md b/Benchmarks/WhereCountBenchmarks.md index 4b66d372e..aa5c6e18b 100644 --- a/Benchmarks/WhereCountBenchmarks.md +++ b/Benchmarks/WhereCountBenchmarks.md @@ -4,7 +4,7 @@ [WhereCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereCountBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 873.0 ns | 2.95 ns | 2.47 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Array | Array | 100 | 242.0 ns | 1.88 ns | 1.76 ns | 0.28 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 196.9 ns | 0.45 ns | 0.40 ns | 0.23 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 195.8 ns | 1.04 ns | 0.97 ns | 0.22 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 199.3 ns | 0.57 ns | 0.50 ns | 0.23 | - | - | - | - | +| Linq_Array | Array | 100 | 878.8 ns | 5.36 ns | 5.01 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Array | Array | 100 | 226.8 ns | 1.00 ns | 0.93 ns | 0.26 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 173.6 ns | 0.35 ns | 0.31 ns | 0.20 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 196.9 ns | 1.29 ns | 1.21 ns | 0.22 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 199.2 ns | 0.58 ns | 0.49 ns | 0.23 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,077.2 ns | 4.67 ns | 4.36 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,041.1 ns | 3.98 ns | 3.33 ns | 0.97 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 230.1 ns | 0.81 ns | 0.72 ns | 0.21 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,102.0 ns | 4.29 ns | 3.58 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,050.1 ns | 7.50 ns | 7.02 ns | 0.95 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 215.4 ns | 1.72 ns | 1.52 ns | 0.20 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,076.8 ns | 4.44 ns | 3.94 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,053.5 ns | 5.57 ns | 4.94 ns | 0.98 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 217.9 ns | 0.48 ns | 0.40 ns | 0.20 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,064.8 ns | 4.86 ns | 4.54 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,076.9 ns | 4.56 ns | 4.27 ns | 1.01 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 218.7 ns | 1.02 ns | 0.91 ns | 0.21 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,054.6 ns | 3.68 ns | 2.87 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Value | List_Value | 100 | 390.4 ns | 3.54 ns | 3.14 ns | 0.37 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 792.8 ns | 4.47 ns | 3.96 ns | 0.75 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,074.6 ns | 6.12 ns | 5.73 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Value | List_Value | 100 | 439.7 ns | 8.58 ns | 8.02 ns | 0.41 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 823.4 ns | 12.20 ns | 10.19 ns | 0.77 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,694.0 ns | 8.28 ns | 6.47 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,498.1 ns | 7.76 ns | 6.88 ns | 1.47 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,698.2 ns | 5.19 ns | 4.34 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,514.1 ns | 6.20 ns | 5.80 ns | 1.48 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,051.9 ns | 4.94 ns | 4.38 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,042.0 ns | 3.95 ns | 3.69 ns | 0.99 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 785.9 ns | 4.76 ns | 4.22 ns | 0.75 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,066.2 ns | 6.23 ns | 5.52 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,082.7 ns | 5.31 ns | 4.97 ns | 1.02 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 773.4 ns | 2.93 ns | 2.60 ns | 0.73 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,056.8 ns | 6.61 ns | 5.86 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,060.8 ns | 2.81 ns | 2.49 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 740.2 ns | 2.78 ns | 2.47 ns | 0.70 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,098.8 ns | 6.60 ns | 5.85 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,116.5 ns | 5.08 ns | 4.24 ns | 1.02 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 737.4 ns | 4.95 ns | 4.63 ns | 0.67 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,081.7 ns | 3.00 ns | 2.66 ns | 1.00 | 0.0153 | - | - | 32 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,076.2 ns | 3.74 ns | 3.32 ns | 0.99 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 821.9 ns | 4.76 ns | 3.98 ns | 0.76 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,101.2 ns | 3.21 ns | 3.00 ns | 1.00 | 0.0153 | - | - | 32 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,032.2 ns | 4.68 ns | 3.91 ns | 0.94 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 822.6 ns | 4.43 ns | 3.70 ns | 0.75 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,697.4 ns | 4.25 ns | 3.77 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,859.4 ns | 23.48 ns | 19.61 ns | 1.68 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,706.4 ns | 7.20 ns | 6.73 ns | 1.00 | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,844.8 ns | 4.59 ns | 4.07 ns | 1.67 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereFirstBenchmarks.md b/Benchmarks/WhereFirstBenchmarks.md index 0e39d8e9a..08d713ca2 100644 --- a/Benchmarks/WhereFirstBenchmarks.md +++ b/Benchmarks/WhereFirstBenchmarks.md @@ -4,7 +4,7 @@ [WhereFirstBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereFirstBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 627.5 ns | 2.33 ns | 2.18 ns | 627.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Array | Array | 100 | 212.0 ns | 2.89 ns | 5.49 ns | 208.9 ns | 0.34 | 0.01 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 797.9 ns | 5.80 ns | 5.14 ns | 798.9 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 251.0 ns | 1.11 ns | 1.04 ns | 251.2 ns | 0.31 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 765.5 ns | 3.23 ns | 2.87 ns | 765.3 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 241.9 ns | 1.58 ns | 1.48 ns | 242.0 ns | 0.32 | 0.00 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 783.9 ns | 2.64 ns | 2.21 ns | 784.0 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Value | List_Value | 100 | 793.4 ns | 2.14 ns | 1.79 ns | 793.6 ns | 1.01 | 0.00 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,766.1 ns | 2.88 ns | 2.41 ns | 1,766.1 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,584.0 ns | 10.26 ns | 9.09 ns | 2,582.8 ns | 1.46 | 0.01 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 797.4 ns | 2.49 ns | 2.33 ns | 796.7 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 792.2 ns | 15.30 ns | 13.56 ns | 789.9 ns | 0.99 | 0.02 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 782.5 ns | 2.91 ns | 2.58 ns | 782.5 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 786.7 ns | 13.69 ns | 31.46 ns | 779.0 ns | 1.05 | 0.07 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 785.6 ns | 2.36 ns | 2.09 ns | 785.7 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 718.2 ns | 4.76 ns | 4.22 ns | 716.3 ns | 0.91 | 0.01 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,759.0 ns | 2.68 ns | 2.38 ns | 1,758.9 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,868.9 ns | 5.06 ns | 4.22 ns | 2,869.9 ns | 1.63 | 0.00 | 0.0458 | - | - | 96 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 628.3 ns | 3.00 ns | 2.50 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Array | Array | 100 | 211.0 ns | 1.17 ns | 0.97 ns | 0.34 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 767.4 ns | 3.83 ns | 3.39 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 250.9 ns | 1.17 ns | 0.98 ns | 0.33 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 784.0 ns | 4.45 ns | 3.71 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 242.3 ns | 1.46 ns | 1.30 ns | 0.31 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 781.3 ns | 6.06 ns | 5.37 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Value | List_Value | 100 | 788.1 ns | 6.22 ns | 5.19 ns | 1.01 | 0.01 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,770.2 ns | 3.54 ns | 3.14 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,585.5 ns | 5.39 ns | 4.78 ns | 1.46 | 0.00 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 767.2 ns | 2.33 ns | 1.95 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 840.7 ns | 2.43 ns | 2.15 ns | 1.10 | 0.00 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 781.4 ns | 5.11 ns | 4.53 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 751.5 ns | 10.10 ns | 8.95 ns | 0.96 | 0.01 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 807.9 ns | 2.84 ns | 2.51 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 785.2 ns | 12.49 ns | 11.68 ns | 0.97 | 0.02 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,782.2 ns | 2.93 ns | 2.60 ns | 1.00 | 0.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,878.4 ns | 4.70 ns | 3.67 ns | 1.61 | 0.00 | 0.0458 | - | - | 96 B | diff --git a/Benchmarks/WhereSelectBenchmarks.md b/Benchmarks/WhereSelectBenchmarks.md index ce98e92ce..336e32ff5 100644 --- a/Benchmarks/WhereSelectBenchmarks.md +++ b/Benchmarks/WhereSelectBenchmarks.md @@ -4,7 +4,7 @@ [WhereSelectBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,49 +14,49 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 692.8 ns | 5.17 ns | 4.84 ns | 1.00 | 0.0496 | - | - | 104 B | -| StructLinq_Array | Array | 100 | 370.8 ns | 2.77 ns | 2.59 ns | 0.54 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 358.4 ns | 1.84 ns | 1.53 ns | 0.52 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 341.0 ns | 1.43 ns | 1.34 ns | 0.49 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 336.9 ns | 1.61 ns | 1.35 ns | 0.49 | - | - | - | - | +| Linq_Array | Array | 100 | 685.4 ns | 4.23 ns | 3.95 ns | 1.00 | 0.0496 | - | - | 104 B | +| StructLinq_Array | Array | 100 | 372.2 ns | 2.24 ns | 2.10 ns | 0.54 | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 339.9 ns | 3.48 ns | 3.08 ns | 0.50 | - | - | - | - | +| Hyperlinq_Span | Array | 100 | 330.2 ns | 1.31 ns | 1.16 ns | 0.48 | - | - | - | - | +| Hyperlinq_Memory | Array | 100 | 334.4 ns | 2.05 ns | 1.92 ns | 0.49 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,486.0 ns | 6.89 ns | 5.38 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,265.8 ns | 6.77 ns | 6.00 ns | 0.85 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 342.3 ns | 1.31 ns | 1.16 ns | 0.23 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,453.1 ns | 5.39 ns | 5.05 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,315.9 ns | 3.66 ns | 3.42 ns | 0.91 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 369.9 ns | 2.59 ns | 2.42 ns | 0.25 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,485.4 ns | 2.99 ns | 2.49 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,291.8 ns | 3.76 ns | 3.14 ns | 0.87 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 339.0 ns | 0.96 ns | 0.85 ns | 0.23 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,480.0 ns | 12.49 ns | 11.07 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,273.0 ns | 2.84 ns | 2.21 ns | 0.86 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 335.4 ns | 1.45 ns | 1.13 ns | 0.23 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,519.6 ns | 24.52 ns | 21.73 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Value | List_Value | 100 | 696.3 ns | 3.43 ns | 3.04 ns | 0.46 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1,317.8 ns | 4.96 ns | 4.39 ns | 0.87 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,486.9 ns | 13.11 ns | 11.62 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Value | List_Value | 100 | 645.3 ns | 3.29 ns | 2.92 ns | 0.43 | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 1,294.9 ns | 7.31 ns | 6.84 ns | 0.87 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,629.5 ns | 23.72 ns | 21.03 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,201.4 ns | 6.04 ns | 5.36 ns | 1.12 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,577.4 ns | 28.26 ns | 23.60 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,184.2 ns | 16.49 ns | 14.62 ns | 1.13 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,499.3 ns | 11.27 ns | 10.54 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,298.5 ns | 8.18 ns | 7.65 ns | 0.87 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,312.7 ns | 4.97 ns | 4.41 ns | 0.88 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,454.4 ns | 5.84 ns | 5.47 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,282.4 ns | 2.51 ns | 2.22 ns | 0.88 | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,318.3 ns | 4.86 ns | 3.79 ns | 0.91 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,504.2 ns | 7.78 ns | 6.50 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,292.6 ns | 5.53 ns | 4.90 ns | 0.86 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,243.6 ns | 8.12 ns | 7.20 ns | 0.83 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,492.2 ns | 5.79 ns | 4.84 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,309.7 ns | 5.51 ns | 4.89 ns | 0.88 | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,289.3 ns | 6.39 ns | 5.67 ns | 0.86 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,506.1 ns | 3.78 ns | 3.35 ns | 1.00 | 0.0725 | - | - | 152 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,289.9 ns | 4.44 ns | 3.71 ns | 0.86 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,249.5 ns | 6.35 ns | 5.63 ns | 0.83 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,474.0 ns | 7.21 ns | 6.40 ns | 1.00 | 0.0725 | - | - | 152 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,281.8 ns | 9.80 ns | 8.69 ns | 0.87 | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,285.7 ns | 8.78 ns | 8.21 ns | 0.87 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,572.8 ns | 8.97 ns | 7.95 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,252.3 ns | 17.50 ns | 15.52 ns | 1.15 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,546.7 ns | 24.51 ns | 21.73 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,313.6 ns | 15.57 ns | 13.80 ns | 1.17 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereSelectCountBenchmarks.md b/Benchmarks/WhereSelectCountBenchmarks.md index d6dae2c74..60aa63122 100644 --- a/Benchmarks/WhereSelectCountBenchmarks.md +++ b/Benchmarks/WhereSelectCountBenchmarks.md @@ -4,7 +4,7 @@ [WhereSelectCountBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSelectCountBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,40 +14,40 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 351.2 ns | 4.93 ns | 4.11 ns | 1.00 | 0.0496 | - | - | 104 B | -| Hyperlinq_Array | Array | 100 | 205.3 ns | 0.54 ns | 0.48 ns | 0.58 | - | - | - | - | +| Linq_Array | Array | 100 | 341.1 ns | 1.86 ns | 1.64 ns | 1.00 | 0.0496 | - | - | 104 B | +| Hyperlinq_Array | Array | 100 | 182.3 ns | 0.69 ns | 0.61 ns | 0.53 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,201.9 ns | 5.46 ns | 4.84 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 233.7 ns | 0.83 ns | 0.74 ns | 0.19 | - | - | - | - | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,186.7 ns | 7.67 ns | 6.80 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 225.2 ns | 1.24 ns | 1.10 ns | 0.19 | - | - | - | - | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,163.1 ns | 6.69 ns | 6.26 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 226.7 ns | 1.15 ns | 1.02 ns | 0.19 | - | - | - | - | +| Linq_Collection_Value | Collection_Value | 100 | 1,204.4 ns | 4.62 ns | 4.32 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 232.3 ns | 1.38 ns | 1.22 ns | 0.19 | - | - | - | - | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,190.5 ns | 3.39 ns | 3.17 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Value | List_Value | 100 | 790.1 ns | 5.03 ns | 4.46 ns | 0.66 | 0.0153 | - | - | 32 B | +| Linq_List_Value | List_Value | 100 | 1,189.7 ns | 6.41 ns | 5.68 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Value | List_Value | 100 | 781.3 ns | 4.77 ns | 3.98 ns | 0.66 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,784.1 ns | 15.70 ns | 13.92 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,498.6 ns | 5.24 ns | 4.90 ns | 0.52 | - | - | - | - | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,777.6 ns | 23.18 ns | 20.55 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,521.2 ns | 7.22 ns | 6.40 ns | 0.53 | - | - | - | - | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,238.5 ns | 4.32 ns | 3.83 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 743.7 ns | 3.76 ns | 3.52 ns | 0.60 | 0.0153 | - | - | 32 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,185.0 ns | 6.96 ns | 6.17 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 749.3 ns | 4.88 ns | 4.33 ns | 0.63 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,219.2 ns | 5.79 ns | 5.42 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 766.8 ns | 4.34 ns | 3.85 ns | 0.63 | 0.0153 | - | - | 32 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,193.0 ns | 13.44 ns | 11.91 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 749.3 ns | 2.33 ns | 2.07 ns | 0.63 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,207.0 ns | 3.77 ns | 3.53 ns | 1.00 | 0.0725 | - | - | 152 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 743.7 ns | 2.69 ns | 2.51 ns | 0.62 | 0.0153 | - | - | 32 B | +| Linq_List_Reference | List_Reference | 100 | 1,201.2 ns | 15.02 ns | 13.31 ns | 1.00 | 0.0725 | - | - | 152 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 808.6 ns | 3.81 ns | 3.38 ns | 0.67 | 0.0153 | - | - | 32 B | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,810.9 ns | 21.97 ns | 19.47 ns | 1.00 | 0.0763 | - | - | 168 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,827.4 ns | 7.57 ns | 7.08 ns | 0.59 | 0.0153 | - | - | 32 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,771.1 ns | 19.32 ns | 18.07 ns | 1.00 | 0.0763 | - | - | 168 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,855.6 ns | 12.53 ns | 11.72 ns | 0.60 | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/WhereSingleBenchmarks.md b/Benchmarks/WhereSingleBenchmarks.md index 9fab9546e..4053fb11f 100644 --- a/Benchmarks/WhereSingleBenchmarks.md +++ b/Benchmarks/WhereSingleBenchmarks.md @@ -4,7 +4,7 @@ [WhereSingleBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereSingleBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,38 +14,38 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------- |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 581.4 ns | 3.08 ns | 2.73 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Array | Array | 100 | 206.9 ns | 0.43 ns | 0.36 ns | 0.36 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 772.8 ns | 3.58 ns | 2.99 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 272.4 ns | 3.12 ns | 2.92 ns | 0.35 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 768.0 ns | 4.02 ns | 3.56 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 266.1 ns | 4.52 ns | 4.01 ns | 0.35 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 782.0 ns | 4.00 ns | 3.55 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Value | List_Value | 100 | 774.0 ns | 2.94 ns | 2.61 ns | 0.99 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,741.8 ns | 5.26 ns | 4.67 ns | 1.00 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 779.5 ns | 2.88 ns | 2.69 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 763.2 ns | 3.25 ns | 2.88 ns | 0.98 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 795.6 ns | 3.08 ns | 2.73 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 749.0 ns | 2.92 ns | 2.59 ns | 0.94 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 807.1 ns | 5.97 ns | 5.29 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 824.7 ns | 3.38 ns | 3.00 ns | 1.02 | 0.0458 | - | - | 96 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,714.4 ns | 2.55 ns | 1.99 ns | 1.00 | 0.0458 | - | - | 96 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------- |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 607.0 ns | 9.12 ns | 8.09 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Array | Array | 100 | 208.4 ns | 0.67 ns | 0.52 ns | 0.34 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 761.0 ns | 4.33 ns | 3.84 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 267.5 ns | 1.15 ns | 1.02 ns | 0.35 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 778.2 ns | 2.81 ns | 2.49 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 262.0 ns | 1.08 ns | 1.01 ns | 0.34 | 0.0305 | - | - | 64 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 762.9 ns | 1.55 ns | 1.30 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Value | List_Value | 100 | 798.4 ns | 3.46 ns | 2.89 ns | 1.05 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,746.6 ns | 4.35 ns | 4.06 ns | 1.00 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 725.9 ns | 7.94 ns | 7.04 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 751.0 ns | 3.70 ns | 3.28 ns | 1.03 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 724.8 ns | 9.52 ns | 8.91 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 758.4 ns | 2.32 ns | 1.94 ns | 1.04 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 716.9 ns | 3.26 ns | 2.89 ns | 1.00 | 0.0458 | - | - | 96 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 828.8 ns | 4.47 ns | 3.97 ns | 1.16 | 0.0458 | - | - | 96 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,726.4 ns | 13.14 ns | 12.29 ns | 1.00 | 0.0458 | - | - | 96 B | diff --git a/Benchmarks/WhereToArrayBenchmarks.md b/Benchmarks/WhereToArrayBenchmarks.md index af1af5720..62dc3c37a 100644 --- a/Benchmarks/WhereToArrayBenchmarks.md +++ b/Benchmarks/WhereToArrayBenchmarks.md @@ -4,7 +4,7 @@ [WhereToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 428.2 ns | 2.40 ns | 1.87 ns | 428.3 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | -| StructLinq_Array | Array | 100 | 407.5 ns | 2.14 ns | 1.79 ns | 407.6 ns | 0.95 | 0.01 | 0.1144 | - | - | 240 B | -| Hyperlinq_Array | Array | 100 | 479.2 ns | 9.36 ns | 12.50 ns | 486.3 ns | 1.10 | 0.03 | 0.1144 | - | - | 240 B | +| Linq_Array | Array | 100 | 424.1 ns | 8.54 ns | 16.45 ns | 415.1 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | +| StructLinq_Array | Array | 100 | 410.3 ns | 7.67 ns | 13.23 ns | 403.1 ns | 0.97 | 0.02 | 0.1144 | - | - | 240 B | +| Hyperlinq_Array | Array | 100 | 513.2 ns | 5.71 ns | 5.06 ns | 512.0 ns | 1.16 | 0.05 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,263.4 ns | 5.52 ns | 5.16 ns | 1,262.6 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,214.8 ns | 8.79 ns | 7.34 ns | 1,215.2 ns | 0.96 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 521.3 ns | 3.21 ns | 3.00 ns | 522.0 ns | 0.41 | 0.00 | 0.1144 | - | - | 240 B | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,389.3 ns | 8.52 ns | 7.55 ns | 1,387.9 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,179.6 ns | 6.07 ns | 5.68 ns | 1,179.8 ns | 0.85 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 545.9 ns | 5.84 ns | 5.47 ns | 545.0 ns | 0.39 | 0.00 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,198.9 ns | 6.14 ns | 5.13 ns | 1,197.5 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,219.9 ns | 7.23 ns | 6.77 ns | 1,219.3 ns | 1.02 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 511.7 ns | 3.86 ns | 3.22 ns | 511.4 ns | 0.43 | 0.00 | 0.1144 | - | - | 240 B | +| Linq_Collection_Value | Collection_Value | 100 | 1,300.4 ns | 8.52 ns | 7.97 ns | 1,300.4 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,185.6 ns | 5.33 ns | 4.72 ns | 1,186.7 ns | 0.91 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 522.6 ns | 2.02 ns | 1.69 ns | 522.5 ns | 0.40 | 0.00 | 0.1144 | - | - | 240 B | | | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,204.2 ns | 11.07 ns | 9.81 ns | 1,201.8 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Value | List_Value | 100 | 784.4 ns | 4.47 ns | 3.73 ns | 782.6 ns | 0.65 | 0.01 | 0.1144 | - | - | 240 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,378.5 ns | 7.58 ns | 7.09 ns | 1,377.8 ns | 1.14 | 0.01 | 0.1297 | - | - | 272 B | +| Linq_List_Value | List_Value | 100 | 1,355.6 ns | 25.15 ns | 27.96 ns | 1,367.7 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Value | List_Value | 100 | 812.9 ns | 3.54 ns | 3.14 ns | 813.1 ns | 0.60 | 0.01 | 0.1144 | - | - | 240 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,370.0 ns | 8.07 ns | 7.15 ns | 1,366.5 ns | 1.02 | 0.02 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,166.4 ns | 63.82 ns | 56.57 ns | 5,169.3 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,864.9 ns | 6.51 ns | 5.77 ns | 2,864.0 ns | 0.55 | 0.01 | 0.3433 | - | - | 720 B | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,086.6 ns | 49.27 ns | 43.68 ns | 5,070.8 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,883.8 ns | 10.40 ns | 9.22 ns | 2,883.1 ns | 0.57 | 0.01 | 0.3357 | - | - | 720 B | | | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,272.1 ns | 23.51 ns | 20.84 ns | 1,276.1 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,213.1 ns | 3.32 ns | 2.94 ns | 1,213.4 ns | 0.95 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,276.6 ns | 5.85 ns | 5.19 ns | 1,275.2 ns | 1.00 | 0.02 | 0.1297 | - | - | 272 B | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,282.7 ns | 4.93 ns | 4.37 ns | 1,282.7 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,192.7 ns | 8.80 ns | 7.80 ns | 1,191.1 ns | 0.93 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,327.2 ns | 20.85 ns | 19.50 ns | 1,329.5 ns | 1.03 | 0.02 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,209.8 ns | 7.05 ns | 6.25 ns | 1,208.3 ns | 1.00 | 0.00 | 0.3681 | - | - | 776 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,256.2 ns | 13.17 ns | 12.32 ns | 1,259.2 ns | 1.04 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,253.4 ns | 4.26 ns | 3.55 ns | 1,253.6 ns | 1.04 | 0.01 | 0.1297 | - | - | 272 B | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,355.8 ns | 7.95 ns | 7.43 ns | 1,354.1 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,190.5 ns | 9.14 ns | 7.13 ns | 1,188.1 ns | 0.88 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,324.2 ns | 22.65 ns | 21.19 ns | 1,331.9 ns | 0.98 | 0.02 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,250.0 ns | 24.34 ns | 25.00 ns | 1,259.9 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,227.7 ns | 23.37 ns | 22.95 ns | 1,215.7 ns | 0.98 | 0.04 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,378.1 ns | 15.40 ns | 14.41 ns | 1,380.6 ns | 1.11 | 0.02 | 0.1297 | - | - | 272 B | +| Linq_List_Reference | List_Reference | 100 | 1,283.1 ns | 7.13 ns | 6.32 ns | 1,281.3 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,226.3 ns | 10.26 ns | 9.60 ns | 1,225.4 ns | 0.96 | 0.01 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,343.9 ns | 7.08 ns | 6.28 ns | 1,344.4 ns | 1.05 | 0.01 | 0.1297 | - | - | 272 B | | | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,982.8 ns | 81.41 ns | 76.15 ns | 4,932.3 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,509.2 ns | 9.72 ns | 7.59 ns | 3,509.3 ns | 0.70 | 0.01 | 0.3548 | - | - | 752 B | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,045.7 ns | 22.45 ns | 17.53 ns | 5,052.5 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,620.7 ns | 12.19 ns | 11.40 ns | 3,622.7 ns | 0.72 | 0.00 | 0.3548 | - | - | 752 B | diff --git a/Benchmarks/WhereToListBenchmarks.md b/Benchmarks/WhereToListBenchmarks.md index 7d7895144..dbb732e7e 100644 --- a/Benchmarks/WhereToListBenchmarks.md +++ b/Benchmarks/WhereToListBenchmarks.md @@ -4,7 +4,7 @@ [WhereToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.4.21253.7 +- Linq: 6.0.0-preview.5.21301.5 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) @@ -14,47 +14,47 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1023 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.4.21255.9 - [Host] : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT - Job-FXRHUT : .NET 6.0.0 (6.0.21.25307), X64 RyuJIT +.NET SDK=6.0.100-preview.5.21302.13 + [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 373.3 ns | 2.27 ns | 2.01 ns | 372.5 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | -| StructLinq_Array | Array | 100 | 433.8 ns | 8.41 ns | 10.94 ns | 437.8 ns | 1.15 | 0.03 | 0.1297 | - | - | 272 B | -| Hyperlinq_Array | Array | 100 | 505.5 ns | 4.81 ns | 4.26 ns | 505.0 ns | 1.35 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,214.5 ns | 24.06 ns | 32.12 ns | 1,229.1 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,215.9 ns | 4.24 ns | 3.76 ns | 1,217.0 ns | 1.02 | 0.03 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 595.6 ns | 11.89 ns | 15.03 ns | 601.2 ns | 0.49 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,134.4 ns | 17.77 ns | 16.62 ns | 1,129.1 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,204.6 ns | 5.24 ns | 4.64 ns | 1,204.5 ns | 1.06 | 0.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 547.6 ns | 10.83 ns | 14.83 ns | 539.4 ns | 0.49 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,185.0 ns | 5.28 ns | 4.94 ns | 1,186.8 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Value | List_Value | 100 | 833.5 ns | 12.80 ns | 11.35 ns | 838.7 ns | 0.70 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,341.0 ns | 4.99 ns | 4.16 ns | 1,340.4 ns | 1.13 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,001.7 ns | 12.64 ns | 11.83 ns | 4,997.4 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,917.6 ns | 8.45 ns | 7.90 ns | 2,916.6 ns | 0.58 | 0.00 | 0.3586 | - | - | 752 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,195.3 ns | 5.12 ns | 4.54 ns | 1,194.5 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,209.6 ns | 4.29 ns | 3.81 ns | 1,208.7 ns | 1.01 | 0.00 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,340.5 ns | 15.32 ns | 14.33 ns | 1,343.2 ns | 1.12 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,130.9 ns | 6.35 ns | 5.63 ns | 1,130.3 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,282.0 ns | 15.81 ns | 14.02 ns | 1,283.2 ns | 1.13 | 0.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,328.9 ns | 6.41 ns | 5.35 ns | 1,328.5 ns | 1.18 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,136.4 ns | 5.65 ns | 5.28 ns | 1,135.3 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,239.8 ns | 23.55 ns | 22.03 ns | 1,246.9 ns | 1.09 | 0.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,323.3 ns | 3.51 ns | 3.11 ns | 1,323.2 ns | 1.16 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,943.3 ns | 23.97 ns | 21.25 ns | 4,938.7 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,667.0 ns | 34.22 ns | 30.34 ns | 3,672.5 ns | 0.74 | 0.01 | 0.3738 | - | - | 784 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 373.4 ns | 2.74 ns | 2.29 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | +| StructLinq_Array | Array | 100 | 403.2 ns | 8.08 ns | 10.50 ns | 1.06 | 0.03 | 0.1297 | - | - | 272 B | +| Hyperlinq_Array | Array | 100 | 523.5 ns | 5.29 ns | 4.94 ns | 1.40 | 0.02 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,146.8 ns | 8.29 ns | 7.34 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,187.8 ns | 5.78 ns | 5.41 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 557.3 ns | 3.76 ns | 3.14 ns | 0.49 | 0.00 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,141.7 ns | 5.63 ns | 4.99 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,189.0 ns | 6.01 ns | 5.32 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 529.1 ns | 3.03 ns | 2.53 ns | 0.46 | 0.00 | 0.1297 | - | - | 272 B | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 1,203.5 ns | 23.17 ns | 29.30 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Value | List_Value | 100 | 852.3 ns | 13.88 ns | 12.30 ns | 0.72 | 0.02 | 0.1297 | - | - | 272 B | +| Hyperlinq_List_Value | List_Value | 100 | 1,354.1 ns | 18.55 ns | 17.35 ns | 1.13 | 0.04 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,047.5 ns | 79.12 ns | 74.01 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,963.9 ns | 57.98 ns | 56.94 ns | 0.59 | 0.01 | 0.3586 | - | - | 752 B | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,140.2 ns | 6.42 ns | 6.01 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,199.0 ns | 5.03 ns | 4.46 ns | 1.05 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,333.4 ns | 7.53 ns | 6.68 ns | 1.17 | 0.01 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 1,199.3 ns | 23.37 ns | 22.95 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,242.0 ns | 13.75 ns | 12.19 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,320.5 ns | 5.12 ns | 4.28 ns | 1.10 | 0.02 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 1,157.6 ns | 20.87 ns | 28.57 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,210.0 ns | 23.79 ns | 23.37 ns | 1.04 | 0.02 | 0.1450 | - | - | 304 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 1,408.2 ns | 7.30 ns | 6.48 ns | 1.20 | 0.03 | 0.1450 | - | - | 304 B | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,964.4 ns | 21.77 ns | 19.30 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,551.4 ns | 10.45 ns | 9.26 ns | 0.72 | 0.00 | 0.3738 | - | - | 784 B | From 193789cd8ac7e609912aa4fef8010ff454925769 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sun, 20 Jun 2021 12:42:40 +0100 Subject: [PATCH 38/61] Array iteration benchmarks --- Benchmarks/ArrayIterationBenchmarks.md | 25 +-- .../Benchmarks/ArrayIterationBenchmarks.cs | 146 +++++++----------- NetFabric.Hyperlinq.Benchmarks/Program.cs | 4 +- 3 files changed, 71 insertions(+), 104 deletions(-) diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 5b123b3c6..58caf7efe 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -14,22 +14,23 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) +BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1081 (21H1/May2021Update) Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.5.21302.13 [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-VMNIKZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|----------------------------- |-------- |-----------:|---------:|---------:|-----------:|------:|--------:|------:|------:|------:|----------:| -| Foreach | 1000000 | 421.7 μs | 2.74 μs | 2.43 μs | 421.4 μs | 1.00 | 0.00 | - | - | - | - | -| For | 1000000 | 453.3 μs | 13.53 μs | 39.90 μs | 424.0 μs | 1.08 | 0.08 | - | - | - | - | -| For_Unsafe | 1000000 | 499.3 μs | 2.06 μs | 1.72 μs | 499.4 μs | 1.19 | 0.01 | - | - | - | - | -| Span | 1000000 | 423.4 μs | 2.07 μs | 1.94 μs | 423.7 μs | 1.00 | 0.01 | - | - | - | - | -| ArraySegment_Foreach | 1000000 | 2,826.5 μs | 9.76 μs | 9.13 μs | 2,824.3 μs | 6.70 | 0.05 | - | - | - | 1 B | -| ArraySegment_For | 1000000 | 817.4 μs | 3.78 μs | 6.71 μs | 815.1 μs | 1.94 | 0.02 | - | - | - | - | -| ArraySegment_Expanded_For | 1000000 | 1,403.9 μs | 27.63 μs | 40.50 μs | 1,425.7 μs | 3.27 | 0.10 | - | - | - | 1 B | -| ArraySegment_Wrapper_Foreach | 1000000 | 1,468.3 μs | 4.87 μs | 4.32 μs | 1,466.8 μs | 3.48 | 0.02 | - | - | - | - | +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|--------------------- |-------- |-----------:|--------:|--------:|-------------:|--------:|------:|------:|------:|----------:| +| Foreach | 1000000 | 410.6 μs | 2.11 μs | 1.65 μs | baseline | | - | - | - | - | +| For | 1000000 | 413.4 μs | 1.94 μs | 1.81 μs | 1.01x slower | 0.01x | - | - | - | - | +| For_Unsafe | 1000000 | 410.5 μs | 1.62 μs | 1.51 μs | 1.00x faster | 0.00x | - | - | - | - | +| ForAdamczewskiUnsafe | 1000000 | 350.6 μs | 1.82 μs | 1.52 μs | 1.17x faster | 0.01x | - | - | - | - | +| Span | 1000000 | 408.3 μs | 1.73 μs | 1.53 μs | 1.01x faster | 0.01x | - | - | - | - | +| ArraySegment_Foreach | 1000000 | 2,784.3 μs | 7.78 μs | 6.50 μs | 6.78x slower | 0.03x | - | - | - | 1 B | +| ArraySegment_For | 1000000 | 800.8 μs | 3.75 μs | 3.13 μs | 1.95x slower | 0.01x | - | - | - | - | +| ArraySegment_AsSpan | 1000000 | 409.3 μs | 1.34 μs | 1.25 μs | 1.00x faster | 0.00x | - | - | - | - | +| ArraySegment_AsArray | 1000000 | 1,054.0 μs | 2.24 μs | 2.09 μs | 2.57x slower | 0.01x | - | - | - | - | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs index d5f674ea1..e6761acd8 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs @@ -63,51 +63,51 @@ public unsafe int For_Unsafe() } // [Benchmark] - // public int ForAdamczewski() - // { - // var source = array!; - // var len = source.Length; - // var sum1 = 0; - // var sum2 = 0; - // for (var index = 0; index < len; index += 2) - // { - // long i1 = index + 0; - // long i2 = index + 1; - // var c = source[i1]; - // var d = source[i2]; - // - // sum1 += c; - // sum2 += d; - // } - // return sum1 + sum2; - // } - // - // [Benchmark] - // public unsafe int ForAdamczewskiUnsafe() - // { - // fixed (int* source = array) - // { - // var len = array!.Length; - // var sum1 = 0; - // var sum2 = 0; - // for (var index = 0; index < len; index += 2) - // { - // long i1 = index + 0; - // long i2 = index + 1; - // var c = source[i1]; - // var d = source[i2]; - // - // sum1 += c; - // sum2 += d; - // } - // return sum1 + sum2; - // } - // } + public int ForAdamczewski() + { + var source = array!; + var len = source.Length; + var sum1 = 0; + var sum2 = 0; + for (var index = 0; index < len; index += 2) + { + long i1 = index + 0; + long i2 = index + 1; + var c = source[i1]; + var d = source[i2]; + + sum1 += c; + sum2 += d; + } + return sum1 + sum2; + } + + [Benchmark] + public unsafe int ForAdamczewskiUnsafe() + { + fixed (int* source = array) + { + var len = array!.Length; + var sum1 = 0; + var sum2 = 0; + for (var index = 0; index < len; index += 2) + { + long i1 = index + 0; + long i2 = index + 1; + var c = source[i1]; + var d = source[i2]; + + sum1 += c; + sum2 += d; + } + return sum1 + sum2; + } + } [Benchmark] public int Span() { - var source = array!.AsSpan(); + var source = array.AsSpan(); var sum = 0; foreach (var item in source) sum += item; @@ -129,73 +129,37 @@ public int ArraySegment_For() { var source = segment; var sum = 0; - for (var index = 0; index < source!.Count; index++) + // ReSharper disable once LoopCanBeConvertedToQuery + // ReSharper disable once ForCanBeConvertedToForeach + for (var index = 0; index < source.Count; index++) { - var item = source![index]; + var item = source[index]; sum += item; } return sum; } [Benchmark] - public int ArraySegment_Expanded_For() + public int ArraySegment_AsSpan() { - var source = segment.Array!; - var start = segment.Offset; - var end = start + segment.Count; var sum = 0; - for (var index = start; index < end && index < source.Length; index++) - { - var item = source[index]; + // ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator + foreach (var item in segment.AsSpan()) sum += item; - } return sum; } - + [Benchmark] - public int ArraySegment_Wrapper_Foreach() + public int ArraySegment_AsArray() { - var source = new ArraySegmentWrapper(segment); + var source = segment.Array!; + var start = segment.Offset; + var end = start + segment.Count; var sum = 0; - foreach (var item in source) - sum += item; + for (var index = start; index < end && index < source.Length; index++) + sum += source[index]; return sum; } - readonly struct ArraySegmentWrapper - { - readonly ArraySegment source; - - public ArraySegmentWrapper(in ArraySegment source) - => this.source = source; - - public Enumerator GetEnumerator() - => new(source.Array.AsSpan().Slice(source.Offset, source.Count)); - - public ref struct Enumerator - { - readonly ReadOnlySpan source; - readonly int end; - int index; - - public Enumerator(ReadOnlySpan source) - { - this.source = source; - index = -1; - end = index + source.Length; - } - - public readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++index <= end; - } - } - } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Program.cs b/NetFabric.Hyperlinq.Benchmarks/Program.cs index a5e5ca55e..c65e9146c 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Program.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Program.cs @@ -1,4 +1,5 @@ -using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Columns; +using BenchmarkDotNet.Configs; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Environments; using System; @@ -20,6 +21,7 @@ class Program static void Main(string[] args) { var config = DefaultConfig.Instance + .WithSummaryStyle(SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend)) .AddJob(Job.Default.WithRuntime(CoreRuntime.Core60)) .AddDiagnoser(MemoryDiagnoser.Default); From 9bb2afaeda8692a6d64671a210943e096cd364e1 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sun, 20 Jun 2021 14:10:02 +0100 Subject: [PATCH 39/61] Use Length - 1 --- Benchmarks/ArrayIterationBenchmarks.md | 21 ++++++++++--------- .../Benchmarks/ArrayIterationBenchmarks.cs | 20 ++++++++++-------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 58caf7efe..dc8d605a8 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -18,19 +18,20 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1081 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.5.21302.13 [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-VMNIKZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-XVAVUK : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |--------------------- |-------- |-----------:|--------:|--------:|-------------:|--------:|------:|------:|------:|----------:| -| Foreach | 1000000 | 410.6 μs | 2.11 μs | 1.65 μs | baseline | | - | - | - | - | -| For | 1000000 | 413.4 μs | 1.94 μs | 1.81 μs | 1.01x slower | 0.01x | - | - | - | - | -| For_Unsafe | 1000000 | 410.5 μs | 1.62 μs | 1.51 μs | 1.00x faster | 0.00x | - | - | - | - | -| ForAdamczewskiUnsafe | 1000000 | 350.6 μs | 1.82 μs | 1.52 μs | 1.17x faster | 0.01x | - | - | - | - | -| Span | 1000000 | 408.3 μs | 1.73 μs | 1.53 μs | 1.01x faster | 0.01x | - | - | - | - | -| ArraySegment_Foreach | 1000000 | 2,784.3 μs | 7.78 μs | 6.50 μs | 6.78x slower | 0.03x | - | - | - | 1 B | -| ArraySegment_For | 1000000 | 800.8 μs | 3.75 μs | 3.13 μs | 1.95x slower | 0.01x | - | - | - | - | -| ArraySegment_AsSpan | 1000000 | 409.3 μs | 1.34 μs | 1.25 μs | 1.00x faster | 0.00x | - | - | - | - | -| ArraySegment_AsArray | 1000000 | 1,054.0 μs | 2.24 μs | 2.09 μs | 2.57x slower | 0.01x | - | - | - | - | +| Foreach | 1000000 | 412.6 μs | 2.14 μs | 1.67 μs | baseline | | - | - | - | - | +| For | 1000000 | 429.4 μs | 2.29 μs | 2.03 μs | 1.04x slower | 0.01x | - | - | - | - | +| For_Unsafe | 1000000 | 413.0 μs | 3.60 μs | 2.81 μs | 1.00x slower | 0.01x | - | - | - | - | +| ForAdamczewski | 1000000 | 408.5 μs | 2.42 μs | 2.14 μs | 1.01x faster | 0.01x | - | - | - | - | +| ForAdamczewskiUnsafe | 1000000 | 352.8 μs | 1.71 μs | 1.52 μs | 1.17x faster | 0.01x | - | - | - | - | +| Span | 1000000 | 413.7 μs | 3.02 μs | 2.82 μs | 1.00x slower | 0.01x | - | - | - | - | +| ArraySegment_Foreach | 1000000 | 2,796.4 μs | 7.48 μs | 7.00 μs | 6.78x slower | 0.04x | - | - | - | 1 B | +| ArraySegment_For | 1000000 | 805.3 μs | 4.55 μs | 3.55 μs | 1.95x slower | 0.01x | - | - | - | - | +| ArraySegment_AsSpan | 1000000 | 412.9 μs | 2.45 μs | 2.29 μs | 1.00x slower | 0.01x | - | - | - | - | +| ArraySegment_AsArray | 1000000 | 802.6 μs | 4.70 μs | 4.17 μs | 1.94x slower | 0.01x | - | - | - | - | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs index e6761acd8..3b88cccf2 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs @@ -35,10 +35,11 @@ public int Foreach() public int For() { var source = array!; + var len = array!.Length - 1; var sum = 0; // ReSharper disable once ForCanBeConvertedToForeach // ReSharper disable once LoopCanBeConvertedToQuery - for (var index = 0; index < source.Length; index++) + for (var index = 0; index <= len; index++) { var item = source[index]; sum += item; @@ -49,11 +50,11 @@ public int For() [Benchmark] public unsafe int For_Unsafe() { - var end = array!.Length; + var len = array!.Length - 1; var sum = 0; fixed (int* source = array) { - for (var index = 0; index < end; index++) + for (var index = 0; index < len; index++) { var item = source[index]; sum += item; @@ -62,14 +63,14 @@ public unsafe int For_Unsafe() return sum; } - // [Benchmark] + [Benchmark] public int ForAdamczewski() { var source = array!; - var len = source.Length; + var len = source.Length - 1; var sum1 = 0; var sum2 = 0; - for (var index = 0; index < len; index += 2) + for (var index = 0; index <= len; index += 2) { long i1 = index + 0; long i2 = index + 1; @@ -87,10 +88,10 @@ public unsafe int ForAdamczewskiUnsafe() { fixed (int* source = array) { - var len = array!.Length; + var len = array!.Length - 1; var sum1 = 0; var sum2 = 0; - for (var index = 0; index < len; index += 2) + for (var index = 0; index <= len; index += 2) { long i1 = index + 0; long i2 = index + 1; @@ -153,10 +154,11 @@ public int ArraySegment_AsSpan() public int ArraySegment_AsArray() { var source = segment.Array!; + var len = array!.Length - 1; var start = segment.Offset; var end = start + segment.Count; var sum = 0; - for (var index = start; index < end && index < source.Length; index++) + for (var index = start; index < end && index <= len; index++) sum += source[index]; return sum; } From 6a7e3e3d90ea5704968e0db6992463905625d505 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sun, 20 Jun 2021 14:20:49 +0100 Subject: [PATCH 40/61] Use Length - 1 --- Benchmarks/ArrayIterationBenchmarks.md | 26 +++++++++---------- .../Benchmarks/ArrayIterationBenchmarks.cs | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index dc8d605a8..96204149f 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -18,20 +18,20 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1081 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.5.21302.13 [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-XVAVUK : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-IRYCMS : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|--------------------- |-------- |-----------:|--------:|--------:|-------------:|--------:|------:|------:|------:|----------:| -| Foreach | 1000000 | 412.6 μs | 2.14 μs | 1.67 μs | baseline | | - | - | - | - | -| For | 1000000 | 429.4 μs | 2.29 μs | 2.03 μs | 1.04x slower | 0.01x | - | - | - | - | -| For_Unsafe | 1000000 | 413.0 μs | 3.60 μs | 2.81 μs | 1.00x slower | 0.01x | - | - | - | - | -| ForAdamczewski | 1000000 | 408.5 μs | 2.42 μs | 2.14 μs | 1.01x faster | 0.01x | - | - | - | - | -| ForAdamczewskiUnsafe | 1000000 | 352.8 μs | 1.71 μs | 1.52 μs | 1.17x faster | 0.01x | - | - | - | - | -| Span | 1000000 | 413.7 μs | 3.02 μs | 2.82 μs | 1.00x slower | 0.01x | - | - | - | - | -| ArraySegment_Foreach | 1000000 | 2,796.4 μs | 7.48 μs | 7.00 μs | 6.78x slower | 0.04x | - | - | - | 1 B | -| ArraySegment_For | 1000000 | 805.3 μs | 4.55 μs | 3.55 μs | 1.95x slower | 0.01x | - | - | - | - | -| ArraySegment_AsSpan | 1000000 | 412.9 μs | 2.45 μs | 2.29 μs | 1.00x slower | 0.01x | - | - | - | - | -| ArraySegment_AsArray | 1000000 | 802.6 μs | 4.70 μs | 4.17 μs | 1.94x slower | 0.01x | - | - | - | - | +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|--------------------- |-------- |-----------:|---------:|--------:|-------------:|--------:|------:|------:|------:|----------:| +| Foreach | 1000000 | 424.2 μs | 5.91 μs | 5.53 μs | baseline | | - | - | - | - | +| For | 1000000 | 428.7 μs | 2.69 μs | 2.52 μs | 1.01x slower | 0.01x | - | - | - | - | +| For_Unsafe | 1000000 | 412.9 μs | 3.31 μs | 2.76 μs | 1.03x faster | 0.01x | - | - | - | - | +| ForAdamczewski | 1000000 | 404.1 μs | 2.42 μs | 2.26 μs | 1.05x faster | 0.02x | - | - | - | - | +| ForAdamczewskiUnsafe | 1000000 | 355.1 μs | 3.48 μs | 3.25 μs | 1.19x faster | 0.02x | - | - | - | - | +| Span | 1000000 | 411.8 μs | 2.92 μs | 2.28 μs | 1.03x faster | 0.01x | - | - | - | - | +| ArraySegment_Foreach | 1000000 | 2,800.7 μs | 10.24 μs | 9.08 μs | 6.60x slower | 0.09x | - | - | - | 1 B | +| ArraySegment_For | 1000000 | 805.2 μs | 4.48 μs | 4.19 μs | 1.90x slower | 0.02x | - | - | - | - | +| ArraySegment_AsSpan | 1000000 | 412.4 μs | 2.08 μs | 1.74 μs | 1.03x faster | 0.01x | - | - | - | - | +| ArraySegment_AsArray | 1000000 | 798.7 μs | 4.39 μs | 3.67 μs | 1.88x slower | 0.03x | - | - | - | - | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs index 3b88cccf2..09798da41 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs @@ -54,7 +54,7 @@ public unsafe int For_Unsafe() var sum = 0; fixed (int* source = array) { - for (var index = 0; index < len; index++) + for (var index = 0; index <= len; index++) { var item = source[index]; sum += item; From e78d5410a653a5ce43e776fbb36eb2ddf5eac694 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Mon, 21 Jun 2021 09:12:12 +0100 Subject: [PATCH 41/61] Add Vector benchmarks --- Benchmarks/ArrayIterationBenchmarks.md | 23 ++++----- .../Benchmarks/ArrayIterationBenchmarks.cs | 47 +++++++++++++++---- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 96204149f..dd2dbfa99 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -18,20 +18,21 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1081 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.5.21302.13 [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-IRYCMS : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-UGMGOQ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` | Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | |--------------------- |-------- |-----------:|---------:|--------:|-------------:|--------:|------:|------:|------:|----------:| -| Foreach | 1000000 | 424.2 μs | 5.91 μs | 5.53 μs | baseline | | - | - | - | - | -| For | 1000000 | 428.7 μs | 2.69 μs | 2.52 μs | 1.01x slower | 0.01x | - | - | - | - | -| For_Unsafe | 1000000 | 412.9 μs | 3.31 μs | 2.76 μs | 1.03x faster | 0.01x | - | - | - | - | -| ForAdamczewski | 1000000 | 404.1 μs | 2.42 μs | 2.26 μs | 1.05x faster | 0.02x | - | - | - | - | -| ForAdamczewskiUnsafe | 1000000 | 355.1 μs | 3.48 μs | 3.25 μs | 1.19x faster | 0.02x | - | - | - | - | -| Span | 1000000 | 411.8 μs | 2.92 μs | 2.28 μs | 1.03x faster | 0.01x | - | - | - | - | -| ArraySegment_Foreach | 1000000 | 2,800.7 μs | 10.24 μs | 9.08 μs | 6.60x slower | 0.09x | - | - | - | 1 B | -| ArraySegment_For | 1000000 | 805.2 μs | 4.48 μs | 4.19 μs | 1.90x slower | 0.02x | - | - | - | - | -| ArraySegment_AsSpan | 1000000 | 412.4 μs | 2.08 μs | 1.74 μs | 1.03x faster | 0.01x | - | - | - | - | -| ArraySegment_AsArray | 1000000 | 798.7 μs | 4.39 μs | 3.67 μs | 1.88x slower | 0.03x | - | - | - | - | +| Foreach | 1000000 | 411.6 μs | 3.58 μs | 2.99 μs | baseline | | - | - | - | - | +| For | 1000000 | 410.3 μs | 1.57 μs | 1.22 μs | 1.00x faster | 0.01x | - | - | - | - | +| For_Unsafe | 1000000 | 411.1 μs | 1.58 μs | 1.48 μs | 1.00x faster | 0.01x | - | - | - | - | +| ForAdamczewski | 1000000 | 404.1 μs | 1.83 μs | 1.53 μs | 1.02x faster | 0.01x | - | - | - | - | +| ForAdamczewskiUnsafe | 1000000 | 411.2 μs | 1.93 μs | 1.71 μs | 1.00x faster | 0.01x | - | - | - | - | +| Span | 1000000 | 411.1 μs | 1.74 μs | 1.36 μs | 1.00x faster | 0.01x | - | - | - | - | +| ArraySegment_Foreach | 1000000 | 2,790.2 μs | 10.03 μs | 7.83 μs | 6.78x slower | 0.06x | - | - | - | 1 B | +| ArraySegment_For | 1000000 | 801.6 μs | 2.79 μs | 2.33 μs | 1.95x slower | 0.02x | - | - | - | - | +| ArraySegment_AsSpan | 1000000 | 410.4 μs | 1.33 μs | 1.24 μs | 1.00x faster | 0.01x | - | - | - | - | +| ArraySegment_AsArray | 1000000 | 560.8 μs | 2.97 μs | 2.63 μs | 1.36x slower | 0.01x | - | - | - | - | +| Vector | 1000000 | 104.3 μs | 0.54 μs | 0.50 μs | 3.95x faster | 0.04x | - | - | - | - | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs index 09798da41..6f996aa75 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs @@ -1,7 +1,9 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Jobs; using System; +using System.Numerics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks { @@ -35,11 +37,10 @@ public int Foreach() public int For() { var source = array!; - var len = array!.Length - 1; var sum = 0; // ReSharper disable once ForCanBeConvertedToForeach // ReSharper disable once LoopCanBeConvertedToQuery - for (var index = 0; index <= len; index++) + for (var index = 0; index <= source.Length - 1; index++) { var item = source[index]; sum += item; @@ -67,19 +68,22 @@ public unsafe int For_Unsafe() public int ForAdamczewski() { var source = array!; - var len = source.Length - 1; var sum1 = 0; var sum2 = 0; - for (var index = 0; index <= len; index += 2) + for (var index = 0; index <= source.Length - 2; index += 2) { long i1 = index + 0; long i2 = index + 1; var c = source[i1]; var d = source[i2]; - + sum1 += c; sum2 += d; } + if ((source.Length & 0x01) != 0) + { + sum1 += source[source.Length - 1]; + } return sum1 + sum2; } @@ -88,7 +92,7 @@ public unsafe int ForAdamczewskiUnsafe() { fixed (int* source = array) { - var len = array!.Length - 1; + var len = array!.Length - 2; var sum1 = 0; var sum2 = 0; for (var index = 0; index <= len; index += 2) @@ -101,6 +105,10 @@ public unsafe int ForAdamczewskiUnsafe() sum1 += c; sum2 += d; } + if ((array.Length & 0x01) != 0) + { + sum1 += source[array!.Length - 1]; + } return sum1 + sum2; } } @@ -154,14 +162,33 @@ public int ArraySegment_AsSpan() public int ArraySegment_AsArray() { var source = segment.Array!; - var len = array!.Length - 1; - var start = segment.Offset; - var end = start + segment.Count; + var end = segment.Offset + segment.Count; var sum = 0; - for (var index = start; index < end && index <= len; index++) + for (var index = segment.Offset; index < end; index++) sum += source[index]; return sum; } + [Benchmark] + public int Vector() + { + var source = array!; + var sum = 0; + var vectors = MemoryMarshal.Cast>(source); + var vectorSum = Vector.Zero; + + foreach (var vector in vectors) + vectorSum += vector; + + for (var index = 0; index < Vector.Count; index++) + sum += vectorSum[index]; + + for (var index = source.Length - (source.Length % Vector.Count); index < source.Length; index++) + { + var item = source[index]; + sum += item; + } + return sum; + } } } From e3c97cfa8820771818b4c0e07c42b95f55ee7074 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Sat, 26 Jun 2021 19:56:26 +0100 Subject: [PATCH 42/61] Cleanup --- Benchmarks/ArrayIterationBenchmarks.md | 28 +++++++------- .../Benchmarks/ArrayIterationBenchmarks.cs | 12 ++---- .../Aggregation/Sum/Sum.ReadOnlySpan.cs | 31 ++++----------- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 4 +- .../AsValueEnumerable'1.ReadOnlyList.cs | 2 +- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 2 +- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 2 +- ...lueEnumerable'6.ValueReadOnlyCollection.cs | 2 +- .../AsValueEnumerable'6.ValueReadOnlyList.cs | 2 +- .../Generation/ValueEnumerable/Range.cs | 2 +- .../Generation/ValueEnumerable/Repeat.cs | 4 +- .../Generation/ValueEnumerable/Return.cs | 2 +- .../SkipTake/SkipTake.ReadOnlyList.cs | 6 +-- .../SkipTake.ValueReadOnlyCollection.cs | 2 +- .../Select/Select/Select.ArraySegment.cs | 2 +- .../Select/Select/Select.ReadOnlyMemory.cs | 2 +- .../Select/Select.ValueReadOnlyCollection.cs | 2 +- .../Select/Select/Select.ValueReadOnlyList.cs | 2 +- .../SelectAt.ValueReadOnlyCollection.cs | 2 +- .../SelectAt/SelectAt.ValueReadOnlyList.cs | 2 +- .../ContainsVector.ReadOnlySpan.cs | 38 ++++++------------- NetFabric.Hyperlinq/Set/Distinct/Set.cs | 8 ++-- .../Utils/ArrayBuilder/ArrayBuilder.cs | 2 +- .../Utils/ArrayBuilder/LargeArrayBuilder.cs | 4 +- NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs | 4 +- .../Utils/Copy/Copy.ReadOnlySpan.cs | 8 ++-- .../Copy/Copy.ValueReadOnlyCollection.cs | 6 +-- 27 files changed, 74 insertions(+), 109 deletions(-) diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index dd2dbfa99..62db6529b 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -18,21 +18,21 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1081 (21H1/May2021Up Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.5.21302.13 [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UGMGOQ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT + Job-SLIMHF : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|--------------------- |-------- |-----------:|---------:|--------:|-------------:|--------:|------:|------:|------:|----------:| -| Foreach | 1000000 | 411.6 μs | 3.58 μs | 2.99 μs | baseline | | - | - | - | - | -| For | 1000000 | 410.3 μs | 1.57 μs | 1.22 μs | 1.00x faster | 0.01x | - | - | - | - | -| For_Unsafe | 1000000 | 411.1 μs | 1.58 μs | 1.48 μs | 1.00x faster | 0.01x | - | - | - | - | -| ForAdamczewski | 1000000 | 404.1 μs | 1.83 μs | 1.53 μs | 1.02x faster | 0.01x | - | - | - | - | -| ForAdamczewskiUnsafe | 1000000 | 411.2 μs | 1.93 μs | 1.71 μs | 1.00x faster | 0.01x | - | - | - | - | -| Span | 1000000 | 411.1 μs | 1.74 μs | 1.36 μs | 1.00x faster | 0.01x | - | - | - | - | -| ArraySegment_Foreach | 1000000 | 2,790.2 μs | 10.03 μs | 7.83 μs | 6.78x slower | 0.06x | - | - | - | 1 B | -| ArraySegment_For | 1000000 | 801.6 μs | 2.79 μs | 2.33 μs | 1.95x slower | 0.02x | - | - | - | - | -| ArraySegment_AsSpan | 1000000 | 410.4 μs | 1.33 μs | 1.24 μs | 1.00x faster | 0.01x | - | - | - | - | -| ArraySegment_AsArray | 1000000 | 560.8 μs | 2.97 μs | 2.63 μs | 1.36x slower | 0.01x | - | - | - | - | -| Vector | 1000000 | 104.3 μs | 0.54 μs | 0.50 μs | 3.95x faster | 0.04x | - | - | - | - | +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|--------------------- |-------- |-----------:|---------:|---------:|-------------:|--------:|------:|------:|------:|----------:| +| Foreach | 1000000 | 432.4 μs | 3.92 μs | 3.06 μs | baseline | | - | - | - | - | +| For | 1000000 | 435.1 μs | 8.19 μs | 7.26 μs | 1.01x slower | 0.02x | - | - | - | - | +| For_Unsafe | 1000000 | 434.8 μs | 8.67 μs | 8.11 μs | 1.00x slower | 0.02x | - | - | - | - | +| ForAdamczewski | 1000000 | 369.4 μs | 6.03 μs | 5.03 μs | 1.17x faster | 0.02x | - | - | - | - | +| ForAdamczewskiUnsafe | 1000000 | 436.1 μs | 4.05 μs | 3.38 μs | 1.01x slower | 0.01x | - | - | - | - | +| Span | 1000000 | 431.5 μs | 2.91 μs | 2.43 μs | 1.00x faster | 0.01x | - | - | - | - | +| ArraySegment_Foreach | 1000000 | 2,890.1 μs | 34.93 μs | 30.97 μs | 6.69x slower | 0.07x | - | - | - | 1 B | +| ArraySegment_For | 1000000 | 836.4 μs | 9.11 μs | 7.60 μs | 1.94x slower | 0.02x | - | - | - | - | +| ArraySegment_AsSpan | 1000000 | 430.0 μs | 4.37 μs | 3.65 μs | 1.01x faster | 0.01x | - | - | - | - | +| ArraySegment_AsArray | 1000000 | 575.1 μs | 3.28 μs | 2.91 μs | 1.33x slower | 0.01x | - | - | - | - | +| Vector | 1000000 | 118.6 μs | 1.91 μs | 2.12 μs | 3.63x faster | 0.08x | - | - | - | - | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs index 6f996aa75..b74b4255f 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs @@ -72,10 +72,8 @@ public int ForAdamczewski() var sum2 = 0; for (var index = 0; index <= source.Length - 2; index += 2) { - long i1 = index + 0; - long i2 = index + 1; - var c = source[i1]; - var d = source[i2]; + var c = source[index + 0]; + var d = source[index + 1]; sum1 += c; sum2 += d; @@ -97,10 +95,8 @@ public unsafe int ForAdamczewskiUnsafe() var sum2 = 0; for (var index = 0; index <= len; index += 2) { - long i1 = index + 0; - long i2 = index + 1; - var c = source[i1]; - var d = source[i2]; + var c = source[index + 0]; + var d = source[index + 1]; sum1 += c; sum2 += d; diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs index d20c6b794..53ddf5bff 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs @@ -24,18 +24,11 @@ static TSource Sum(this ReadOnlySpan source) for (var index = 0; index < Vector.Count; index++) sum = GenericsOperator.Add(vectorSum[index], sum); - for (var index = source.Length - (source.Length % Vector.Count); index < source.Length; index++) - { - var item = source[index]; - sum = GenericsOperator.Add(item, sum); - } + var count = source.Length % Vector.Count; + source = source.Slice(source.Length - count, count); } - else - { - foreach (var item in source) - sum = GenericsOperator.Add(item, sum); - } - + foreach (var item in source) + sum = GenericsOperator.Add(item, sum); return sum; } @@ -59,17 +52,11 @@ static TResult Sum(this ReadOnlySp for (var index = 0; index < Vector.Count; index++) sum = GenericsOperator.Add(vectorSum[index], sum); - for (var index = source.Length - (source.Length % Vector.Count); index < source.Length; index++) - { - var item = source[index]; - sum = GenericsOperator.Add(selector.Invoke(item), sum); - } - } - else - { - foreach (var item in source) - sum = GenericsOperator.Add(selector.Invoke(item), sum); + var count = source.Length % Vector.Count; + source = source.Slice(source.Length - count, count); } + foreach (var item in source) + sum = GenericsOperator.Add(selector.Invoke(item), sum); return sum; } @@ -77,10 +64,8 @@ static TSum Sum(this ReadOnlySpan source) where TSum : struct { var sum = default(TSum); - foreach (var item in source) sum = GenericsOperator.AddNullable(item, sum); - return sum; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index ae372e243..98b5f8875 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -51,7 +51,7 @@ public void CopyTo(Span span) using var enumerator = GetEnumerator(); checked { - for (var index = 0; enumerator.MoveNext() && index < span.Length; index++) + for (var index = 0; enumerator.MoveNext(); index++) span[index] = enumerator.Current; } } @@ -65,7 +65,7 @@ public void CopyTo(TSource[] array, int arrayIndex) collection.CopyTo(array, arrayIndex); break; default: - CopyTo(array.AsSpan().Slice(arrayIndex)); + CopyTo(array.AsSpan(arrayIndex)); break; } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs index f5dec170c..fdcb0db47 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs @@ -86,7 +86,7 @@ public void CopyTo(TSource[] array, int arrayIndex) collection.CopyTo(array, arrayIndex); break; default: - CopyTo(array.AsSpan().Slice(arrayIndex)); + CopyTo(array.AsSpan(arrayIndex)); break; } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index 6c4c72d8f..9db9a65ed 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -63,7 +63,7 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index d9f9e8848..831644a20 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -98,7 +98,7 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index e8bc1433e..382f539f7 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -105,7 +105,7 @@ public void CopyTo(TSource[] array, int arrayIndex) collection.CopyTo(array, arrayIndex); break; default: - CopyTo(array.AsSpan().Slice(arrayIndex)); + CopyTo(array.AsSpan(arrayIndex)); break; } } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs index 658ac133a..61f92a2ff 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs @@ -117,7 +117,7 @@ public void CopyTo(TSource[] array, int arrayIndex) collection.CopyTo(array, arrayIndex); break; default: - CopyTo(array.AsSpan().Slice(arrayIndex)); + CopyTo(array.AsSpan(arrayIndex)); break; } } diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs index 2dfe9894d..e8f8cbdff 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs @@ -88,7 +88,7 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(int[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs index e65b2e982..0e90f3a15 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs @@ -64,7 +64,7 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) @@ -217,7 +217,7 @@ public static void CopyToVector(this RepeatEnumerable source, for (var index = 0; index < destinationVectors.Length; index++) destinationVectors[index] = vector; - for (var index = count - (count % Vector.Count); index < count && index < destination.Length; index++) + for (var index = count - (count % Vector.Count); index < count; index++) destination[index] = value; } else diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs index a0489b573..58f85cb90 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs @@ -75,7 +75,7 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs index 53a7097dc..da715018e 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs @@ -73,12 +73,12 @@ public void CopyTo(Span span) if (offset is 0) { - for(var index = 0; index < Count && index < span.Length; index++) + for(var index = 0; index < Count; index++) span[index] = source[index]; } else { - for(var index = 0; index < Count && index < span.Length; index++) + for(var index = 0; index < Count; index++) span[index] = source[index + offset]; } } @@ -93,7 +93,7 @@ public void CopyTo(TSource[] array, int arrayIndex) if (offset is 0 && Count == source.Count && source is ICollection collection) collection.CopyTo(array, arrayIndex); else - CopyTo(array.AsSpan().Slice(arrayIndex)); + CopyTo(array.AsSpan(arrayIndex)); } public bool Contains(TSource item) diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs index 94012f107..36351086b 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs @@ -78,7 +78,7 @@ public void CopyTo(TSource[] array, int arrayIndex) if (offset is 0 && Count == source.Count && source is ICollection collection) collection.CopyTo(array, arrayIndex); else - CopyTo(array.AsSpan().Slice(arrayIndex)); + CopyTo(array.AsSpan(arrayIndex)); } public bool Contains(TSource item) diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index e014144d0..266db4240 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -85,7 +85,7 @@ public void CopyTo(Span span) } void ICollection.CopyTo(TResult[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); void ICollection.Add(TResult item) => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index 46305ec71..56f92f6b6 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -83,7 +83,7 @@ public void CopyTo(Span span) } void ICollection.CopyTo(TResult[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); void ICollection.Add(TResult item) => Throw.NotSupportedException(); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index 86a52aac4..3dfaf18be 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -74,7 +74,7 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TResult[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); public bool Contains(TResult item) => ValueReadOnlyCollectionExtensions.Contains(source, item, default, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs index 800ebbc92..15cb40d8b 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -85,7 +85,7 @@ public readonly void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly void CopyTo(TResult[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); public readonly bool Contains(TResult item) => ValueReadOnlyCollectionExtensions.Contains(source, item, default, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index 4922ab686..e30d01fa7 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -74,7 +74,7 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TResult[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); public bool Contains(TResult item) => ContainsAt(source, item, default, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs index 8659308fd..573377393 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -90,7 +90,7 @@ public void CopyTo(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TResult[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); public readonly bool Contains(TResult item) => ValueReadOnlyCollectionExtensions.ContainsAt(source, item, default, selector); diff --git a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs index 97965fb1b..60ef67bd2 100644 --- a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs @@ -23,22 +23,14 @@ static bool ContainsVector(this ReadOnlySpan source, TSource v return true; } - for (var index = source.Length - (source.Length % Vector.Count); index < source.Length; index++) - { - var item = source[index]; - if (GenericsOperator.Equals(item, value)) - return true; - } + var count = source.Length % Vector.Count; + source = source.Slice(source.Length - count, count); } - else + foreach (var item in source) { - foreach (var item in source) - { - if (GenericsOperator.Equals(item, value)) - return true; - } - } - + if (GenericsOperator.Equals(item, value)) + return true; + } return false; } @@ -63,22 +55,14 @@ static bool ContainsVector(this Re return true; } - for (var index = source.Length - (source.Length % Vector.Count); index < source.Length; index++) - { - var item = source[index]; - if (GenericsOperator.Equals(selector.Invoke(item), value)) - return true; - } + var count = source.Length % Vector.Count; + source = source.Slice(source.Length - count, count); } - else + foreach (var item in source) { - foreach (var item in source) - { - if (GenericsOperator.Equals(selector.Invoke(item), value)) - return true; - } + if (GenericsOperator.Equals(selector.Invoke(item), value)) + return true; } - return false; } } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index 12c3e71c6..1a1f1f649 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -142,7 +142,7 @@ void Resize() Array.Clear(newSlots, Count, newSlots.Length - Count); Array.Clear(newBuckets, 0, newBuckets.Length); - for (var index = 0; index < Count && index < newSlots.Length; index++) + for (var index = 0; index < Count; index++) { var bucket = newSlots[index].HashCode % newSize; newSlots[index].Next = newBuckets[bucket] - 1; @@ -202,8 +202,8 @@ public readonly void CopyTo(Span span) if (Count is 0) return; - var source = slots!.AsSpan().Slice(0, Count); - for (var index = 0; index < source.Length && index < span.Length; index++) + var source = slots!.AsSpan(0, Count); + for (var index = 0; index < source.Length; index++) { ref readonly var slot = ref source[index]; span[index] = slot.Value; @@ -211,7 +211,7 @@ public readonly void CopyTo(Span span) } public readonly void CopyTo(TElement[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); [ExcludeFromCodeCoverage] readonly void ICollection.Add(TElement item) diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs index c6dac872d..58ae177ef 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs @@ -70,7 +70,7 @@ public int Capacity // } public readonly Span AsSpan() - => buffer!.AsSpan().Slice(0, Count); + => buffer!.AsSpan(0, Count); /// /// Adds an item to the backing array, resizing it if necessary. diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs index 5e715adf3..4e3c52904 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs @@ -107,7 +107,7 @@ public void AddRef(in T item) /// The destination array. /// The index in to start copying to. public readonly void CopyTo(T[] array, int arrayIndex) - => CopyTo(array.AsSpan().Slice(arrayIndex)); + => CopyTo(array.AsSpan(arrayIndex)); public readonly void CopyTo(Span span) { @@ -122,7 +122,7 @@ public readonly void CopyTo(Span span) if (arrayIndex < Count) { var length = Count - arrayIndex; - current.AsSpan().Slice(0, length).CopyTo(span.Slice(arrayIndex, length)); + current.AsSpan(0, length).CopyTo(span.Slice(arrayIndex, length)); } } diff --git a/NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs b/NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs index a19e81484..84992d303 100644 --- a/NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs +++ b/NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs @@ -21,12 +21,12 @@ public static void CopyRange(int start, int count, Span destination) if (start is 0) { - for (var index = 0; index < Vector.Count && index < destination.Length; index++) + for (var index = 0; index < Vector.Count; index++) destination[index] = index; } else { - for (var index = 0; index < Vector.Count && index < destination.Length; index++) + for (var index = 0; index < Vector.Count; index++) destination[index] = index + start; } diff --git a/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs index e2919534d..57fd57f97 100644 --- a/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs @@ -22,7 +22,7 @@ public static void Copy(ReadOnlySpan sourc { Debug.Assert(destination.Length >= source.Length); - for (var index = 0; index < source.Length && index < destination.Length; index++) + for (var index = 0; index < source.Length; index++) { var item = source[index]; destination[index] = selector.Invoke(item); @@ -50,7 +50,7 @@ public static void CopyVector(Read destinationVectors[index] = vectorSelector.Invoke(sourceVector); } - for (var index = source.Length - (source.Length % Vector.Count); index < source.Length && index < destination.Length; index++) + for (var index = source.Length - (source.Length % Vector.Count); index < source.Length; index++) { var item = source[index]; destination[index] = selector.Invoke(item); @@ -58,7 +58,7 @@ public static void CopyVector(Read } else { - for (var index = 0; index < source.Length && index < destination.Length; index++) + for (var index = 0; index < source.Length; index++) { var item = source[index]; destination[index] = selector.Invoke(item); @@ -72,7 +72,7 @@ public static void CopyAt(ReadOnlySpan sou { Debug.Assert(destination.Length >= source.Length); - for (var index = 0; index < source.Length && index < destination.Length; index++) + for (var index = 0; index < source.Length; index++) { var item = source[index]; destination[index] = selector.Invoke(item, index); diff --git a/NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyCollection.cs index 4cc30f807..b2b6d8070 100644 --- a/NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyCollection.cs @@ -15,7 +15,7 @@ public static void Copy(TEnumerable source, S using var enumerator = source.GetEnumerator(); checked { - for (var index = 0; enumerator.MoveNext() && index < destination.Length; index++) + for (var index = 0; enumerator.MoveNext(); index++) destination[index] = enumerator.Current; } } @@ -31,7 +31,7 @@ public static void Copy(T using var enumerator = source.GetEnumerator(); checked { - for (var index = 0; enumerator.MoveNext() && index < destination.Length; index++) + for (var index = 0; enumerator.MoveNext(); index++) destination[index] = selector.Invoke(enumerator.Current); } } @@ -47,7 +47,7 @@ public static void CopyAt using var enumerator = source.GetEnumerator(); checked { - for (var index = 0; enumerator.MoveNext() && index < destination.Length; index++) + for (var index = 0; enumerator.MoveNext(); index++) destination[index] = selector.Invoke(enumerator.Current, index); } } From 3c29ee4530a0f6a70ed8eba54711e8fbe4f87abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Tue, 29 Jun 2021 00:17:35 +0100 Subject: [PATCH 43/61] Improve performance of Sum() (#370) --- .../Aggregation/Sum.TestData.cs | 49 +++- .../Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs | 45 +++- .../Sum/Sum.ValueEnumerable.Tests.cs | 52 +++- .../Sum/Sum.ValueReadOnlyCollection.Tests.cs | 44 +++- .../SumAsync.AsyncValueEnumerable.Tests.cs | 46 +++- .../Aggregation/Sum/Sum.Range.cs | 6 +- .../Aggregation/Sum/Sum.ReadOnlySpan.cs | 189 +++++++++------ .../Aggregation/Sum/Sum.ValueEnumerable.cs | 14 +- .../Sum/SumAsync.AsyncValueEnumerable.cs | 12 +- ...sAsyncValueEnumerable'1.AsyncEnumerable.cs | 16 ++ ...cValueEnumerable'1.AsyncValueEnumerable.cs | 20 ++ ...sAsyncValueEnumerable'6.AsyncEnumerable.cs | 36 +++ ...cValueEnumerable'6.AsyncValueEnumerable.cs | 36 +++ .../AsValueEnumerable'1.Enumerable.cs | 16 ++ .../AsValueEnumerable'1.ReadOnlyCollection.cs | 16 ++ .../AsValueEnumerable'1.ReadOnlyList.cs | 20 ++ .../AsValueEnumerable'1.ValueEnumerable.cs | 20 ++ ...lueEnumerable'1.ValueReadOnlyCollection.cs | 20 ++ .../AsValueEnumerable'6.Enumerable.cs | 36 +++ .../AsValueEnumerable'6.ReadOnlyCollection.cs | 36 +++ .../AsValueEnumerable'6.ValueEnumerable.cs | 36 +++ ...lueEnumerable'6.ValueReadOnlyCollection.cs | 36 +++ .../AsValueEnumerable'6.ValueReadOnlyList.cs | 36 +++ .../AsValueEnumerable.ArraySegment.cs | 28 ++- .../AsValueEnumerable.ReadOnlyMemory.cs | 26 +- .../AsValueEnumerable.ReadOnlySpan.cs | 26 +- .../Where/Where/Where.ArraySegment.cs | 20 ++ .../Where/Where/Where.AsyncValueEnumerable.cs | 28 +++ .../Where/Where/Where.ReadOnlyMemory.cs | 20 ++ .../Where/Where/Where.ReadOnlySpan.cs | 20 ++ .../Where/Where/Where.ValueEnumerable.cs | 28 +++ .../Where/Where.ValueReadOnlyCollection.cs | 28 +++ .../Where/WhereAt/WhereAt.ArraySegment.cs | 20 ++ .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 28 +++ .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 20 ++ .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 20 ++ .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 28 +++ .../WhereAt.ValueReadOnlyCollection.cs | 28 +++ .../WhereSelect/WhereSelect.ArraySegment.cs | 24 ++ .../WhereSelect.AsyncValueEnumerable.cs | 32 +++ .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 24 ++ .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 24 ++ .../WhereSelect.ValueEnumerable.cs | 32 +++ .../WhereSelect.ValueReadOnlyCollection.cs | 32 +++ .../Select/Select/Select.ArraySegment.cs | 20 ++ .../Select/Select.AsyncValueEnumerable.cs | 28 +++ .../Select/Select/Select.ReadOnlyMemory.cs | 20 ++ .../Select/Select/Select.ReadOnlySpan.cs | 20 ++ .../Select/Select/Select.ValueEnumerable.cs | 28 +++ .../Select/Select.ValueReadOnlyCollection.cs | 28 +++ .../Select/Select/Select.ValueReadOnlyList.cs | 28 +++ .../Select/SelectAt/SelectAt.ArraySegment.cs | 20 ++ .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 28 +++ .../SelectAt/SelectAt.ReadOnlyMemory.cs | 20 ++ .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 20 ++ .../SelectAt/SelectAt.ValueEnumerable.cs | 28 +++ .../SelectAt.ValueReadOnlyCollection.cs | 28 +++ .../SelectAt/SelectAt.ValueReadOnlyList.cs | 28 +++ .../Select/SelectVector/SelectVector.Range.cs | 12 + .../SelectVector/SelectVector.ReadOnlySpan.cs | 26 +- .../SelectMany/SelectMany.ArraySegment.cs | 28 +++ .../SelectMany/SelectMany.ReadOnlyMemory.cs | 28 +++ .../SelectMany/SelectMany.ValueEnumerable.cs | 36 +++ .../ContainsVector.ReadOnlySpan.cs | 4 +- .../Set/Distinct/Distinct.ArraySegment.cs | 16 ++ .../Distinct/Distinct.AsyncValueEnumerable.cs | 24 ++ .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 16 ++ .../Set/Distinct/Distinct.ValueEnumerable.cs | 24 ++ NetFabric.Hyperlinq/Utils/GenericsOperator.cs | 123 ---------- NetFabric.Hyperlinq/Utils/IntExtensions.cs | 15 ++ NetFabric.Hyperlinq/Utils/Scalar.cs | 227 ++++++++++++++++++ NetFabric.Hyperlinq/Utils/VectorExtensions.cs | 18 ++ 72 files changed, 2048 insertions(+), 266 deletions(-) delete mode 100644 NetFabric.Hyperlinq/Utils/GenericsOperator.cs create mode 100644 NetFabric.Hyperlinq/Utils/IntExtensions.cs create mode 100644 NetFabric.Hyperlinq/Utils/Scalar.cs create mode 100644 NetFabric.Hyperlinq/Utils/VectorExtensions.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs index 6e2a00ad6..a749e624d 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs @@ -7,13 +7,18 @@ namespace NetFabric.Hyperlinq { public static partial class TestData { - public static TheoryData Sum + public static TheoryData SumDouble => new() { new double[] { }, new[] { double.NaN }, new[] { double.PositiveInfinity }, new[] { 1.0 }, + new[] { 1.0, 2.0 }, + new[] { 1.0, 2.0, 3.0 }, + new[] { 1.0, 2.0, 3.0, 4.0 }, + new[] { 1.0, 2.0, 3.0, 4.0, 5.0 }, + new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }, new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }, new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }, new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }, @@ -24,22 +29,58 @@ public static TheoryData Sum new[] { double.PositiveInfinity, double.PositiveInfinity } }; - public static TheoryData NullableSum + public static TheoryData SumNullableDouble => new() { new double?[] { }, new double?[] { default }, new double?[] { double.NaN }, new double?[] { double.PositiveInfinity }, - new double?[] { 1 }, + new double?[] { 1.0 }, + new double?[] { 1.0, 2.0 }, + new double?[] { 1.0, 2.0, 3.0 }, + new double?[] { 1.0, 2.0, 3.0, 4.0 }, + new double?[] { 1.0, 2.0, 3.0, 4.0, 5.0 }, new double?[] { default, default, default }, new double?[] { default, 2.0, double.NaN, 4.0, default }, new double?[] { default, 2.0, 3.0, 4.0, default }, new double?[] { 1.0, 2.0, default, 4.0, 5.0 }, - new double?[] { 1.0, 2.0, 3.0, 4.0, 5.0 }, new double?[] { double.MaxValue, double.MaxValue }, new double?[] { double.PositiveInfinity, double.PositiveInfinity } }; + public static TheoryData SumDecimal + => new() + { + new decimal[] { }, + new[] { 1.0M }, + new[] { 1.0M, 2.0M }, + new[] { 1.0M, 2.0M, 3.0M }, + new[] { 1.0M, 2.0M, 3.0M, 4.0M }, + new[] { 1.0M, 2.0M, 3.0M, 4.0M, 5.0M }, + new[] { 1.0M, 2.0M, 3.0M, 4.0M, 5.0M, 6.0M }, + new[] { 1.0M, 2.0M, 3.0M, 4.0M, 5.0M, 6.0M, 7.0M }, + new[] { 1.0M, 2.0M, 3.0M, 4.0M, 5.0M, 6.0M, 7.0M, 8.0M }, + new[] { 1.0M, 2.0M, 3.0M, 4.0M, 5.0M, 6.0M, 7.0M, 8.0M, 9.0M }, + new[] { 1.0M, 2.0M, 3.0M, 4.0M, 5.0M, 6.0M, 7.0M, 8.0M, 9.0M, 10.0M, 11.0M, 12.0M, 13.0M, 14.0M, 15.0M, 16.0M, 17.0M, 18.0M, 19.0M, 20.0M }, + //new[] { decimal.MaxValue, decimal.MaxValue }, + }; + + + public static TheoryData SumNullableDecimal + => new() + { + new decimal?[] { }, + new decimal?[] { default }, + new decimal?[] { 1.0M }, + new decimal?[] { 1.0M, 2.0M }, + new decimal?[] { 1.0M, 2.0M, 3.0M }, + new decimal?[] { 1.0M, 2.0M, 3.0M, 4.0M }, + new decimal?[] { 1.0M, 2.0M, 3.0M, 4.0M, 5.0M }, + new decimal?[] { default, default, default }, + new decimal?[] { default, 2.0M, 3.0M, 4.0M, default }, + new decimal?[] { 1.0M, 2.0M, default, 4.0M, 5.0M }, + //new decimal?[] { decimal.MaxValue, decimal.MaxValue }, + }; } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs index c44e6f00e..0515270bd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs @@ -9,8 +9,8 @@ public class ArrayTests { [Theory] - [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public void Sum_With_ValidData_Must_Succeed(double[] source) + [MemberData(nameof(TestData.SumDouble), MemberType = typeof(TestData))] + public void Sum_With_Double_Must_Succeed(double[] source) { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); @@ -27,8 +27,8 @@ public void Sum_With_ValidData_Must_Succeed(double[] source) } [Theory] - [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) + [MemberData(nameof(TestData.SumNullableDouble), MemberType = typeof(TestData))] + public void Sum_With_NullableDouble_Must_Succeed(double?[] source) { // Arrange var wrapped = (ReadOnlySpan)source.AsSpan(); @@ -43,5 +43,42 @@ public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) _ = result.Must() .BeEqualTo(expected!.Value); } + + + [Theory] + [MemberData(nameof(TestData.SumDecimal), MemberType = typeof(TestData))] + public void Sum_With_Decimal_Must_Succeed(decimal[] source) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SumNullableDecimal), MemberType = typeof(TestData))] + public void Sum_With_NullableDecimal_ValidData_Must_Succeed(decimal?[] source) + { + // Arrange + var wrapped = (ReadOnlySpan)source.AsSpan(); + var expected = source + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected!.Value); + } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs index b4420fa02..2f8bdac05 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs @@ -8,8 +8,8 @@ namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum public class ValueEnumerableTests { [Theory] - [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public void Sum_With_ValidData_Must_Succeed(double[] source) + [MemberData(nameof(TestData.SumDouble), MemberType = typeof(TestData))] + public void Sum_With_Double_Must_Succeed(double[] source) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); @@ -17,8 +17,8 @@ public void Sum_With_ValidData_Must_Succeed(double[] source) .Sum(); // Act - var result = wrapped - .Sum, Wrap.Enumerator, double, double>(); + var result = wrapped.AsValueEnumerable() + .Sum(); // Assert _ = result.Must() @@ -26,8 +26,26 @@ public void Sum_With_ValidData_Must_Succeed(double[] source) } [Theory] - [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) + [MemberData(nameof(TestData.SumNullableDouble), MemberType = typeof(TestData))] + public void Sum_With_NullableDouble_Must_Succeed(double?[] source) + { + // Arrange + var wrapped = Wrap.AsValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected!.Value); + } + + [Theory] + [MemberData(nameof(TestData.SumDecimal), MemberType = typeof(TestData))] + public void Sum_With_Decimal_Must_Succeed(decimal[] source) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); @@ -35,8 +53,26 @@ public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) .Sum(); // Act - var result = wrapped - .Sum, Wrap.Enumerator, double?, double>(); + var result = wrapped.AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SumNullableDecimal), MemberType = typeof(TestData))] + public void Sum_With_NullableDecimal_Must_Succeed(decimal?[] source) + { + // Arrange + var wrapped = Wrap.AsValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Sum(); // Assert _ = result.Must() diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs index 0dae33b78..d1078b274 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs @@ -8,8 +8,8 @@ namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum public class ValueReadOnlyCollectionTests { [Theory] - [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public void Sum_With_ValidData_Must_Succeed(double[] source) + [MemberData(nameof(TestData.SumDouble), MemberType = typeof(TestData))] + public void Sum_With_Double_Must_Succeed(double[] source) { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); @@ -26,8 +26,44 @@ public void Sum_With_ValidData_Must_Succeed(double[] source) } [Theory] - [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public void Sum_With_Nullable_ValidData_Must_Succeed(double?[] source) + [MemberData(nameof(TestData.SumNullableDouble), MemberType = typeof(TestData))] + public void Sum_With_NullableDouble_Must_Succeed(double?[] source) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyCollection(source); + var expected = source + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected!.Value); + } + + [Theory] + [MemberData(nameof(TestData.SumDecimal), MemberType = typeof(TestData))] + public void Sum_With_Decimal_Must_Succeed(decimal[] source) + { + // Arrange + var wrapped = Wrap.AsValueReadOnlyCollection(source); + var expected = source + .Sum(); + + // Act + var result = wrapped.AsValueEnumerable() + .Sum(); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SumNullableDecimal), MemberType = typeof(TestData))] + public void Sum_With_NullableDecimal_Must_Succeed(decimal?[] source) { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs index c595838a1..51065d9cb 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs @@ -9,8 +9,8 @@ namespace NetFabric.Hyperlinq.UnitTests.Aggregation.Sum public class AsyncValueEnumerableTests { [Theory] - [MemberData(nameof(TestData.Sum), MemberType = typeof(TestData))] - public async ValueTask SumAsync_With_ValidData_Must_Succeed(double[] source) + [MemberData(nameof(TestData.SumDouble), MemberType = typeof(TestData))] + public async ValueTask SumAsync_With_Double_Must_Succeed(double[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -28,8 +28,46 @@ public async ValueTask SumAsync_With_ValidData_Must_Succeed(double[] source) } [Theory] - [MemberData(nameof(TestData.NullableSum), MemberType = typeof(TestData))] - public async ValueTask SumAsync_With_Nullable_ValidData_Must_Succeed(double?[] source) + [MemberData(nameof(TestData.SumNullableDouble), MemberType = typeof(TestData))] + public async ValueTask SumAsync_With_NullableDouble_Must_Succeed(double?[] source) + { + // Arrange + var wrapped = Wrap.AsAsyncValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = await wrapped.AsAsyncValueEnumerable() + .SumAsync() + .ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected!.Value); + } + + [Theory] + [MemberData(nameof(TestData.SumDecimal), MemberType = typeof(TestData))] + public async ValueTask SumAsync_With_Decimal_Must_Succeed(decimal[] source) + { + // Arrange + var wrapped = Wrap.AsAsyncValueEnumerable(source); + var expected = source + .Sum(); + + // Act + var result = await wrapped.AsAsyncValueEnumerable() + .SumAsync() + .ConfigureAwait(false); + + // Assert + _ = result.Must() + .BeEqualTo(expected); + } + + [Theory] + [MemberData(nameof(TestData.SumNullableDecimal), MemberType = typeof(TestData))] + public async ValueTask SumAsync_With_NullableDecimal_Must_Succeed(decimal?[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs index a84a82a13..2712efc14 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs @@ -43,18 +43,18 @@ static unsafe TResult SumRange(int start, i } for (index = 0; index < Vector.Count; index++) - sum = GenericsOperator.Add(vectorSum[index], sum); + sum = Scalar.Add(vectorSum[index], sum); } if (start is 0) { for (; index < count; index++) - sum = GenericsOperator.Add(selector.Invoke(index), sum); + sum = Scalar.Add(selector.Invoke(index), sum); } else { for (; index < count; index++) - sum = GenericsOperator.Add(selector.Invoke(index + start), sum); + sum = Scalar.Add(selector.Invoke(index + start), sum); } return sum; diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs index 53ddf5bff..197420b85 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs @@ -6,67 +6,42 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore] - static TSource Sum(this ReadOnlySpan source) - where TSource : struct + static TSum Sum(this ReadOnlySpan source) + where TSum : struct { - var sum = default(TSource); - - if (Vector.IsHardwareAccelerated && source.Length > Vector.Count * 2) // use SIMD + var sum0 = default(TSum); + var sum1 = default(TSum); + for (var index = 0; index < source.Length - 1; index += 2) { - var vectors = MemoryMarshal.Cast>(source); - var vectorSum = Vector.Zero; - - foreach (var vector in vectors) - vectorSum += vector; - - for (var index = 0; index < Vector.Count; index++) - sum = GenericsOperator.Add(vectorSum[index], sum); - - var count = source.Length % Vector.Count; - source = source.Slice(source.Length - count, count); + var item0 = source[index]; + var item1 = source[index + 1]; + sum0 = Scalar.Add(item0, sum0); + sum1 = Scalar.Add(item1, sum1); } - foreach (var item in source) - sum = GenericsOperator.Add(item, sum); - return sum; - } + + if (source.Length.IsOdd()) + sum0 = Scalar.Add(source[source.Length - 1], sum0); + return Scalar.Add(sum0, sum1); + } + [GeneratorIgnore] - static TResult Sum(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction + static TSum SumVector(this ReadOnlySpan source) where TSource : struct - where TResult : struct + where TSum : struct { - var sum = default(TResult); - - if (Vector.IsHardwareAccelerated && source.Length > Vector.Count * 2) // use SIMD - { - var vectors = MemoryMarshal.Cast>(source); - var vectorSum = Vector.Zero; - - foreach (var vector in vectors) - vectorSum += vectorSelector.Invoke(vector); + if (!Vector.IsHardwareAccelerated || source.Length <= Vector.Count * 2) + return Sum(source); + + var vectors = MemoryMarshal.Cast>(source); + var vectorSum = Vector.Zero; - for (var index = 0; index < Vector.Count; index++) - sum = GenericsOperator.Add(vectorSum[index], sum); + foreach (var vector in vectors) + vectorSum += vector; - var count = source.Length % Vector.Count; - source = source.Slice(source.Length - count, count); - } - foreach (var item in source) - sum = GenericsOperator.Add(selector.Invoke(item), sum); - return sum; - } - - static TSum Sum(this ReadOnlySpan source) - where TSum : struct - { - var sum = default(TSum); - foreach (var item in source) - sum = GenericsOperator.AddNullable(item, sum); - return sum; + var count = source.Length % Vector.Count; + return Scalar.Add(vectorSum.Sum(), Sum(source.Slice(source.Length - count, count))); } [GeneratorIgnore] @@ -74,13 +49,21 @@ static TSum Sum(this ReadOnlySpan source, TP where TPredicate : struct, IFunction where TSum : struct { - var sum = default(TSum); - foreach (var item in source) + var sum0 = default(TSum); + var sum1 = default(TSum); + for (var index = 0; index < source.Length - 1; index += 2) { - if (predicate.Invoke(item)) - sum = GenericsOperator.AddNullable(item, sum); + var item0 = source[index]; + var item1 = source[index + 1]; + sum0 = Scalar.Add(Scalar.GetValueOrDefault(predicate, item0), sum0); + sum1 = Scalar.Add(Scalar.GetValueOrDefault(predicate, item1), sum1); + } + if (source.Length.IsOdd()) + { + var item = source[source.Length - 1]; + sum0 = Scalar.Add(Scalar.GetValueOrDefault(predicate, item), sum0); } - return sum; + return Scalar.Add(sum0, sum1); } [GeneratorIgnore] @@ -88,14 +71,22 @@ static TSum SumAt(this ReadOnlySpan source, where TPredicate : struct, IFunction where TSum : struct { - var sum = default(TSum); - for (var index = 0; index < source.Length; index++) + var sum0 = default(TSum); + var sum1 = default(TSum); + for (var index = 0; index < source.Length - 1; index += 2) { + var item0 = source[index]; + var item1 = source[index + 1]; + sum0 = Scalar.Add(Scalar.GetValueOrDefault(predicate, item0, index), sum0); + sum1 = Scalar.Add(Scalar.GetValueOrDefault(predicate, item1, index + 1), sum1); + } + if (source.Length.IsOdd()) + { + var index = source.Length - 1; var item = source[index]; - if (predicate.Invoke(item, index)) - sum = GenericsOperator.AddNullable(item, sum); + sum0 = Scalar.Add(Scalar.GetValueOrDefault(predicate, item, index), sum0); } - return sum; + return Scalar.Add(sum0, sum1); } [GeneratorIgnore] @@ -103,10 +94,41 @@ static TSum Sum(this ReadOnlySpan so where TSelector : struct, IFunction where TSum : struct { - var sum = default(TSum); - foreach (var item in source) - sum = GenericsOperator.AddNullable(selector.Invoke(item), sum); - return sum; + var sum0 = default(TSum); + var sum1 = default(TSum); + for (var index = 0; index < source.Length - 1; index += 2) + { + var item0 = source[index]; + var item1 = source[index + 1]; + sum0 = Scalar.Add(selector.Invoke(item0), sum0); + sum1 = Scalar.Add(selector.Invoke(item1), sum1); + } + + if (source.Length.IsOdd()) + sum0 = Scalar.Add(selector.Invoke(source[source.Length - 1]), sum0); + + return Scalar.Add(sum0, sum1); + } + + [GeneratorIgnore] + static TSum SumVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) + where TVectorSelector : struct, IFunction, Vector> + where TSelector : struct, IFunction + where TSource : struct + where TResult : struct + where TSum : struct + { + if (!Vector.IsHardwareAccelerated || source.Length <= Vector.Count * 2) + return Sum(source); + + var vectors = MemoryMarshal.Cast>(source); + var vectorSum = Vector.Zero; + + foreach (var vector in vectors) + vectorSum += vectorSelector.Invoke(vector); + + var count = source.Length % Vector.Count; + return Scalar.Add(vectorSum.Sum(), Sum(source.Slice(source.Length - count, count), selector)); } [GeneratorIgnore] @@ -114,13 +136,21 @@ static TSum SumAt(this ReadOnlySpan where TSelector : struct, IFunction where TSum : struct { - var sum = default(TSum); - for (var index = 0; index < source.Length; index++) + var sum0 = default(TSum); + var sum1 = default(TSum); + for (var index = 0; index < source.Length - 1; index += 2) { - var item = source[index]; - sum = GenericsOperator.AddNullable(selector.Invoke(item, index), sum); + var item0 = source[index]; + var item1 = source[index + 1]; + sum0 = Scalar.Add(selector.Invoke(item0, index), sum0); + sum1 = Scalar.Add(selector.Invoke(item1, index + 1), sum1); + } + if (source.Length.IsOdd()) + { + var index = source.Length - 1; + sum0 = Scalar.Add(selector.Invoke(source[index], index), sum0); } - return sum; + return Scalar.Add(sum0, sum1); } [GeneratorIgnore] @@ -129,13 +159,24 @@ static TSum Sum(this ReadOnlySpan where TSelector : struct, IFunction where TSum : struct { - var sum = default(TSum); - foreach (var item in source) + var sum0 = default(TSum); + var sum1 = default(TSum); + for (var index = 0; index < source.Length - 1; index += 2) + { + var item0 = source[index]; + var item1 = source[index + 1]; + if (predicate.Invoke(item0)) + sum0 = Scalar.Add(selector.Invoke(item0), sum0); + if (predicate.Invoke(item1)) + sum1 = Scalar.Add(selector.Invoke(item1), sum1); + } + if (source.Length.IsOdd()) { + var item = source[source.Length - 1]; if (predicate.Invoke(item)) - sum = GenericsOperator.AddNullable(selector.Invoke(item), sum); + sum0 = Scalar.Add(selector.Invoke(item), sum0); } - return sum; + return Scalar.Add(sum0, sum1); } } } diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs index 8f1326fce..1cc64d0c4 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs @@ -13,7 +13,7 @@ internal static TSum Sum(this TEnumerab var sum = default(TSum); using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) - sum = GenericsOperator.AddNullable(enumerator.Current, sum); + sum = Scalar.Add(enumerator.Current, sum); return sum; } @@ -29,8 +29,7 @@ internal static TSum Sum(th while (enumerator.MoveNext()) { var item = enumerator.Current; - if (predicate.Invoke(item)) - sum = GenericsOperator.AddNullable(item, sum); + sum = Scalar.Add(Scalar.GetValueOrDefault(predicate, item), sum); } return sum; } @@ -47,8 +46,7 @@ internal static TSum SumAt( for (var index = 0; enumerator.MoveNext(); index++) { var item = enumerator.Current; - if (predicate.Invoke(item, index)) - sum = GenericsOperator.AddNullable(item, sum); + sum = Scalar.Add(Scalar.GetValueOrDefault(predicate, item, index), sum); } return sum; } @@ -65,7 +63,7 @@ internal static TSum Sum SumAsync SumAsync SumAtAsync SumAsync SumAtAsync SumAsync SumAsync(this AsyncValueEnumerable source, Can public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, int?, int>(cancellationToken); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, nint, nint>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, nint?, nint>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, nuint, nuint>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, nuint?, nuint>(cancellationToken); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) => source.SumAsync, AsyncValueEnumerable.AsyncEnumerator, long, long>(cancellationToken); diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs index c3c15f577..09046a183 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs @@ -54,6 +54,26 @@ public static ValueTask SumAsync(this AsyncValueEnumerable => source.SumAsync, TEnumerator, int?, int>(cancellationToken); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, nint, nint>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, nint?, nint>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, nuint, nuint>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, TEnumerator, nuint?, nuint>(cancellationToken); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs index 71aab5bad..c4ae76d5d 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs @@ -98,6 +98,42 @@ public static ValueTask SumAsync => source.SumAsync, TEnumerator, int?, int>(cancellationToken); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, nint, nint>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, nint?, nint>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, nuint, nuint>(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.SumAsync, TEnumerator, nuint?, nuint>(cancellationToken); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs index 9dc82a023..7fc40740b 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs @@ -99,6 +99,42 @@ public static ValueTask SumAsync => source.source.SumAsync(cancellationToken); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.source.SumAsync(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.source.SumAsync(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.source.SumAsync(cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TEnumerator2 : struct + where TGetAsyncEnumerator : struct, IFunction + where TGetAsyncEnumerator2 : struct, IFunction + => source.source.SumAsync(cancellationToken); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this AsyncValueEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs index c82f69c6e..2065bd521 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs @@ -50,6 +50,22 @@ public static int Sum(this ValueEnumerable source) public static int Sum(this ValueEnumerable source) => source.Sum, ValueEnumerator, int?, int>(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + => source.Sum, ValueEnumerator, nuint?, nuint>(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) => source.Sum, ValueEnumerator, long, long>(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index 98b5f8875..7736e74af 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -118,6 +118,22 @@ public static int Sum(this ValueEnumerable source) public static int Sum(this ValueEnumerable source) => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int?, int>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint?, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint, nuint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint?, nuint>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long, long>(source); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs index fdcb0db47..de7c52ad1 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs @@ -192,6 +192,26 @@ public static int Sum(this ValueEnumerable source) where TList : IReadOnlyList => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int?, int>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint?, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint, nuint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TList : IReadOnlyList + => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint?, nuint>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TList : IReadOnlyList diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs index 95a858484..20977d65b 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs @@ -57,6 +57,26 @@ public static int Sum(this ValueEnumerable sourc where TEnumerator : struct, IEnumerator => source.Sum, TEnumerator, int?, int>(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => source.Sum, TEnumerator, nuint?, nuint>(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index 9db9a65ed..a12501405 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -110,6 +110,26 @@ public static int Sum(this ValueEnumerable sourc where TEnumerator : struct, IEnumerator => Sum, TEnumerator, int?, int>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, nint, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, nint?, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, nuint, nuint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerator : struct, IEnumerator + => Sum, TEnumerator, nuint?, nuint>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs index 6d0e27e72..c13c74c9e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -98,6 +98,42 @@ public static int Sum => source.Sum, TEnumerator, int?, int>(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Sum, TEnumerator, nuint?, nuint>(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TEnumerable : IEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index 831644a20..39842ec76 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -157,6 +157,42 @@ public static int Sum => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int?, int>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint?, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint, nuint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint?, nuint>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TEnumerable : IReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs index 599754b5a..263dc8353 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs @@ -101,6 +101,42 @@ public static int Sum => source.source.Sum(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.source.Sum(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index 382f539f7..318390ddc 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -166,6 +166,42 @@ public static int Sum => Sum, TEnumerator, int?, int>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, nint, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, nint?, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, nuint, nuint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => Sum, TEnumerator, nuint?, nuint>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs index 61f92a2ff..bbbf73dbe 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs @@ -234,6 +234,42 @@ public static int Sum => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int?, int>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint?, nint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint, nuint>(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ValueEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint?, nuint>(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ValueEnumerable source) where TEnumerable : IValueReadOnlyList diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index e619cecb2..b8cf7a1d6 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -332,15 +332,31 @@ public static int Count(this ArraySegmentValueEnumerable sourc [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentValueEnumerable source) => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentValueEnumerable source) + => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentValueEnumerable source) + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentValueEnumerable source) + => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentValueEnumerable source) + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentValueEnumerable source) @@ -348,7 +364,7 @@ public static long Sum(this ArraySegmentValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentValueEnumerable source) @@ -356,7 +372,7 @@ public static float Sum(this ArraySegmentValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentValueEnumerable source) @@ -364,11 +380,11 @@ public static double Sum(this ArraySegmentValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => ((ReadOnlySpan)source.source.AsSpan()).Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool ContainsVector(this ArraySegmentValueEnumerable source, TSource value) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index e1a420e74..f64176e29 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -246,15 +246,31 @@ public static int Count(this MemoryValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemoryValueEnumerable source) => source.source.Span.Sum(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryValueEnumerable source) + => source.source.Span.SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryValueEnumerable source) + => source.source.Span.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryValueEnumerable source) + => source.source.Span.SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryValueEnumerable source) + => source.source.Span.Sum(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemoryValueEnumerable source) @@ -262,7 +278,7 @@ public static long Sum(this MemoryValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this MemoryValueEnumerable source) @@ -270,7 +286,7 @@ public static float Sum(this MemoryValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this MemoryValueEnumerable source) @@ -278,7 +294,7 @@ public static double Sum(this MemoryValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this MemoryValueEnumerable source) - => source.source.Span.Sum(); + => source.source.Span.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this MemoryValueEnumerable source) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index cde9e5fcb..26ca1d40b 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -173,15 +173,31 @@ public static int Count(this SpanValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SpanValueEnumerable source) - => source.source.Sum(); + => source.source.SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SpanValueEnumerable source) => source.source.Sum(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanValueEnumerable source) + => source.source.SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanValueEnumerable source) + => source.source.Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanValueEnumerable source) + => source.source.SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanValueEnumerable source) + => source.source.Sum(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SpanValueEnumerable source) - => source.source.Sum(); + => source.source.SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SpanValueEnumerable source) @@ -189,7 +205,7 @@ public static long Sum(this SpanValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this SpanValueEnumerable source) - => source.source.Sum(); + => source.source.SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this SpanValueEnumerable source) @@ -197,7 +213,7 @@ public static float Sum(this SpanValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this SpanValueEnumerable source) - => source.source.Sum(); + => source.source.SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this SpanValueEnumerable source) @@ -205,7 +221,7 @@ public static double Sum(this SpanValueEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this SpanValueEnumerable source) - => source.source.Sum(); + => source.source.Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this SpanValueEnumerable source) diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index 3e5c79cea..f2f5e0132 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -245,6 +245,26 @@ public static int Sum(this ArraySegmentWhereEnumerable => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentWhereEnumerable source) + where TPredicate : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentWhereEnumerable source) + where TPredicate : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentWhereEnumerable source) + where TPredicate : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentWhereEnumerable source) + where TPredicate : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index 03f044881..0f855762e 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -355,6 +355,34 @@ public static ValueTask SumAsync(this where TPredicate : struct, IAsyncFunction => source.source.SumAsync(cancellationToken, source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index 0601701c9..45be02d7c 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -237,6 +237,26 @@ public static int Sum(this MemoryWhereEnumerable s where TPredicate : struct, IFunction => source.source.Span.Sum(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryWhereEnumerable source) + where TPredicate : struct, IFunction + => source.source.Span.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryWhereEnumerable source) + where TPredicate : struct, IFunction + => source.source.Span.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryWhereEnumerable source) + where TPredicate : struct, IFunction + => source.source.Span.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryWhereEnumerable source) + where TPredicate : struct, IFunction + => source.source.Span.Sum(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemoryWhereEnumerable source) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index 9bffafc63..b8b23a9b5 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -202,6 +202,26 @@ public static int Sum(this SpanWhereEnumerable sou where TPredicate : struct, IFunction => source.source.Sum(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanWhereEnumerable source) + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanWhereEnumerable source) + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanWhereEnumerable source) + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanWhereEnumerable source) + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SpanWhereEnumerable source) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index 659422f39..50da765f8 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -260,6 +260,34 @@ public static int Sum(this WhereEnumerable where TPredicate : struct, IFunction => source.source.Sum(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.Sum(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this WhereEnumerable source) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index 5bab7b510..6b83db793 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -253,6 +253,34 @@ public static int Sum(this WhereEnumerable where TPredicate : struct, IFunction => Sum(source.source, source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => Sum(source.source, source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this WhereEnumerable source) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index 67371a77d..186e26a51 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -243,6 +243,26 @@ public static int Sum(this ArraySegmentWhereAtEnumerable => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentWhereAtEnumerable source) + where TPredicate : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentWhereAtEnumerable source) + where TPredicate : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentWhereAtEnumerable source) + where TPredicate : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentWhereAtEnumerable source) + where TPredicate : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index bb5bc9fba..ff3144ae8 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -348,6 +348,34 @@ public static ValueTask SumAsync(this where TPredicate : struct, IAsyncFunction => source.source.SumAtAsync(cancellationToken, source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(cancellationToken, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(cancellationToken, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(cancellationToken, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + => source.source.SumAtAsync(cancellationToken, source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index ee604e9aa..74dbf06ae 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -228,6 +228,26 @@ public static int Sum(this MemoryWhereAtEnumerable where TPredicate : struct, IFunction => source.source.Span.SumAt(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryWhereAtEnumerable source) + where TPredicate : struct, IFunction + => source.source.Span.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryWhereAtEnumerable source) + where TPredicate : struct, IFunction + => source.source.Span.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryWhereAtEnumerable source) + where TPredicate : struct, IFunction + => source.source.Span.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryWhereAtEnumerable source) + where TPredicate : struct, IFunction + => source.source.Span.SumAt(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemoryWhereAtEnumerable source) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index 3a4d811d3..df207310d 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -193,6 +193,26 @@ public static int Sum(this SpanWhereAtEnumerable s where TPredicate : struct, IFunction => source.source.SumAt(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanWhereAtEnumerable source) + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanWhereAtEnumerable source) + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanWhereAtEnumerable source) + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanWhereAtEnumerable source) + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SpanWhereAtEnumerable source) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index 7191605a4..60ada4189 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -250,6 +250,34 @@ public static int Sum(this WhereAtEnumerab where TPredicate : struct, IFunction => source.source.SumAt(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.source.SumAt(source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this WhereAtEnumerable source) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index d42a6acea..ba4218dd3 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -249,6 +249,34 @@ public static int Sum(this WhereAtEnumerab where TPredicate : struct, IFunction => SumAt(source.source, source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => SumAt(source.source, source.predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this WhereAtEnumerable source) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index ccfefcde7..5184f6e12 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -260,6 +260,30 @@ public static int Sum(this ArraySegmentWhereSele where TSelector : struct, IFunction => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index 568cfc4fc..7b1bb5e90 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -385,6 +385,38 @@ public static ValueTask SumAsync => source.source.SumAsync(cancellationToken, source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TPredicate : struct, IAsyncFunction + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this WhereSelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index b502b0bbe..bb5bb3a8c 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -264,6 +264,30 @@ public static int Sum(this MemoryWhereSelectEnum where TSelector : struct, IFunction => source.source.Span.Sum(source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Span.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Span.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Span.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Span.Sum(source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemoryWhereSelectEnumerable source) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index d2e03ac7a..fb8c37b8b 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -161,6 +161,30 @@ public static int Sum(this SpanWhereSelectEnumer where TSelector : struct, IFunction => source.source.Sum(source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanWhereSelectEnumerable source) + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SpanWhereSelectEnumerable source) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index f87b3e290..d69f3ff4e 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -272,6 +272,38 @@ public static int Sum( where TSelector : struct, IFunction => source.source.Sum(source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => source.source.Sum(source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this WhereSelectEnumerable source) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index a8814ffaa..318b52d53 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -272,6 +272,38 @@ public static int Sum( where TSelector : struct, IFunction => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this WhereSelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.predicate, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this WhereSelectEnumerable source) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 266db4240..655bf27e2 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -236,6 +236,26 @@ public static int Sum(this ArraySegmentSelectEnumerable => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentSelectEnumerable source) + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentSelectEnumerable source) + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentSelectEnumerable source) + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentSelectEnumerable source) + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs index 0b8e2a7f1..9aa0e00b4 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -279,6 +279,34 @@ public static ValueTask SumAsync => source.source.SumAsync(cancellationToken, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAsync(cancellationToken, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index 56f92f6b6..95e841f29 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -228,6 +228,26 @@ public static int Sum(this MemorySelectEnumerable => source.source.Span.Sum(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemorySelectEnumerable source) + where TSelector : struct, IFunction + => source.source.Span.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemorySelectEnumerable source) + where TSelector : struct, IFunction + => source.source.Span.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemorySelectEnumerable source) + where TSelector : struct, IFunction + => source.source.Span.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemorySelectEnumerable source) + where TSelector : struct, IFunction + => source.source.Span.Sum(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemorySelectEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index 6d25c8e1e..3c6ccb3b8 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -137,6 +137,26 @@ public static int Count(this SpanSelectEnumerable => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanSelectEnumerable source) + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanSelectEnumerable source) + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanSelectEnumerable source) + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanSelectEnumerable source) + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SpanSelectEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index 27e973436..e365a3491 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -181,6 +181,34 @@ public static int Sum(this SelectE where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SelectEnumerable source) diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index 3dfaf18be..c2473c354 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -224,6 +224,34 @@ public static int Sum(this SelectE where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SelectEnumerable source) diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs index 15cb40d8b..91bea70bd 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -251,6 +251,34 @@ public static int Sum(this SelectE where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SelectEnumerable source) diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 92417e00e..d488425ea 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -227,6 +227,26 @@ public static int Sum(this ArraySegmentSelectAtEnumerable => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentSelectAtEnumerable source) + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentSelectAtEnumerable source) + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentSelectAtEnumerable source) + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentSelectAtEnumerable source) + where TSelector : struct, IFunction + => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentSelectAtEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index cbb420165..8fc4865f0 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -281,6 +281,34 @@ public static ValueTask SumAsync => source.source.SumAtAsync(cancellationToken, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(cancellationToken, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(cancellationToken, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(cancellationToken, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + where TSelector : struct, IAsyncFunction + => source.source.SumAtAsync(cancellationToken, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this SelectAtEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index d1e548eb1..5dec3455d 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -219,6 +219,26 @@ public static int Sum(this MemorySelectAtEnumerable => source.source.Span.SumAt(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemorySelectAtEnumerable source) + where TSelector : struct, IFunction + => source.source.Span.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemorySelectAtEnumerable source) + where TSelector : struct, IFunction + => source.source.Span.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemorySelectAtEnumerable source) + where TSelector : struct, IFunction + => source.source.Span.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemorySelectAtEnumerable source) + where TSelector : struct, IFunction + => source.source.Span.SumAt(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemorySelectAtEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index 0e1cd403a..d5b98bbfc 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -147,6 +147,26 @@ public static int Sum(this SpanSelectAtEnumerable => source.source.SumAt(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanSelectAtEnumerable source) + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanSelectAtEnumerable source) + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanSelectAtEnumerable source) + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SpanSelectAtEnumerable source) + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SpanSelectAtEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index 281494cd6..924116c48 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -191,6 +191,34 @@ public static int Sum(this SelectA where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectAtEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.source.SumAt(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SelectAtEnumerable source) diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index e30d01fa7..8d08ef0f1 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -233,6 +233,34 @@ public static int Sum(this SelectA where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectAtEnumerable source) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SelectAtEnumerable source) diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs index 573377393..4d8118e45 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -266,6 +266,34 @@ public static int Sum(this SelectA where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectAtEnumerable source) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.SumAt(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SelectAtEnumerable source) diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs index afcfec9e1..5ed43848c 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs @@ -109,6 +109,18 @@ public static int Sum(this RangeSelectVectorContext< where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction => SumRange(source.start, source.count, source.vectorSelector, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this RangeSelectVectorContext source) + where TVectorSelector : struct, IFunction, Vector> + where TSelector : struct, IFunction + => SumRange(source.start, source.count, source.vectorSelector, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this RangeSelectVectorContext source) + where TVectorSelector : struct, IFunction, Vector> + where TSelector : struct, IFunction + => SumRange(source.start, source.count, source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this RangeSelectVectorContext source) diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs index 62b2588d1..b91d2354f 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs @@ -102,36 +102,42 @@ public static int Sum(this SpanSelectVector where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct - => source.source.Sum(source.vectorSelector, source.selector); + => source.source.SumVector(source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SpanSelectVectorContext source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct - => source.source.Sum(source.vectorSelector, source.selector); + => source.source.SumVector(source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this SpanSelectVectorContext source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct - => source.source.Sum(source.vectorSelector, source.selector); + => source.source.SumVector(source.vectorSelector, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this SpanSelectVectorContext source) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct - => source.source.Sum(source.vectorSelector, source.selector); - + => source.source.SumVector(source.vectorSelector, source.selector); + [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this SpanSelectVectorContext source) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction + public static nuint Sum(this SpanSelectVectorContext source) + where TVectorSelector : struct, IFunction, Vector> + where TSelector : struct, IFunction where TSource : struct - => source.source.Sum(source.vectorSelector, source.selector); - + => source.source.SumVector(source.vectorSelector, source.selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SpanSelectVectorContext source) + where TVectorSelector : struct, IFunction, Vector> + where TSelector : struct, IFunction + where TSource : struct + => source.source.SumVector(source.vectorSelector, source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs index cfbad322f..7f5fb7f77 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs @@ -242,6 +242,34 @@ public static int Sum(this A where TSubEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentSelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, ArraySegmentSelectManyEnumerable.Enumerator, nuint?, nuint>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentSelectManyEnumerable source) diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs index 85a6191c7..66ca00a41 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs @@ -241,6 +241,34 @@ public static int Sum(this M where TSubEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.Sum, MemorySelectManyEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemorySelectManyEnumerable source) + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, MemorySelectManyEnumerable.Enumerator, nuint?, nuint>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemorySelectManyEnumerable source) diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs index 9d304d6ef..5f8b2af3e 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs @@ -248,6 +248,42 @@ public static int Sum where TSelector : struct, IFunction => source.Sum, SelectManyEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this SelectManyEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => source.Sum, SelectManyEnumerable.Enumerator, nuint?, nuint>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SelectManyEnumerable source) diff --git a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs index 60ef67bd2..516503ef2 100644 --- a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs @@ -28,7 +28,7 @@ static bool ContainsVector(this ReadOnlySpan source, TSource v } foreach (var item in source) { - if (GenericsOperator.Equals(item, value)) + if (Scalar.Equals(item, value)) return true; } return false; @@ -60,7 +60,7 @@ static bool ContainsVector(this Re } foreach (var item in source) { - if (GenericsOperator.Equals(selector.Invoke(item), value)) + if (Scalar.Equals(selector.Invoke(item), value)) return true; } return false; diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs index 826da2014..2c963c386 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs @@ -152,6 +152,22 @@ public static int Sum(this ArraySegmentDistinctEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentDistinctEnumerable source) => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentDistinctEnumerable source) + => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, nuint?, nuint>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentDistinctEnumerable source) diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs index d31f4aa05..f5f339021 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs @@ -240,6 +240,30 @@ public static ValueTask SumAsync(this DistinctEnu where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator => source.SumAsync, DistinctEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask SumAsync(this DistinctEnumerable source) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.SumAsync, DistinctEnumerable.Enumerator, nuint?, nuint>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueTask SumAsync(this DistinctEnumerable source) diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs index 75edcc4e8..bd737e17b 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -154,6 +154,22 @@ public static int Sum(this MemoryDistinctEnumerable source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemoryDistinctEnumerable source) => source.Sum, MemoryDistinctEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this MemoryDistinctEnumerable source) + => source.Sum, MemoryDistinctEnumerable.Enumerator, nuint?, nuint>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this MemoryDistinctEnumerable source) diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs index 98112f194..53308869b 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs @@ -134,6 +134,30 @@ public static int Sum(this DistinctEnumerable where TEnumerator : struct, IEnumerator => source.Sum, DistinctEnumerable.Enumerator, int?, int>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, nint, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, nint?, nint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, nuint, nuint>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this DistinctEnumerable source) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Sum, DistinctEnumerable.Enumerator, nuint?, nuint>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this DistinctEnumerable source) diff --git a/NetFabric.Hyperlinq/Utils/GenericsOperator.cs b/NetFabric.Hyperlinq/Utils/GenericsOperator.cs deleted file mode 100644 index 8821a3670..000000000 --- a/NetFabric.Hyperlinq/Utils/GenericsOperator.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - static class GenericsOperator - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TValue Add(TValue a, TValue b) - where TValue : struct - { - if (typeof(TValue) == typeof(byte)) - return (TValue)(object)((byte)(object)a + (byte)(object)b); - - if (typeof(TValue) == typeof(sbyte)) - return (TValue)(object)((sbyte)(object)a + (sbyte)(object)b); - - if (typeof(TValue) == typeof(ushort)) - return (TValue)(object)((ushort)(object)a + (ushort)(object)b); - - if (typeof(TValue) == typeof(short)) - return (TValue)(object)((short)(object)a + (short)(object)b); - - if (typeof(TValue) == typeof(uint)) - return (TValue)(object)((uint)(object)a + (uint)(object)b); - - if (typeof(TValue) == typeof(int)) - return (TValue)(object)((int)(object)a + (int)(object)b); - - if (typeof(TValue) == typeof(ulong)) - return (TValue)(object)((ulong)(object)a + (ulong)(object)b); - - if (typeof(TValue) == typeof(long)) - return (TValue)(object)((long)(object)a + (long)(object)b); - - if (typeof(TValue) == typeof(float)) - return (TValue)(object)((float)(object)a + (float)(object)b); - - if (typeof(TValue) == typeof(double)) - return (TValue)(object)((double)(object)a + (double)(object)b); - - return Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TValue AddNullable(TNullableValue a, TValue b) - where TValue : struct - { -#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. - - if (typeof(TNullableValue) == typeof(int?) && typeof(TValue) == typeof(int)) - return (TValue)(object)(((int?)(object)a).GetValueOrDefault() + (int)(object)b); - - if (typeof(TNullableValue) == typeof(int) && typeof(TValue) == typeof(int)) - return (TValue)(object)((int)(object)a! + (int)(object)b); - - if (typeof(TNullableValue) == typeof(long?) && typeof(TValue) == typeof(long)) - return (TValue)(object)(((long?)(object)a).GetValueOrDefault() + (long)(object)b); - - if (typeof(TNullableValue) == typeof(long) && typeof(TValue) == typeof(long)) - return (TValue)(object)((long)(object)a! + (long)(object)b); - - if (typeof(TNullableValue) == typeof(float?) && typeof(TValue) == typeof(float)) - return (TValue)(object)(((float?)(object)a).GetValueOrDefault() + (float)(object)b); - - if (typeof(TNullableValue) == typeof(float) && typeof(TValue) == typeof(float)) - return (TValue)(object)((float)(object)a! + (float)(object)b); - - if (typeof(TNullableValue) == typeof(double?) && typeof(TValue) == typeof(double)) - return (TValue)(object)(((double?)(object)a).GetValueOrDefault() + (double)(object)b); - - if (typeof(TNullableValue) == typeof(double) && typeof(TValue) == typeof(double)) - return (TValue)(object)((double)(object)a! + (double)(object)b); - - if (typeof(TNullableValue) == typeof(decimal?) && typeof(TValue) == typeof(decimal)) - return (TValue)(object)(((decimal?)(object)a).GetValueOrDefault() + (decimal)(object)b); - - if (typeof(TNullableValue) == typeof(decimal) && typeof(TValue) == typeof(decimal)) - return (TValue)(object)((decimal)(object)a! + (decimal)(object)b); - -#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. - - return Throw.NotSupportedException(); - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Equals(TValue a, TValue b) - where TValue : struct - { - if (typeof(TValue) == typeof(byte)) - return (byte)(object)a == (byte)(object)b; - - if (typeof(TValue) == typeof(sbyte)) - return (sbyte)(object)a == (sbyte)(object)b; - - if (typeof(TValue) == typeof(ushort)) - return (ushort)(object)a == (ushort)(object)b; - - if (typeof(TValue) == typeof(short)) - return (short)(object)a == (short)(object)b; - - if (typeof(TValue) == typeof(uint)) - return (uint)(object)a == (uint)(object)b; - - if (typeof(TValue) == typeof(int)) - return (int)(object)a == (int)(object)b; - - if (typeof(TValue) == typeof(ulong)) - return (ulong)(object)a == (ulong)(object)b; - - if (typeof(TValue) == typeof(long)) - return (long)(object)a == (long)(object)b; - - if (typeof(TValue) == typeof(float)) - return (float)(object)a == (float)(object)b; - - if (typeof(TValue) == typeof(double)) - return (double)(object)a == (double)(object)b; - - return Throw.NotSupportedException(); - } - } -} diff --git a/NetFabric.Hyperlinq/Utils/IntExtensions.cs b/NetFabric.Hyperlinq/Utils/IntExtensions.cs new file mode 100644 index 000000000..baf066cd6 --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/IntExtensions.cs @@ -0,0 +1,15 @@ +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class IntExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsEven(this int value) + => (value & 1) is 0; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsOdd(this int value) + => (value & 1) is not 0; + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Utils/Scalar.cs b/NetFabric.Hyperlinq/Utils/Scalar.cs new file mode 100644 index 000000000..c77244f9e --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/Scalar.cs @@ -0,0 +1,227 @@ +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class Scalar + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static TValue Add(TNullableValue a, TValue b) + where TValue : struct + { + if (typeof(TNullableValue) == typeof(int?) && typeof(TValue) == typeof(int)) + return (TValue)(object)(((int?)(object?)a).GetValueOrDefault() + (int)(object)b); + + if (typeof(TNullableValue) == typeof(int) && typeof(TValue) == typeof(int)) + return (TValue)(object)((int)(object)a! + (int)(object)b); + + if (typeof(TNullableValue) == typeof(uint?) && typeof(TValue) == typeof(uint)) + return (TValue)(object)(((uint?)(object?)a).GetValueOrDefault() + (uint)(object)b); + + if (typeof(TNullableValue) == typeof(uint) && typeof(TValue) == typeof(uint)) + return (TValue)(object)((uint)(object)a! + (uint)(object)b); + + if (typeof(TNullableValue) == typeof(nint?) && typeof(TValue) == typeof(nint)) + return (TValue)(object)(((nint?)(object?)a).GetValueOrDefault() + (nint)(object)b); + + if (typeof(TNullableValue) == typeof(nint) && typeof(TValue) == typeof(nint)) + return (TValue)(object)((nint)(object)a! + (nint)(object)b); + + if (typeof(TNullableValue) == typeof(nuint?) && typeof(TValue) == typeof(nuint)) + return (TValue)(object)(((nuint?)(object?)a).GetValueOrDefault() + (nuint)(object)b); + + if (typeof(TNullableValue) == typeof(nuint) && typeof(TValue) == typeof(nuint)) + return (TValue)(object)((nuint)(object)a! + (nuint)(object)b); + + if (typeof(TNullableValue) == typeof(long?) && typeof(TValue) == typeof(long)) + return (TValue)(object)(((long?)(object?)a).GetValueOrDefault() + (long)(object)b); + + if (typeof(TNullableValue) == typeof(long) && typeof(TValue) == typeof(long)) + return (TValue)(object)((long)(object)a! + (long)(object)b); + + if (typeof(TNullableValue) == typeof(float?) && typeof(TValue) == typeof(float)) + return (TValue)(object)(((float?)(object?)a).GetValueOrDefault() + (float)(object)b); + + if (typeof(TNullableValue) == typeof(float) && typeof(TValue) == typeof(float)) + return (TValue)(object)((float)(object)a! + (float)(object)b); + + if (typeof(TNullableValue) == typeof(double?) && typeof(TValue) == typeof(double)) + return (TValue)(object)(((double?)(object?)a).GetValueOrDefault() + (double)(object)b); + + if (typeof(TNullableValue) == typeof(double) && typeof(TValue) == typeof(double)) + return (TValue)(object)((double)(object)a! + (double)(object)b); + + if (typeof(TNullableValue) == typeof(decimal?) && typeof(TValue) == typeof(decimal)) + return (TValue)(object)(((decimal?)(object?)a).GetValueOrDefault() + (decimal)(object)b); + + if (typeof(TNullableValue) == typeof(decimal) && typeof(TValue) == typeof(decimal)) + return (TValue)(object)((decimal)(object)a! + (decimal)(object)b); + + return Throw.NotSupportedException(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool Equals(TValue a, TValue b) + where TValue : struct + { + if (typeof(TValue) == typeof(byte)) + return (byte)(object)a == (byte)(object)b; + + if (typeof(TValue) == typeof(sbyte)) + return (sbyte)(object)a == (sbyte)(object)b; + + if (typeof(TValue) == typeof(short)) + return (short)(object)a == (short)(object)b; + + if (typeof(TValue) == typeof(ushort)) + return (ushort)(object)a == (ushort)(object)b; + + if (typeof(TValue) == typeof(int)) + return (int)(object)a == (int)(object)b; + + if (typeof(TValue) == typeof(uint)) + return (uint)(object)a == (uint)(object)b; + + if (typeof(TValue) == typeof(long)) + return (long)(object)a == (long)(object)b; + + if (typeof(TValue) == typeof(ulong)) + return (ulong)(object)a == (ulong)(object)b; + + if (typeof(TValue) == typeof(float)) + // ReSharper disable once CompareOfFloatsByEqualityOperator + return (float)(object)a == (float)(object)b; + + if (typeof(TValue) == typeof(double)) + // ReSharper disable once CompareOfFloatsByEqualityOperator + return (double)(object)a == (double)(object)b; + + if (typeof(TValue) == typeof(decimal)) + return (decimal)(object)a == (decimal)(object)b; + + return Throw.NotSupportedException(); + } + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static TValue GetValueOrDefault(TPredicate predicate, TValue value) + where TPredicate : struct, IFunction + { + if (typeof(TValue) == typeof(int?)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * ((int?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(int)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * (int)(object)value!); + + if (typeof(TValue) == typeof(uint?)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * ((uint?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(uint)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * (uint)(object)value!); + + if (typeof(TValue) == typeof(nint?)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * ((nint?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(nint)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * (nint)(object)value!); + + if (typeof(TValue) == typeof(nuint?)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * ((nuint?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(nuint)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * (nuint)(object)value!); + + if (typeof(TValue) == typeof(long?)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * ((long?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(long)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * (long)(object)value!); + + if (typeof(TValue) == typeof(ulong?)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * ((ulong?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(ulong)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * (ulong)(object)value!); + + if (typeof(TValue) == typeof(float?)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * ((float?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(float)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * (float)(object)value!); + + if (typeof(TValue) == typeof(double?)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * ((double?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(double)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * (double)(object)value!); + + if (typeof(TValue) == typeof(decimal?)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * ((decimal?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(decimal)) + return (TValue)(object)(predicate.Invoke(value).AsByte() * (decimal)(object)value!); + + return Throw.NotSupportedException(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static TValue GetValueOrDefault(TPredicate predicate, TValue value, int index) + where TPredicate : struct, IFunction + { + if (typeof(TValue) == typeof(int?)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * ((int?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(int)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * (int)(object)value!); + + if (typeof(TValue) == typeof(uint?)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * ((uint?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(uint)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * (uint)(object)value!); + + if (typeof(TValue) == typeof(nint?)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * ((nint?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(nint)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * (nint)(object)value!); + + if (typeof(TValue) == typeof(nuint?)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * ((nuint?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(nuint)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * (nuint)(object)value!); + + if (typeof(TValue) == typeof(long?)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * ((long?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(long)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * (long)(object)value!); + + if (typeof(TValue) == typeof(ulong?)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * ((ulong?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(ulong)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * (ulong)(object)value!); + + if (typeof(TValue) == typeof(float?)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * ((float?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(float)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * (float)(object)value!); + + if (typeof(TValue) == typeof(double?)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * ((double?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(double)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * (double)(object)value!); + + if (typeof(TValue) == typeof(decimal?)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * ((decimal?)(object?)value).GetValueOrDefault()); + + if (typeof(TValue) == typeof(decimal)) + return (TValue)(object)(predicate.Invoke(value, index).AsByte() * (decimal)(object)value!); + + return Throw.NotSupportedException(); + } + } +} diff --git a/NetFabric.Hyperlinq/Utils/VectorExtensions.cs b/NetFabric.Hyperlinq/Utils/VectorExtensions.cs new file mode 100644 index 000000000..bbbff542a --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/VectorExtensions.cs @@ -0,0 +1,18 @@ +using System.Numerics; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class VectorExtensions + { + public static T Sum(this Vector vector) + where T : struct + { + ref var item = ref Unsafe.As, T>(ref Unsafe.AsRef(in vector)); + var sum = default(T); + for (var index = 0; index < Vector.Count; index++) + sum = Scalar.Add(Unsafe.Add(ref item, index), sum); + return sum; + } + } +} \ No newline at end of file From 2a8f9618e4c55b3312d842b0bef99a4789f6f402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Thu, 1 Jul 2021 23:00:29 +0100 Subject: [PATCH 44/61] Add Count(predicate) (#363) --- Directory.Build.props | 2 +- .../NetFabric.Hyperlinq.Abstractions.csproj | 6 +- .../NetFabric.Hyperlinq.Benchmarks.csproj | 4 +- .../NetFabric.Hyperlinq.Immutable.csproj | 4 +- ...Hyperlinq.SourceGenerator.UnitTests.csproj | 2 +- ...NetFabric.Hyperlinq.SourceGenerator.csproj | 2 +- .../OverloadsGenerator.cs | 5 +- .../Immutable/ImmutableArray.Tests.cs | 2 +- .../NetFabric.Hyperlinq.UnitTests.csproj | 4 +- .../Aggregation/Count/Count.ReadOnlySpan.cs | 14 ++-- .../Count/Count.ValueEnumerable.cs | 22 +++++-- .../Count/Count.ValueReadOnlyCollection.cs | 20 ++++-- .../Count/CountAsync.AsyncValueEnumerable.cs | 22 +++++-- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 18 +++++ .../AsValueEnumerable'1.ReadOnlyList.cs | 22 +++++++ ...lueEnumerable'1.ValueReadOnlyCollection.cs | 22 +++++++ .../AsValueEnumerable'6.ReadOnlyCollection.cs | 40 ++++++++++++ ...lueEnumerable'6.ValueReadOnlyCollection.cs | 40 ++++++++++++ .../AsValueEnumerable'6.ValueReadOnlyList.cs | 47 ++++++++++++-- .../AsValueEnumerable.ArraySegment.cs | 18 +++++ .../AsValueEnumerable.ReadOnlyMemory.cs | 20 +++++- .../AsValueEnumerable.ReadOnlySpan.cs | 20 +++++- .../Where/Where/Where.ArraySegment.cs | 28 ++++++-- .../Where/Where/Where.AsyncValueEnumerable.cs | 35 ++++++++-- .../Where/Where/Where.ReadOnlyMemory.cs | 29 +++++++-- .../Where/Where/Where.ReadOnlySpan.cs | 29 +++++++-- .../Where/Where/Where.ValueEnumerable.cs | 31 +++++++-- .../Where/Where.ValueReadOnlyCollection.cs | 31 +++++++-- .../Where/WhereAt/WhereAt.ArraySegment.cs | 28 ++++++-- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 27 +++++++- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 26 ++++++-- .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 26 ++++++-- .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 31 +++++++-- .../WhereAt.ValueReadOnlyCollection.cs | 31 +++++++-- .../WhereSelect/WhereSelect.ArraySegment.cs | 37 +++++++++-- .../WhereSelect.AsyncValueEnumerable.cs | 27 +++++++- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 28 ++++++-- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 18 +++++ .../WhereSelect.ValueEnumerable.cs | 31 +++++++-- .../WhereSelect.ValueReadOnlyCollection.cs | 31 +++++++-- .../WhereSelect/WhereSelectEnumerator.cs | 2 + .../NetFabric.Hyperlinq.csproj | 8 ++- NetFabric.Hyperlinq/Option/Option.cs | 7 +- .../Skip/Skip.AsyncValueEnumerable.cs | 7 +- .../Partitioning/Skip/Skip.ValueEnumerable.cs | 5 +- .../SkipTake/SkipTake.AsyncValueEnumerable.cs | 7 +- .../SkipTake/SkipTake.ReadOnlyList.cs | 22 +++++++ .../SkipTake/SkipTake.ValueEnumerable.cs | 5 +- .../SkipTake.ValueReadOnlyCollection.cs | 31 ++++++++- .../Take/Take.AsyncValueEnumerable.cs | 7 +- .../Partitioning/Take/Take.ValueEnumerable.cs | 5 +- .../Select/Select/Select.ArraySegment.cs | 24 +++++++ .../Select/Select.AsyncValueEnumerable.cs | 7 +- .../Select/Select/Select.ReadOnlyMemory.cs | 24 +++++++ .../Select/Select/Select.ReadOnlySpan.cs | 22 +++++++ .../Select/Select/Select.ValueEnumerable.cs | 5 +- .../Select/Select.ValueReadOnlyCollection.cs | 65 ++++++++++++++----- .../Select/Select/Select.ValueReadOnlyList.cs | 40 ++++++++++-- .../Select/SelectAt/SelectAt.ArraySegment.cs | 24 +++++++ .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 7 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 41 +++++++++--- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 22 +++++++ .../SelectAt/SelectAt.ValueEnumerable.cs | 5 +- .../SelectAt.ValueReadOnlyCollection.cs | 37 ++++++++++- .../SelectAt/SelectAt.ValueReadOnlyList.cs | 37 ++++++++++- .../SelectMany/SelectMany.ArraySegment.cs | 5 +- .../SelectMany/SelectMany.ReadOnlyMemory.cs | 5 +- .../SelectMany/SelectMany.ReadOnlySpan.cs | 5 +- .../SelectMany/SelectMany.ValueEnumerable.cs | 8 +-- .../Distinct/Distinct.AsyncValueEnumerable.cs | 7 +- .../Set/Distinct/Distinct.ValueEnumerable.cs | 5 +- .../AsyncPredicateCombination.cs | 12 +++- .../AsyncSelectorCombination.cs | 16 +++-- .../PredicateCombination.cs | 12 +++- .../PredicateInCombination.cs | 12 +++- .../SelectorCombination.cs | 16 +++-- NetFabric.Hyperlinq/Utils/Throw.cs | 20 ++++++ 77 files changed, 1252 insertions(+), 217 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3d49125fa..ce2d72bbe 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ Antao Almada Copyright 2019-2021 Antao Almada - 9.0 + latest strict enable diff --git a/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj b/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj index f2abf5f42..a7ecc6c65 100644 --- a/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj +++ b/NetFabric.Hyperlinq.Abstractions/NetFabric.Hyperlinq.Abstractions.csproj @@ -1,15 +1,17 @@  - net461;net5.0;netstandard2.0;netstandard2.1 + net5.0;netstandard2.0;netstandard2.1 NetFabric.Hyperlinq.Abstractions NetFabric.Hyperlinq.Abstractions Abstractions for high performance enumeration. - 1.2.0 + 1.3.0 Icon.png LICENSE netfabric, hyperlinq, abstractions, linq, enumeration, performance true + true + snupkg diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index f860f61cd..794ee51ce 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -18,9 +18,9 @@ - + - + diff --git a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj index c3beabc44..f433a0dbc 100644 --- a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj +++ b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj @@ -1,7 +1,7 @@ - net461;netstandard2.0 + netstandard2.0 NetFabric.Hyperlinq.Immutable NetFabric.Hyperlinq.Immutable High performance LINQ implementation with minimal heap allocations. Supports all collections in System.Collections.Immutable. @@ -36,7 +36,7 @@ all runtime; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj index da6cbd6b3..6e60efb64 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj @@ -7,7 +7,7 @@ - + diff --git a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj index e6b2bb746..538195793 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj @@ -10,7 +10,7 @@ - + all diff --git a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs index 0e66284c7..1852dbec3 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs @@ -344,7 +344,10 @@ void GenerateMethodSource(CodeBuilder builder, CompilationContext context, IName if (isExtensionMethod) { - _ = builder.AppendLine($"public static {methodReturnType} {methodName}{methodGenericParametersString}(this {methodExtensionType} source{methodParameters})"); + var extraMethodParameter = methodParameters is { Length: 0 } + ? string.Empty + : $", {methodParameters}"; + _ = builder.AppendLine($"public static {methodReturnType} {methodName}{methodGenericParametersString}(this {methodExtensionType} source{extraMethodParameter})"); firstCallParameter = bindingsAttribute is null ? "source" diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs index d21e7e9a2..3d0d57576 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs @@ -24,7 +24,7 @@ public void AsValueEnumerable_With_ImmutableArray_Must_ReturnWrapper(int[] sourc .BeOfType>() .BeEnumerableOf() .BeEqualTo(wrapped, testRefStructs: false); - result.SequenceEqual(wrapped).Must().BeTrue(); + _ = result.SequenceEqual(wrapped).Must().BeTrue(); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj index ee0d1d49e..0158308fc 100644 --- a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj +++ b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj @@ -1,7 +1,7 @@  - net461;netcoreapp2.1;netcoreapp3.1;net6.0 + net48;netcoreapp2.1;netcoreapp3.1;net6.0 false @@ -24,7 +24,7 @@ - + diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs index f73369e65..72c8dc7a5 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs @@ -9,8 +9,11 @@ public static partial class ArrayExtensions static int Count(this ReadOnlySpan source) => source.Length; - [GeneratorIgnore] - static int Count(this ReadOnlySpan source, TPredicate predicate) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static int Count(this ReadOnlySpan source, Func predicate) + => source.Count(new FunctionWrapper(predicate)); + + static int Count(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate: struct, IFunction { var counter = 0; @@ -21,8 +24,11 @@ static int Count(this ReadOnlySpan source, TPredic return counter; } - [GeneratorIgnore] - static int CountAt(this ReadOnlySpan source, TPredicate predicate) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static int Count(this ReadOnlySpan source, Func predicate) + => source.CountAt(new FunctionWrapper(predicate)); + + static int CountAt(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate: struct, IFunction { var counter = 0; diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs index f68b1c0b9..f7eef5479 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -17,9 +19,14 @@ public static int Count(this TEnumerable sour } return counter; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this TEnumerable source, Func predicate) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.Count>(new FunctionWrapper(predicate)); - [GeneratorIgnore] - internal static int Count(this TEnumerable source, TPredicate predicate) + public static int Count(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate: struct, IFunction @@ -33,9 +40,14 @@ internal static int Count(this TE } return counter; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this TEnumerable source, Func predicate) + where TEnumerable : IValueEnumerable + where TEnumerator : struct, IEnumerator + => source.CountAt>(new FunctionWrapper(predicate)); - [GeneratorIgnore] - internal static int CountAt(this TEnumerable source, TPredicate predicate) + public static int CountAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate: struct, IFunction diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs index 18c918af3..0dd554836 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -9,8 +11,13 @@ public static int Count(this TEnumerable sour where TEnumerator : struct, IEnumerator => source.Count; - [GeneratorIgnore] - static int Count(this TEnumerable source, TPredicate predicate) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this TEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + => Count>(source, new FunctionWrapper(predicate)); + + public static int Count(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate: struct, IFunction @@ -19,9 +26,14 @@ static int Count(this TEnumerable {Count: 0} => 0, _ => ValueEnumerableExtensions.Count(source, predicate) }; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this TEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + => CountAt>(source, new FunctionWrapper(predicate)); - [GeneratorIgnore] - static int CountAt(this TEnumerable source, TPredicate predicate) + public static int CountAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate: struct, IFunction diff --git a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs index debe9ac3d..152bad6f5 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -27,8 +29,13 @@ public static async ValueTask CountAsync return counter; } - [GeneratorIgnore] - static async ValueTask CountAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask CountAsync(this TEnumerable source, Func> predicate, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.CountAsync>(new AsyncFunctionWrapper(predicate), cancellationToken); + + public static async ValueTask CountAsync(this TEnumerable source, TPredicate predicate = default, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction @@ -53,8 +60,13 @@ static async ValueTask CountAsync CountAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueTask CountAsync(this TEnumerable source, Func> predicate, CancellationToken cancellationToken = default) + where TEnumerable : IAsyncValueEnumerable + where TEnumerator : struct, IAsyncEnumerator + => source.CountAtAsync>(new AsyncFunctionWrapper(predicate), cancellationToken); + + public static async ValueTask CountAtAsync(this TEnumerable source, TPredicate predicate = default, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate: struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index 7736e74af..1cf6cf678 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -110,6 +110,24 @@ public bool Contains(TSource value, IEqualityComparer? comparer) public static int Count(this ValueEnumerable source) => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int, int>(source); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs index de7c52ad1..cbc18a5b3 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs @@ -182,6 +182,28 @@ public static int Count(this ValueEnumerable sou where TList : IReadOnlyList => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TList : IReadOnlyList + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, TPredicate predicate = default) + where TList : IReadOnlyList + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TList : IReadOnlyList + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) + where TList : IReadOnlyList + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) where TList : IReadOnlyList diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index a12501405..470a699b5 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -100,6 +100,28 @@ public static int Count(this ValueEnumerable => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TEnumerator : struct, IEnumerator + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, TPredicate predicate = default) + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TEnumerator : struct, IEnumerator + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index 39842ec76..64450742e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -55,8 +55,10 @@ public partial struct ValueEnumerable { readonly TEnumerable source; +#pragma warning disable IDE0044 // Add readonly modifier TGetEnumerator getEnumerator; TGetEnumerator2 getEnumerator2; +#pragma warning restore IDE0044 // Add readonly modifier internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); @@ -139,6 +141,44 @@ public static int Count => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TEnumerable : IReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, TPredicate predicate = default) + where TEnumerable : IReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TEnumerable : IReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) + where TEnumerable : IReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) where TEnumerable : IReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index 318390ddc..5d43faa04 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -56,8 +56,10 @@ public partial struct ValueEnumerable { readonly TEnumerable source; +#pragma warning disable IDE0044 // Add readonly modifier TGetEnumerator getEnumerator; TGetEnumerator2 getEnumerator2; +#pragma warning restore IDE0044 // Add readonly modifier internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); @@ -148,6 +150,44 @@ public static int Count => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs index bbbf73dbe..d148e92e7 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs @@ -56,24 +56,25 @@ public partial struct ValueEnumerable { readonly TEnumerable source; +#pragma warning disable IDE0044 // Add readonly modifier TGetEnumerator getEnumerator; TGetEnumerator2 getEnumerator2; +#pragma warning restore IDE0044 // Add readonly modifier internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - public TSource this[int index] + public readonly TSource this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => source[index]; } - - TSource IList.this[int index] + readonly TSource IList.this[int index] { get => source[index]; set => Throw.NotSupportedException(); } - + public readonly int Count => source.Count; @@ -216,6 +217,44 @@ public static int Count => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ValueEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TEnumerator2 : struct + where TGetEnumerator : struct, IFunction + where TGetEnumerator2 : struct, IFunction + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ValueEnumerable source) where TEnumerable : IValueReadOnlyList diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index b8cf7a1d6..1bb92e5bd 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -330,6 +330,24 @@ public ArraySegmentDistinctEnumerable Distinct(IEqualityComparer(this ArraySegmentValueEnumerable source) => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ArraySegmentValueEnumerable source, Func predicate) + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ArraySegmentValueEnumerable source, TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ArraySegmentValueEnumerable source, Func predicate) + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this ArraySegmentValueEnumerable source, TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentValueEnumerable source) => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index f64176e29..554fb5d71 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -241,9 +241,27 @@ public MemoryDistinctEnumerable Distinct(IEqualityComparer? co } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemoryValueEnumerable source) + public static int Count(this MemoryValueEnumerable source) => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemoryValueEnumerable source, Func predicate) + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemoryValueEnumerable source, TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemoryValueEnumerable source, Func predicate) + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this MemoryValueEnumerable source, TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemoryValueEnumerable source) => source.source.Span.SumVector(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index 26ca1d40b..3d8b97c67 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -168,9 +168,27 @@ public bool SequenceEqual(IEnumerable other, IEqualityComparer } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanValueEnumerable source) + public static int Count(this SpanValueEnumerable source) => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SpanValueEnumerable source, Func predicate) + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SpanValueEnumerable source, TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SpanValueEnumerable source, Func predicate) + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this SpanValueEnumerable source, TPredicate predicate = default) + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SpanValueEnumerable source) => source.source.SumVector(); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index f2f5e0132..0af210f36 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -50,7 +50,9 @@ public struct Enumerator : IEnumerator { readonly TSource[]? source; +#pragma warning disable IDE0044 // Add readonly modifier TPredicate predicate; +#pragma warning restore IDE0044 // Add readonly modifier readonly int end; int index; @@ -96,6 +98,24 @@ public readonly void Dispose() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() => ((ReadOnlySpan)source.AsSpan()).Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ((ReadOnlySpan)source.AsSpan()).Count(new PredicatePredicateCombination(this.predicate, predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ((ReadOnlySpan)source.AsSpan()).CountAt(new PredicatePredicateAtCombination(this.predicate, predicate)); #endregion #region Quantifier @@ -109,7 +129,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ((ReadOnlySpan)source.AsSpan()).All(new PredicatePredicateCombination(this.predicate, predicate)); @@ -118,7 +138,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ((ReadOnlySpan)source.AsSpan()).AllAt(new PredicatePredicateAtCombination(this.predicate, predicate)); @@ -131,7 +151,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ((ReadOnlySpan)source.AsSpan()).Any(new PredicatePredicateCombination(this.predicate, predicate)); @@ -140,7 +160,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ((ReadOnlySpan)source.AsSpan()).AnyAt(new PredicatePredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index 0f855762e..2b945a112 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -56,15 +56,18 @@ public struct Enumerator : IAsyncEnumerator , IAsyncStateMachine { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TPredicate predicate; +#pragma warning restore IDE0044 // Add readonly modifier readonly CancellationToken cancellationToken; int state; AsyncValueTaskMethodBuilder builder; +#pragma warning disable IDE1006 // Naming Styles bool s__1; bool s__2; +#pragma warning restore IDE1006 // Naming Styles ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__1; ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__2; @@ -201,7 +204,25 @@ readonly void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAsync(CancellationToken cancellationToken = default) - => source.CountAsync(cancellationToken, predicate); + => source.CountAsync(predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) + => CountAsync(new AsyncFunctionWrapper(predicate), cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) + where TPredicate2 : struct, IAsyncFunction + => source.CountAsync>(new AsyncPredicatePredicateCombination(this.predicate, predicate), cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) + => CountAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAtAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) + where TPredicate2 : struct, IAsyncFunction + => source.CountAtAsync>(new AsyncPredicatePredicateAtCombination(this.predicate, predicate), cancellationToken); #endregion #region Quantifier @@ -215,7 +236,7 @@ public ValueTask AllAsync(Func => AllAsync(new AsyncFunctionWrapper(predicate), cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AllAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) + public ValueTask AllAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.AllAsync>(new AsyncPredicatePredicateCombination(this.predicate, predicate), cancellationToken); @@ -224,7 +245,7 @@ public ValueTask AllAsync(Func AllAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AllAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) + public ValueTask AllAtAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.AllAtAsync>(new AsyncPredicatePredicateAtCombination(this.predicate, predicate), cancellationToken); @@ -237,7 +258,7 @@ public ValueTask AnyAsync(Func => AnyAsync(new AsyncFunctionWrapper(predicate), cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AnyAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) + public ValueTask AnyAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.AnyAsync>(new AsyncPredicatePredicateCombination(this.predicate, predicate), cancellationToken); @@ -246,7 +267,7 @@ public ValueTask AnyAsync(Func AnyAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AnyAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) + public ValueTask AnyAtAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.AnyAtAsync>(new AsyncPredicatePredicateAtCombination(this.predicate, predicate), cancellationToken); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index 45be02d7c..15018ad65 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -50,7 +50,9 @@ public struct Enumerator : IEnumerator { readonly ReadOnlyMemory source; +#pragma warning disable IDE0044 // Add readonly modifier TPredicate predicate; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal Enumerator(in MemoryWhereEnumerable enumerable) @@ -93,9 +95,28 @@ public readonly void Dispose() { } #region Aggregation + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() => source.Span.Count(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.Span.Count(new PredicatePredicateCombination(this.predicate, predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.Span.CountAt(new PredicatePredicateAtCombination(this.predicate, predicate)); + #endregion #region Quantifier @@ -109,7 +130,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Span.All(new PredicatePredicateCombination(this.predicate, predicate)); @@ -118,7 +139,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Span.AllAt(new PredicatePredicateAtCombination(this.predicate, predicate)); @@ -131,7 +152,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Span.Any(new PredicatePredicateCombination(this.predicate, predicate)); @@ -140,7 +161,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Span.AnyAt(new PredicatePredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index b8b23a9b5..83259a241 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -34,12 +34,31 @@ internal SpanWhereEnumerable(ReadOnlySpan source, TPredicate predicate) public WhereEnumerator GetEnumerator() => new(source, predicate); - + #region Aggregation + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() => source.Count(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.Count(new PredicatePredicateCombination(this.predicate, predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.CountAt(new PredicatePredicateAtCombination(this.predicate, predicate)); + #endregion #region Quantifier @@ -52,7 +71,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.All(new PredicatePredicateCombination(this.predicate, predicate)); @@ -61,7 +80,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AllAt(new PredicatePredicateAtCombination(this.predicate, predicate)); @@ -74,7 +93,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Any(new PredicatePredicateCombination(this.predicate, predicate)); @@ -83,7 +102,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AnyAt(new PredicatePredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index 50da765f8..04aa70044 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -55,9 +55,10 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TPredicate predicate; +#pragma warning restore IDE0044 // Add readonly modifier internal Enumerator(in WhereEnumerable enumerable) { @@ -102,6 +103,24 @@ public void Dispose() public int Count() => source.Count(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.Count>(new PredicatePredicateCombination(this.predicate, predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.CountAt>(new PredicatePredicateAtCombination(this.predicate, predicate)); + #endregion #region Conversion @@ -158,7 +177,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.All>(new PredicatePredicateCombination(this.predicate, predicate)); @@ -167,7 +186,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AllAt>(new PredicatePredicateAtCombination(this.predicate, predicate)); @@ -180,7 +199,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Any>(new PredicatePredicateCombination(this.predicate, predicate)); @@ -189,7 +208,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AnyAt>(new PredicatePredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index 6b83db793..ee6250540 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -54,9 +54,10 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TPredicate predicate; +#pragma warning restore IDE0044 // Add readonly modifier internal Enumerator(in WhereEnumerable enumerable) { @@ -101,6 +102,24 @@ public void Dispose() public int Count() => ValueReadOnlyCollectionExtensions.Count(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count>(source, new PredicatePredicateCombination(this.predicate, predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.CountAt>(source, new PredicatePredicateAtCombination(this.predicate, predicate)); + #endregion #region Quantifier @@ -113,7 +132,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.All>(source, new PredicatePredicateCombination(this.predicate, predicate)); @@ -122,7 +141,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.AllAt>(source, new PredicatePredicateAtCombination(this.predicate, predicate)); @@ -135,7 +154,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.Any>(source, new PredicatePredicateCombination(this.predicate, predicate)); @@ -144,7 +163,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.AnyAt>(source, new PredicatePredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index 186e26a51..6e6093428 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -54,7 +54,9 @@ public struct Enumerator : IEnumerator { readonly TSource[]? source; +#pragma warning disable IDE0044 // Add readonly modifier TPredicate predicate; +#pragma warning restore IDE0044 // Add readonly modifier readonly int offset; readonly int end; int index; @@ -103,6 +105,24 @@ public readonly void Dispose() { } public int Count() => ((ReadOnlySpan)source.AsSpan()).CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ((ReadOnlySpan)source.AsSpan()).CountAt(new PredicatePredicateAtCombination(predicate, this.predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ((ReadOnlySpan)source.AsSpan()).CountAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + #endregion #region Quantifier @@ -116,7 +136,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ((ReadOnlySpan)source.AsSpan()).AllAt(new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -125,7 +145,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ((ReadOnlySpan)source.AsSpan()).AllAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); @@ -138,7 +158,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ((ReadOnlySpan)source.AsSpan()).AnyAt(new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -147,7 +167,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ((ReadOnlySpan)source.AsSpan()).AnyAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index ff3144ae8..3100a92c5 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -56,16 +56,19 @@ public struct Enumerator : IAsyncEnumerator , IAsyncStateMachine { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TPredicate predicate; +#pragma warning restore IDE0044 // Add readonly modifier readonly CancellationToken cancellationToken; int index; int state; AsyncValueTaskMethodBuilder builder; +#pragma warning disable IDE1006 // Naming Styles bool s__1; bool s__2; +#pragma warning restore IDE1006 // Naming Styles ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__1; ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__2; @@ -203,7 +206,25 @@ readonly void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAsync(CancellationToken cancellationToken = default) - => source.CountAtAsync(cancellationToken, predicate); + => source.CountAtAsync(predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) + => CountAsync(new AsyncFunctionWrapper(predicate), cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) + where TPredicate2 : struct, IAsyncFunction + => source.CountAtAsync>(new AsyncPredicatePredicateAtCombination(predicate, this.predicate), cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) + => CountAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) + where TPredicate2 : struct, IAsyncFunction + => source.CountAtAsync>(new AsyncPredicateAtPredicateAtCombination(this.predicate, predicate), cancellationToken); #endregion #region Quantifier diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index 74dbf06ae..c33057a85 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -97,6 +97,24 @@ public readonly void Dispose() { } public int Count() => source.Span.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.Span.CountAt(new PredicatePredicateAtCombination(predicate, this.predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.Span.CountAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + #endregion #region Quantifier @@ -109,7 +127,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Span.AllAt(new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -118,7 +136,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Span.AllAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); @@ -131,7 +149,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Span.AnyAt(new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -140,7 +158,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Span.AnyAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index df207310d..a61545c68 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -40,6 +40,24 @@ public WhereAtEnumerator GetEnumerator() public int Count() => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.CountAt(new PredicatePredicateAtCombination(predicate, this.predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.CountAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + #endregion #region Quantifier @@ -52,7 +70,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AllAt(new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -61,7 +79,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AllAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); @@ -74,7 +92,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AnyAt(new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -83,7 +101,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AnyAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index 60ada4189..81667a8bb 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -54,9 +54,10 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TPredicate predicate; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal Enumerator(in WhereAtEnumerable enumerable) @@ -107,6 +108,24 @@ public void Dispose() public int Count() => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.CountAt>(new PredicatePredicateAtCombination(predicate, this.predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => source.CountAt>(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + #endregion #region Quantifier @@ -119,7 +138,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AllAt>(new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -128,7 +147,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AllAt>(new PredicateAtPredicateAtCombination(this.predicate, predicate)); @@ -141,7 +160,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AnyAt>(new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -150,7 +169,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AnyAt>(new PredicateAtPredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index ba4218dd3..4df20a09f 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -54,9 +54,10 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TPredicate predicate; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal Enumerator(in WhereAtEnumerable enumerable) @@ -106,6 +107,24 @@ public void Dispose() public int Count() => CountAt(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.CountAt>(source, new PredicatePredicateAtCombination(predicate, this.predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueReadOnlyCollectionExtensions.CountAt>(source, new PredicateAtPredicateAtCombination(this.predicate, predicate)); + #endregion #region Quantifier @@ -118,7 +137,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.AllAt>(source, new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -127,7 +146,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.AllAt>(source, new PredicateAtPredicateAtCombination(this.predicate, predicate)); @@ -140,7 +159,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.AnyAt>(source, new PredicatePredicateAtCombination(predicate, this.predicate)); @@ -149,7 +168,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.AnyAt>(source, new PredicateAtPredicateAtCombination(this.predicate, predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index 5184f6e12..2d9c935a6 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -54,8 +54,10 @@ public struct Enumerator : IEnumerator { readonly TSource[]? source; +#pragma warning disable IDE0044 // Add readonly modifier TPredicate predicate; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier readonly int end; int index; @@ -68,9 +70,12 @@ internal Enumerator(in ArraySegmentWhereSelectEnumerable selector.Invoke(source![index]); - object? IEnumerator.Current + public readonly TResult Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => selector.Invoke(source![index]); + } + readonly object? IEnumerator.Current // ReSharper disable once HeapView.PossibleBoxingAllocation => selector.Invoke(source![index]); @@ -98,6 +103,24 @@ public readonly void Dispose() { } public int Count() => ((ReadOnlySpan)source.AsSpan()).Count(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueEnumerableExtensions.Count, Enumerator, TResult, TPredicate2>(this, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueEnumerableExtensions.CountAt, Enumerator, TResult, TPredicate2>(this, predicate); + #endregion #region Quantifier @@ -111,7 +134,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.All, Enumerator, TResult, TPredicate2>(predicate); @@ -120,7 +143,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.AllAt, Enumerator, TResult, TPredicate2>(predicate); @@ -133,7 +156,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Any, Enumerator, TResult, TPredicate2>(predicate); @@ -142,7 +165,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.AnyAt, Enumerator, TResult, TPredicate2>(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index 7b1bb5e90..b8b6863a1 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -52,18 +52,21 @@ public struct Enumerator : IAsyncEnumerator , IAsyncStateMachine { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TPredicate predicate; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier readonly CancellationToken cancellationToken; int state; AsyncValueTaskMethodBuilder builder; TSource? item; +#pragma warning disable IDE1006 // Naming Styles bool s__2; TResult? s__3; bool s__4; +#pragma warning restore IDE1006 // Naming Styles ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__1; ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__2; ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__3; @@ -229,7 +232,25 @@ void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAsync(CancellationToken cancellationToken = default) - => source.CountAsync(cancellationToken, predicate); + => source.CountAsync(predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) + => CountAsync(new AsyncFunctionWrapper(predicate), cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) + where TPredicate2 : struct, IAsyncFunction + => AsyncValueEnumerableExtensions.CountAsync, Enumerator, TResult, TPredicate2>(this, predicate, cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) + => CountAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask CountAtAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) + where TPredicate2 : struct, IAsyncFunction + => AsyncValueEnumerableExtensions.CountAtAsync, Enumerator, TResult, TPredicate2>(this, predicate, cancellationToken); #endregion #region Quantifier diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index bb5bb3a8c..683c97e93 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -56,8 +56,10 @@ public struct Enumerator : IEnumerator { readonly ReadOnlyMemory source; +#pragma warning disable IDE0044 // Add readonly modifier TPredicate predicate; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal Enumerator(in MemoryWhereSelectEnumerable enumerable) @@ -103,6 +105,24 @@ public readonly void Dispose() { } public int Count() => source.Span.Count(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueEnumerableExtensions.Count, Enumerator, TResult, TPredicate2>(this, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueEnumerableExtensions.CountAt, Enumerator, TResult, TPredicate2>(this, predicate); + #endregion #region Quantifier @@ -115,7 +135,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.All, Enumerator, TResult, TPredicate2>(predicate); @@ -124,7 +144,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.AllAt, Enumerator, TResult, TPredicate2>(predicate); @@ -137,7 +157,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Any, Enumerator, TResult, TPredicate2>(predicate); @@ -146,7 +166,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.AnyAt, Enumerator, TResult, TPredicate2>(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index fb8c37b8b..133accd8c 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -45,6 +45,24 @@ public WhereSelectEnumerator GetEnumera public int Count() => source.Count(predicate); + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public int Count(Func predicate) + // => Count(new FunctionWrapper(predicate)); + + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public int Count(TPredicate2 predicate = default) + // where TPredicate2 : struct, IFunction + // => ValueEnumerableExtensions.Count, WhereSelectEnumerator, TResult, TPredicate2>(this, predicate); + + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public int Count(Func predicate) + // => CountAt(new FunctionWrapper(predicate)); + + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public int CountAt(TPredicate2 predicate = default) + // where TPredicate2 : struct, IFunction + // => ValueEnumerableExtensions.CountAt, WhereSelectEnumerator, TResult, TPredicate2>(this, predicate); + #endregion #region Quantifier diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index d69f3ff4e..abeda7695 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -60,10 +60,11 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TPredicate predicate; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier internal Enumerator(in WhereSelectEnumerable enumerable) { @@ -107,6 +108,24 @@ public void Dispose() public int Count() => source.Count(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueEnumerableExtensions.Count, Enumerator, TResult, TPredicate2>(this, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueEnumerableExtensions.CountAt, Enumerator, TResult, TPredicate2>(this, predicate); + #endregion #region Quantifier @@ -119,7 +138,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.All, Enumerator, TResult, TPredicate2>(predicate); @@ -128,7 +147,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.AllAt, Enumerator, TResult, TPredicate2>(predicate); @@ -141,7 +160,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Any, Enumerator, TResult, TPredicate2>(predicate); @@ -150,7 +169,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.AnyAt, Enumerator, TResult, TPredicate2>(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index 318b52d53..3a9ee6f62 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -60,10 +60,11 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TPredicate predicate; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier internal Enumerator(in WhereSelectEnumerable enumerable) { @@ -107,6 +108,24 @@ public void Dispose() public int Count() => ValueReadOnlyCollectionExtensions.Count(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => Count(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueEnumerableExtensions.Count, Enumerator, TResult, TPredicate2>(this, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Count(Func predicate) + => CountAt(new FunctionWrapper(predicate)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int CountAt(TPredicate2 predicate = default) + where TPredicate2 : struct, IFunction + => ValueEnumerableExtensions.CountAt, Enumerator, TResult, TPredicate2>(this, predicate); + #endregion #region Quantifier @@ -119,7 +138,7 @@ public bool All(Func predicate) => All(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate2 predicate) + public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.All, Enumerator, TResult, TPredicate2>(predicate); @@ -128,7 +147,7 @@ public bool All(Func predicate) => AllAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate2 predicate) + public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.AllAt, Enumerator, TResult, TPredicate2>(predicate); @@ -141,7 +160,7 @@ public bool Any(Func predicate) => Any(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate2 predicate) + public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Any, Enumerator, TResult, TPredicate2>(predicate); @@ -150,7 +169,7 @@ public bool Any(Func predicate) => AnyAt(new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate2 predicate) + public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.AnyAt, Enumerator, TResult, TPredicate2>(predicate); diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs index 11e618bd0..df7f34b58 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs @@ -10,8 +10,10 @@ public ref struct WhereSelectEnumerator where TSelector : struct, IFunction { readonly ReadOnlySpan source; +#pragma warning disable IDE0044 // Add readonly modifier TPredicate predicate; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal WhereSelectEnumerator(ReadOnlySpan source, TPredicate predicate, TSelector selector) diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index fc28e5aa2..4873c2627 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -1,16 +1,18 @@  - net461;netstandard2.0;netcoreapp3.1;net5.0;net6.0 + netstandard2.0;netcoreapp3.1;net5.0;net6.0 NetFabric.Hyperlinq NetFabric.Hyperlinq High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, Memory, and Span. - 3.0.0-beta44 + 3.0.0-beta45 Icon.png LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance true true + true + snupkg true @@ -60,7 +62,7 @@ all runtime; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers diff --git a/NetFabric.Hyperlinq/Option/Option.cs b/NetFabric.Hyperlinq/Option/Option.cs index 5ab29bc49..6eb50cea1 100644 --- a/NetFabric.Hyperlinq/Option/Option.cs +++ b/NetFabric.Hyperlinq/Option/Option.cs @@ -252,10 +252,11 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - readonly Option source; + readonly Option source; +#pragma warning disable IDE0044 // Add readonly modifier TSelector selector; - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TSubEnumerator subEnumerator; // do not make readonly + TSubEnumerator subEnumerator; +#pragma warning restore IDE0044 // Add readonly modifier int state; internal Enumerator(in SelectManyEnumerable enumerable) diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs index 2c8ac363d..35fa68594 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs @@ -40,14 +40,17 @@ public struct Enumerator : IAsyncEnumerator , IAsyncStateMachine { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; +#pragma warning restore IDE0044 // Add readonly modifier int counter; int state; AsyncValueTaskMethodBuilder builder; +#pragma warning disable IDE1006 // Naming Styles bool s__1; bool s__2; +#pragma warning restore IDE1006 // Naming Styles ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__1; internal Enumerator(in SkipEnumerable enumerable, CancellationToken cancellationToken) diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs index 2101b7761..e26b528b6 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs @@ -40,8 +40,9 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; +#pragma warning restore IDE0044 // Add readonly modifier int counter; internal Enumerator(in SkipEnumerable enumerable) diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs index 4cbaba57c..02933aa2b 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs @@ -39,15 +39,18 @@ public struct Enumerator : IAsyncEnumerator , IAsyncStateMachine { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; +#pragma warning restore IDE0044 // Add readonly modifier int skipCounter; int takeCounter; int state; AsyncValueTaskMethodBuilder builder; +#pragma warning disable IDE1006 // Naming Styles bool s__1; bool s__2; +#pragma warning restore IDE1006 // Naming Styles ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__1; ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__2; diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs index da715018e..d553707ea 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs @@ -282,5 +282,27 @@ static bool ComparerContains(TList source, TSource value, IEqualityComparer(this in SkipTakeEnumerable source) where TList : struct, IReadOnlyList => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SkipTakeEnumerable source, Func predicate) + where TList : struct, IReadOnlyList + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SkipTakeEnumerable source, TPredicate predicate = default) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SkipTakeEnumerable source, Func predicate) + where TList : struct, IReadOnlyList + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this SkipTakeEnumerable source, TPredicate predicate = default) + where TList : struct, IReadOnlyList + where TPredicate : struct, IFunction + => source.CountAt(predicate); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs index f2299f3f0..e3c11e3bb 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs @@ -40,8 +40,9 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; +#pragma warning restore IDE0044 // Add readonly modifier int skipCounter; int takeCounter; diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs index 36351086b..24ab0a7b0 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs @@ -98,8 +98,9 @@ bool ICollection.Remove(TSource item) public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; +#pragma warning restore IDE0044 // Add readonly modifier int skipCounter; int takeCounter; EnumeratorState state; @@ -255,5 +256,31 @@ public static int Count(this in SkipTakeEnume where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator => source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SkipTakeEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SkipTakeEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SkipTakeEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this SkipTakeEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => source.CountAt(predicate); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs index abb22691f..fe686d543 100644 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs @@ -41,13 +41,16 @@ public struct Enumerator : IAsyncEnumerator , IAsyncStateMachine { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; +#pragma warning restore IDE0044 // Add readonly modifier int counter; int state; AsyncValueTaskMethodBuilder builder; +#pragma warning disable IDE1006 // Naming Styles bool s__1; +#pragma warning restore IDE1006 // Naming Styles ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__1; ValueTaskAwaiter u__2; diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs index 982cb3ced..561203a42 100644 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs @@ -42,8 +42,9 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; +#pragma warning restore IDE0044 // Add readonly modifier int counter; internal Enumerator(in TakeEnumerable enumerable) diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 655bf27e2..9c4001f46 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -108,7 +108,9 @@ public struct Enumerator : IEnumerator { readonly TSource[]? source; +#pragma warning disable IDE0044 // Add readonly modifier TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier readonly int end; int index; @@ -226,6 +228,28 @@ public static int Count(this ArraySegmentSelectEnum where TSelector : struct, IFunction => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ArraySegmentSelectEnumerable source, Func predicate) + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ArraySegmentSelectEnumerable source, TPredicate predicate = default) + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ArraySegmentSelectEnumerable source, Func predicate) + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this ArraySegmentSelectEnumerable source, TPredicate predicate = default) + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.CountAt, ArraySegmentSelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs index 9aa0e00b4..e1c26f312 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -53,15 +53,18 @@ public struct Enumerator : IAsyncEnumerator , IAsyncStateMachine { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier readonly CancellationToken cancellationToken; int state; AsyncValueTaskMethodBuilder builder; +#pragma warning disable IDE1006 // Naming Styles bool s__1; TResult? s__2; +#pragma warning restore IDE1006 // Naming Styles ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__1; ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__2; ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__3; diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index 95e841f29..fc86272de 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -105,7 +105,9 @@ public struct Enumerator : IEnumerator { readonly ReadOnlyMemory source; +#pragma warning disable IDE0044 // Add readonly modifier TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal Enumerator(in MemorySelectEnumerable enumerable) @@ -218,6 +220,28 @@ public static int Count(this MemorySelectEnumerable where TSelector : struct, IFunction => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemorySelectEnumerable source, Func predicate) + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, MemorySelectEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemorySelectEnumerable source, TPredicate predicate = default) + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, MemorySelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemorySelectEnumerable source, Func predicate) + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, MemorySelectEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this MemorySelectEnumerable source, TPredicate predicate = default) + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.CountAt, MemorySelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemorySelectEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index 3c6ccb3b8..210e5ed69 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -137,6 +137,28 @@ public static int Count(this SpanSelectEnumerable => source.Count; + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static int Count(this SpanSelectEnumerable source, Func predicate) + // where TSelector : struct, IFunction + // => ValueReadOnlyCollectionExtensions.Count, SpanSelectEnumerable.Enumerator, TResult>(source, predicate); + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static int Count(this SpanSelectEnumerable source, TPredicate predicate = default) + // where TSelector : struct, IFunction + // where TPredicate : struct, IFunction + // => ValueReadOnlyCollectionExtensions.Count, SpanSelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static int Count(this SpanSelectEnumerable source, Func predicate) + // where TSelector : struct, IFunction + // => ValueReadOnlyCollectionExtensions.Count, SpanSelectEnumerable.Enumerator, TResult>(source, predicate); + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static int CountAt(this SpanSelectEnumerable source, TPredicate predicate = default) + // where TSelector : struct, IFunction + // where TPredicate : struct, IFunction + // => ValueReadOnlyCollectionExtensions.CountAt, SpanSelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this SpanSelectEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index e365a3491..3043a11c3 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -55,9 +55,10 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier internal Enumerator(in SelectEnumerable enumerable) { diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index c2473c354..c223d31fe 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -93,9 +93,10 @@ bool ICollection.Remove(TResult item) public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier internal Enumerator(in SelectEnumerable enumerable) { @@ -210,104 +211,134 @@ public static int Count(t where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.Count; - + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => Count, SelectEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => Count, SelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => Count, SelectEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this SelectEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => CountAt, SelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this SelectEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum(source.source, source.selector); + => Sum(source.source, source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs index 91bea70bd..5300c6878 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -114,10 +114,10 @@ readonly void IList.RemoveAt(int index) public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TSelector selector; // do not make readonly to avoid +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; + TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier internal Enumerator(in SelectEnumerable enumerable) { @@ -237,7 +237,37 @@ public static int Count(t where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.Count; - + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectEnumerable source, Func predicate) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, SelectEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectEnumerable source, TPredicate predicate = default) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, SelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectEnumerable source, Func predicate) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, SelectEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this SelectEnumerable source, TPredicate predicate = default) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.CountAt, SelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SelectEnumerable source) where TEnumerable : struct, IValueReadOnlyList diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index d488425ea..a15e1c6d8 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -101,7 +101,9 @@ public struct Enumerator : IEnumerator { readonly TSource[]? source; +#pragma warning disable IDE0044 // Add readonly modifier TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier readonly int offset; readonly int end; int index; @@ -217,6 +219,28 @@ public static int Count(this ArraySegmentSelectAtEn where TSelector : struct, IFunction => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ArraySegmentSelectAtEnumerable source, Func predicate) + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectAtEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ArraySegmentSelectAtEnumerable source, TPredicate predicate = default) + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectAtEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this ArraySegmentSelectAtEnumerable source, Func predicate) + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectAtEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this ArraySegmentSelectAtEnumerable source, TPredicate predicate = default) + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.CountAt, ArraySegmentSelectAtEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentSelectAtEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index 8fc4865f0..658feaa60 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -53,16 +53,19 @@ public struct Enumerator : IAsyncEnumerator , IAsyncStateMachine { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier readonly CancellationToken cancellationToken; int index; int state; AsyncValueTaskMethodBuilder builder; +#pragma warning disable IDE1006 // Naming Styles bool s__1; TResult? s__2; +#pragma warning restore IDE1006 // Naming Styles ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__1; ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__2; ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__3; diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 5dec3455d..64f5d1c20 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -76,19 +76,20 @@ void ICollection.CopyTo(TResult[] array, int arrayAt) for (var index = 0; index < span.Length; index++) array[index + arrayAt] = selector.Invoke(span[index], index); } - void ICollection.Add(TResult item) + + readonly void ICollection.Add(TResult item) => Throw.NotSupportedException(); - void ICollection.Clear() + readonly void ICollection.Clear() => Throw.NotSupportedException(); - public bool Contains(TResult item) + public readonly bool Contains(TResult item) => source.Span.ContainsAt(item, default, selector); - bool ICollection.Remove(TResult item) + readonly bool ICollection.Remove(TResult item) => Throw.NotSupportedException(); - int IList.IndexOf(TResult item) + readonly int IList.IndexOf(TResult item) => IndexOfAt(source.Span, item, selector); - void IList.Insert(int index, TResult item) + readonly void IList.Insert(int index, TResult item) => Throw.NotSupportedException(); - void IList.RemoveAt(int index) + readonly void IList.RemoveAt(int index) => Throw.NotSupportedException(); [StructLayout(LayoutKind.Auto)] @@ -96,7 +97,9 @@ public struct Enumerator : IEnumerator { readonly ReadOnlyMemory source; +#pragma warning disable IDE0044 // Add readonly modifier TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal Enumerator(in MemorySelectAtEnumerable enumerable) @@ -106,7 +109,7 @@ internal Enumerator(in MemorySelectAtEnumerable enu index = -1; } - public TResult Current + public readonly TResult Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => selector.Invoke(source.Span[index], index); @@ -209,6 +212,28 @@ public static int Count(this MemorySelectAtEnumerab where TSelector : struct, IFunction => source.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemorySelectAtEnumerable source, Func predicate) + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, MemorySelectAtEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemorySelectAtEnumerable source, TPredicate predicate = default) + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => source.Count(predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this MemorySelectAtEnumerable source, Func predicate) + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, MemorySelectAtEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this MemorySelectAtEnumerable source, TPredicate predicate = default) + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemorySelectAtEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index d5b98bbfc..df4ae147e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -137,6 +137,28 @@ public static int Count(this SpanSelectAtEnumerable where TSelector : struct, IFunction => source.Count; + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static int Count(this SpanSelectAtEnumerable source, Func predicate) + // where TSelector : struct, IFunction + // => source.Count(predicate); + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static int Count(this SpanSelectAtEnumerable source, TPredicate predicate = default) + // where TSelector : struct, IFunction + // where TPredicate : struct, IFunction + // => source.Count(predicate); + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static int Count(this SpanSelectAtEnumerable source, Func predicate) + // where TSelector : struct, IFunction + // => source.Count(predicate); + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static int CountAt(this SpanSelectAtEnumerable source, TPredicate predicate = default) + // where TSelector : struct, IFunction + // where TPredicate : struct, IFunction + // => source.CountAt(predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SpanSelectAtEnumerable source) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index 924116c48..7801ac752 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -55,9 +55,10 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal Enumerator(in SelectAtEnumerable enumerable) diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index 8d08ef0f1..fe2d27d49 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -93,9 +93,10 @@ bool ICollection.Remove(TResult item) public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal Enumerator(in SelectAtEnumerable enumerable) @@ -219,7 +220,37 @@ public static int Count(t where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.Count; - + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectAtEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => Count, SelectAtEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectAtEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => Count, SelectAtEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectAtEnumerable source, Func predicate) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => Count, SelectAtEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this SelectAtEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => CountAt, SelectAtEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SelectAtEnumerable source) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs index 4d8118e45..5e7ac4098 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -119,9 +119,10 @@ void IList.RemoveAt(int index) public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; TSelector selector; +#pragma warning restore IDE0044 // Add readonly modifier int index; internal Enumerator(in SelectAtEnumerable enumerable) @@ -252,7 +253,37 @@ public static int Count(t where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction => source.Count; - + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectAtEnumerable source, Func predicate) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, SelectAtEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectAtEnumerable source, TPredicate predicate = default) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, SelectAtEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this SelectAtEnumerable source, Func predicate) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.Count, SelectAtEnumerable.Enumerator, TResult>(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this SelectAtEnumerable source, TPredicate predicate = default) + where TEnumerable : struct, IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.CountAt, SelectAtEnumerable.Enumerator, TResult, TPredicate>(source, predicate); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SelectAtEnumerable source) where TEnumerable : struct, IValueReadOnlyList diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs index 7f5fb7f77..0bd25b721 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs @@ -54,12 +54,13 @@ public struct Enumerator : IEnumerator { readonly TSource[]? source; +#pragma warning disable IDE0044 // Add readonly modifier TSelector selector; + TSubEnumerator subEnumerator; +#pragma warning restore IDE0044 // Add readonly modifier readonly int end; EnumeratorState state; int sourceIndex; - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TSubEnumerator subEnumerator; // do not make readonly internal Enumerator(in ArraySegmentSelectManyEnumerable enumerable) { diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs index 66ca00a41..5fa18194b 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs @@ -55,12 +55,13 @@ public struct Enumerator : IEnumerator { readonly ReadOnlyMemory source; +#pragma warning disable IDE0044 // Add readonly modifier TSelector selector; + TSubEnumerator subEnumerator; +#pragma warning restore IDE0044 // Add readonly modifier readonly int end; EnumeratorState state; int sourceIndex; - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TSubEnumerator subEnumerator; // do not make readonly internal Enumerator(in MemorySelectManyEnumerable enumerable) { diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs index 5064dcd22..6f7bff87a 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs @@ -47,12 +47,13 @@ public Enumerator GetEnumerator() public ref struct Enumerator { readonly ReadOnlySpan source; +#pragma warning disable IDE0044 // Add readonly modifier TSelector selector; + TSubEnumerator subEnumerator; +#pragma warning restore IDE0044 // Add readonly modifier readonly int end; EnumeratorState state; int sourceIndex; - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TSubEnumerator subEnumerator; // do not make readonly internal Enumerator(SpanSelectManyEnumerable enumerable) { diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs index 5f8b2af3e..bc5c33140 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs @@ -60,11 +60,11 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator sourceEnumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator sourceEnumerator; TSelector selector; - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TSubEnumerator subEnumerator; // do not make readonly + TSubEnumerator subEnumerator; +#pragma warning restore IDE0044 // Add readonly modifier int state; internal Enumerator(in SelectManyEnumerable enumerable) diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs index f5f339021..95fee3686 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs @@ -45,14 +45,17 @@ public struct Enumerator : IAsyncEnumerator , IAsyncStateMachine { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; +#pragma warning restore IDE0044 // Add readonly modifier readonly IEqualityComparer? comparer; Set set; int state; AsyncValueTaskMethodBuilder builder; +#pragma warning disable IDE1006 // Naming Styles bool s__1; +#pragma warning restore IDE1006 // Naming Styles ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter u__1; ValueTaskAwaiter u__2; diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs index 53308869b..bd7f01411 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs @@ -46,8 +46,9 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - [SuppressMessage("Style", "IDE0044:Add readonly modifier")] - TEnumerator enumerator; // do not make readonly +#pragma warning disable IDE0044 // Add readonly modifier + TEnumerator enumerator; +#pragma warning restore IDE0044 // Add readonly modifier readonly IEqualityComparer? comparer; Set set; diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncPredicateCombination.cs b/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncPredicateCombination.cs index 3599ee390..1c826e808 100644 --- a/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncPredicateCombination.cs +++ b/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncPredicateCombination.cs @@ -10,13 +10,15 @@ public struct AsyncPredicatePredicateCombination where TPredicate2 : struct, IAsyncFunction { +#pragma warning disable IDE0044 // Add readonly modifier TPredicate1 first; TPredicate2 second; +#pragma warning restore IDE0044 // Add readonly modifier public AsyncPredicatePredicateCombination(TPredicate1 first, TPredicate2 second) => (this.first, this.second) = (first, second); - public async ValueTask InvokeAsync(TSource item, CancellationToken cancellationToken) + public readonly async ValueTask InvokeAsync(TSource item, CancellationToken cancellationToken) => await first.InvokeAsync(item, cancellationToken).ConfigureAwait(false) && await second.InvokeAsync(item, cancellationToken).ConfigureAwait(false); } @@ -27,13 +29,15 @@ public struct AsyncPredicatePredicateAtCombination where TPredicate2 : struct, IAsyncFunction { +#pragma warning disable IDE0044 // Add readonly modifier TPredicate1 first; TPredicate2 second; +#pragma warning restore IDE0044 // Add readonly modifier public AsyncPredicatePredicateAtCombination(TPredicate1 first, TPredicate2 second) => (this.first, this.second) = (first, second); - public async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) + public readonly async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) => await first.InvokeAsync(item, cancellationToken).ConfigureAwait(false) && await second.InvokeAsync(item, index, cancellationToken).ConfigureAwait(false); } @@ -44,13 +48,15 @@ public struct AsyncPredicateAtPredicateAtCombination where TPredicate2 : struct, IAsyncFunction { +#pragma warning disable IDE0044 // Add readonly modifier TPredicate1 first; TPredicate2 second; +#pragma warning restore IDE0044 // Add readonly modifier public AsyncPredicateAtPredicateAtCombination(TPredicate1 first, TPredicate2 second) => (this.first, this.second) = (first, second); - public async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) + public readonly async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) => await first.InvokeAsync(item, index, cancellationToken).ConfigureAwait(false) && await second.InvokeAsync(item, index, cancellationToken).ConfigureAwait(false); } diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncSelectorCombination.cs b/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncSelectorCombination.cs index 47ffdeefc..191d83789 100644 --- a/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncSelectorCombination.cs +++ b/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncSelectorCombination.cs @@ -10,13 +10,15 @@ public struct AsyncSelectorSelectorCombination where TSelector2 : struct, IAsyncFunction { +#pragma warning disable IDE0044 // Add readonly modifier TSelector1 first; TSelector2 second; +#pragma warning restore IDE0044 // Add readonly modifier public AsyncSelectorSelectorCombination(TSelector1 first, TSelector2 second) => (this.first, this.second) = (first, second); - public async ValueTask InvokeAsync(TSource item, CancellationToken cancellationToken) + public readonly async ValueTask InvokeAsync(TSource item, CancellationToken cancellationToken) => await second.InvokeAsync( await first.InvokeAsync(item, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); } @@ -27,13 +29,15 @@ public struct AsyncSelectorAtSelectorCombination where TSelector2 : struct, IAsyncFunction { +#pragma warning disable IDE0044 // Add readonly modifier TSelector1 first; TSelector2 second; +#pragma warning restore IDE0044 // Add readonly modifier public AsyncSelectorAtSelectorCombination(TSelector1 first, TSelector2 second) => (this.first, this.second) = (first, second); - public async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) + public readonly async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) => await second.InvokeAsync( await first.InvokeAsync(item, index, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); @@ -45,13 +49,15 @@ public struct AsyncSelectorSelectorAtCombination where TSelector2 : struct, IAsyncFunction { +#pragma warning disable IDE0044 // Add readonly modifier TSelector1 first; TSelector2 second; +#pragma warning restore IDE0044 // Add readonly modifier public AsyncSelectorSelectorAtCombination(TSelector1 first, TSelector2 second) => (this.first, this.second) = (first, second); - public async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) + public readonly async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) => await second.InvokeAsync( await first.InvokeAsync(item, cancellationToken).ConfigureAwait(false), index, cancellationToken).ConfigureAwait(false); @@ -64,13 +70,15 @@ public struct AsyncSelectorAtSelectorAtCombination where TSelector2 : struct, IAsyncFunction { +#pragma warning disable IDE0044 // Add readonly modifier TSelector1 first; TSelector2 second; +#pragma warning restore IDE0044 // Add readonly modifier public AsyncSelectorAtSelectorAtCombination(TSelector1 first, TSelector2 second) => (this.first, this.second) = (first, second); - public async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) + public readonly async ValueTask InvokeAsync(TSource item, int index, CancellationToken cancellationToken) => await second.InvokeAsync( await first.InvokeAsync(item, index, cancellationToken).ConfigureAwait(false), index, cancellationToken).ConfigureAwait(false); diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateCombination.cs b/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateCombination.cs index 07542f345..e1e503097 100644 --- a/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateCombination.cs +++ b/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateCombination.cs @@ -8,13 +8,15 @@ public struct PredicatePredicateCombination where TPredicate1 : struct, IFunction where TPredicate2 : struct, IFunction { +#pragma warning disable IDE0044 // Add readonly modifier TPredicate1 first; TPredicate2 second; +#pragma warning restore IDE0044 // Add readonly modifier public PredicatePredicateCombination(TPredicate1 first, TPredicate2 second) => (this.first, this.second) = (first, second); - public bool Invoke(TSource item) + public readonly bool Invoke(TSource item) => first.Invoke(item) && second.Invoke(item); } @@ -24,13 +26,15 @@ public struct PredicatePredicateAtCombination where TPredicate1 : struct, IFunction where TPredicate2 : struct, IFunction { +#pragma warning disable IDE0044 // Add readonly modifier TPredicate1 first; TPredicate2 second; +#pragma warning restore IDE0044 // Add readonly modifier public PredicatePredicateAtCombination(TPredicate1 first, TPredicate2 second) => (this.first, this.second) = (first, second); - public bool Invoke(TSource item, int index) + public readonly bool Invoke(TSource item, int index) => first.Invoke(item) && second.Invoke(item, index); } @@ -40,13 +44,15 @@ public struct PredicateAtPredicateAtCombination where TPredicate2 : struct, IFunction { +#pragma warning disable IDE0044 // Add readonly modifier TPredicate1 first; TPredicate2 second; +#pragma warning restore IDE0044 // Add readonly modifier public PredicateAtPredicateAtCombination(TPredicate1 first, TPredicate2 second) => (this.first, this.second) = (first, second); - public bool Invoke(TSource item, int index) + public readonly bool Invoke(TSource item, int index) => first.Invoke(item, index) && second.Invoke(item, index); } } diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateInCombination.cs b/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateInCombination.cs index 6b9bd5927..4d1573aa9 100644 --- a/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateInCombination.cs +++ b/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateInCombination.cs @@ -8,13 +8,15 @@ public struct PredicatePredicateCombinationIn where TPredicate1 : struct, IFunctionIn where TPredicate2 : struct, IFunctionIn { +#pragma warning disable IDE0044 // Add readonly modifier TPredicate1 first; TPredicate2 second; +#pragma warning restore IDE0044 // Add readonly modifier public PredicatePredicateCombinationIn(TPredicate1 first, TPredicate2 second) => (this.first, this.second) = (first, second); - public bool Invoke(in TSource item) + public readonly bool Invoke(in TSource item) => first.Invoke(in item) && second.Invoke(in item); } @@ -24,13 +26,15 @@ public struct PredicatePredicateAtCombinationIn where TPredicate2 : struct, IFunctionIn { +#pragma warning disable IDE0044 // Add readonly modifier TPredicate1 first; TPredicate2 second; +#pragma warning restore IDE0044 // Add readonly modifier public PredicatePredicateAtCombinationIn(TPredicate1 first, TPredicate2 second) => (this.first, this.second) = (first, second); - public bool Invoke(in TSource item, int index) + public readonly bool Invoke(in TSource item, int index) => first.Invoke(in item) && second.Invoke(in item, index); } @@ -40,13 +44,15 @@ public struct PredicateAtPredicateAtCombinationIn where TPredicate2 : struct, IFunctionIn { +#pragma warning disable IDE0044 // Add readonly modifier TPredicate1 first; TPredicate2 second; +#pragma warning restore IDE0044 // Add readonly modifier public PredicateAtPredicateAtCombinationIn(TPredicate1 first, TPredicate2 second) => (this.first, this.second) = (first, second); - public bool Invoke(in TSource item, int index) + public readonly bool Invoke(in TSource item, int index) => first.Invoke(in item, index) && second.Invoke(in item, index); } } diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/SelectorCombination.cs b/NetFabric.Hyperlinq/Utils/FunctionCombination/SelectorCombination.cs index 456bb94f0..92d3bb4c1 100644 --- a/NetFabric.Hyperlinq/Utils/FunctionCombination/SelectorCombination.cs +++ b/NetFabric.Hyperlinq/Utils/FunctionCombination/SelectorCombination.cs @@ -8,13 +8,15 @@ public struct SelectorSelectorCombination where TSelector2 : struct, IFunction { +#pragma warning disable IDE0044 // Add readonly modifier TSelector1 first; TSelector2 second; +#pragma warning restore IDE0044 // Add readonly modifier public SelectorSelectorCombination(TSelector1 first, TSelector2 second) => (this.first, this.second) = (first, second); - public TResult Invoke(TSource item) + public readonly TResult Invoke(TSource item) => second.Invoke(first.Invoke(item)); } @@ -24,13 +26,15 @@ public struct SelectorAtSelectorCombination where TSelector2 : struct, IFunction { +#pragma warning disable IDE0044 // Add readonly modifier TSelector1 first; TSelector2 second; +#pragma warning restore IDE0044 // Add readonly modifier public SelectorAtSelectorCombination(TSelector1 first, TSelector2 second) => (this.first, this.second) = (first, second); - public TResult Invoke(TSource item, int index) + public readonly TResult Invoke(TSource item, int index) => second.Invoke(first.Invoke(item, index)); } @@ -40,13 +44,15 @@ public struct SelectorSelectorAtCombination where TSelector2 : struct, IFunction { +#pragma warning disable IDE0044 // Add readonly modifier TSelector1 first; TSelector2 second; +#pragma warning restore IDE0044 // Add readonly modifier public SelectorSelectorAtCombination(TSelector1 first, TSelector2 second) => (this.first, this.second) = (first, second); - public TResult Invoke(TSource item, int index) + public readonly TResult Invoke(TSource item, int index) => second.Invoke(first.Invoke(item), index); } @@ -57,13 +63,15 @@ public struct SelectorAtSelectorAtCombination where TSelector2 : struct, IFunction { +#pragma warning disable IDE0044 // Add readonly modifier TSelector1 first; TSelector2 second; +#pragma warning restore IDE0044 // Add readonly modifier public SelectorAtSelectorAtCombination(TSelector1 first, TSelector2 second) => (this.first, this.second) = (first, second); - public TResult Invoke(TSource item, int index) + public readonly TResult Invoke(TSource item, int index) => second.Invoke(first.Invoke(item, index), index); } } diff --git a/NetFabric.Hyperlinq/Utils/Throw.cs b/NetFabric.Hyperlinq/Utils/Throw.cs index 705ae3841..26e021d5a 100644 --- a/NetFabric.Hyperlinq/Utils/Throw.cs +++ b/NetFabric.Hyperlinq/Utils/Throw.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; namespace NetFabric.Hyperlinq { @@ -7,78 +8,97 @@ namespace NetFabric.Hyperlinq static class Throw { [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static void ArgumentArraySegmentNullException(string paramName) => throw new ArgumentException(paramName: paramName, message: Resource.ArraySegmentNull); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static void ArgumentException(string paramName, string? message = default) => throw new ArgumentException(paramName: paramName, message: message); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static void ArgumentNullException(string paramName, string? message = default) => throw new ArgumentNullException(paramName: paramName, message: message); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static T ArgumentNullException(string paramName, string? message = default) => throw new ArgumentNullException(paramName: paramName, message: message); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static ref readonly T ArgumentNullExceptionRef(string paramName, string? message = default) => throw new ArgumentNullException(paramName: paramName, message: message); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static void ArgumentOutOfRangeException(string paramName, string? message = default) => throw new ArgumentOutOfRangeException(paramName: paramName, message: message); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static T ArgumentOutOfRangeException(string paramName, string? message = default) => throw new ArgumentOutOfRangeException(paramName: paramName, message: message); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static ref readonly T ArgumentOutOfRangeExceptionRef(string paramName, string? message = default) => throw new ArgumentOutOfRangeException(paramName: paramName, message: message); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static void EmptySequence() => throw new InvalidOperationException(Resource.EmptySequence); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static T EmptySequence() => throw new InvalidOperationException(Resource.EmptySequence); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static ref readonly T EmptySequenceRef() => throw new InvalidOperationException(Resource.EmptySequence); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static void NotSingleSequence() => throw new InvalidOperationException(Resource.NotSingleSequence); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static T NotSingleSequence() => throw new InvalidOperationException(Resource.NotSingleSequence); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static ref readonly T NotSingleSequenceRef() => throw new InvalidOperationException(Resource.NotSingleSequence); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static void InvalidOperationException(string? message = default) => throw new InvalidOperationException(message); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static T InvalidOperationException() => throw new InvalidOperationException(); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static void NotSupportedException() => throw new NotSupportedException(); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static T NotSupportedException() => throw new NotSupportedException(); [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] public static void ObjectDisposedException(string objectName) => throw new ObjectDisposedException(objectName); } From 59d8d4038bac098d65487e03a5e243887d755a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Wed, 1 Sep 2021 19:56:46 +0100 Subject: [PATCH 45/61] Fix Contains() and ToArray() (#376) * Fix Contains() and ToArray() #373 * Fix Contains() with custom IEqualityComparer<> --- Benchmarks/ContainsBenchmarks.md | 74 ++++---- Benchmarks/ContainsComparerBenchmarks.md | 72 ++++---- Benchmarks/ToArrayArrayPoolBenchmarks.md | 53 ++++++ Benchmarks/ToArrayBenchmarks.md | 95 +++++----- .../Benchmarks/AnyPredicateBenchmarks.cs | 4 +- .../Benchmarks/ContainsBenchmarks.cs | 2 +- .../Benchmarks/CountBenchmarks.cs | 10 +- .../Benchmarks/DistinctBenchmarks.cs | 2 + .../Benchmarks/ElementAtBenchmarks.cs | 10 +- .../Benchmarks/FirstBenchmarks.cs | 10 +- .../Benchmarks/ListIterationBenchmarks.cs | 2 + .../Benchmarks/RangeBenchmarks.cs | 2 + .../Benchmarks/ToArrayArrayPoolBenchmarks.cs | 162 ++++++++++++++++++ .../Benchmarks/ToArrayBenchmarks.cs | 2 + .../Contains.AsyncValueEnumerable.Tests.cs | 10 +- .../Contains/Contains.ReadOnlySpan.Tests.cs | 10 +- .../Contains.ValueEnumerable.Tests.cs | 10 +- .../Contains.ValueReadOnlyCollection.Tests.cs | 10 +- .../Utils/SpanExtensions.cs | 2 +- .../Utils/TestComparer.cs | 20 ++- .../Utils/Wrappers/Wrap.AsCollection.cs | 6 +- ...sAsyncValueEnumerable'1.AsyncEnumerable.cs | 15 +- ...sAsyncValueEnumerable'6.AsyncEnumerable.cs | 13 ++ .../AsValueEnumerable'1.Enumerable.cs | 27 ++- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 26 ++- .../AsValueEnumerable'1.ReadOnlyList.cs | 32 +++- .../AsValueEnumerable'1.ValueEnumerable.cs | 12 ++ ...lueEnumerable'1.ValueReadOnlyCollection.cs | 22 ++- .../AsValueEnumerable'6.Enumerable.cs | 29 ++++ .../AsValueEnumerable'6.ReadOnlyCollection.cs | 29 +++- .../AsValueEnumerable'6.ValueEnumerable.cs | 13 ++ ...lueEnumerable'6.ValueReadOnlyCollection.cs | 24 ++- .../AsValueEnumerable'6.ValueReadOnlyList.cs | 25 ++- .../AsValueEnumerable.ArraySegment.cs | 8 + .../Conversion/ToArray/ToArray.Memory.cs | 15 ++ .../ToArray/ToArray.ReadOnlyMemory.cs | 15 ++ .../ToArray/ToArray.ReadOnlySpan.cs | 8 +- .../Conversion/ToArray/ToArray.Span.cs | 15 ++ .../ToArray/ToArray.ValueEnumerable.cs | 37 ++-- .../ToArray.ValueReadOnlyCollection.cs | 48 +++--- .../Generation/AsyncValueEnumerable/Repeat.cs | 2 +- .../Generation/ValueEnumerable/Range.cs | 2 +- .../Generation/ValueEnumerable/Repeat.cs | 4 +- .../Select/SelectVector/SelectVector.Range.cs | 2 +- .../Contains/Contains.Enumerable.cs | 12 +- .../Contains/Contains.ValueEnumerable.cs | 12 +- NetFabric.Hyperlinq/Resource.Designer.cs | 51 ++---- NetFabric.Hyperlinq/Resource.resx | 2 +- NetFabric.Hyperlinq/Set/Distinct/Set.cs | 2 +- .../Utils/ArrayBuilder/LargeArrayBuilder.cs | 2 +- .../Utils/ArrayPoolExtensions.cs | 35 ++-- NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs | 2 +- .../Utils/Utils.EqualityComparer.cs | 3 +- 53 files changed, 814 insertions(+), 298 deletions(-) create mode 100644 Benchmarks/ToArrayArrayPoolBenchmarks.md create mode 100644 NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs create mode 100644 NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs create mode 100644 NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs create mode 100644 NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs diff --git a/Benchmarks/ContainsBenchmarks.md b/Benchmarks/ContainsBenchmarks.md index 2efe03098..b079eda6c 100644 --- a/Benchmarks/ContainsBenchmarks.md +++ b/Benchmarks/ContainsBenchmarks.md @@ -4,51 +4,51 @@ [ContainsBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.0.1561-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + Job-PWZZUK : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 39.09 ns | 0.295 ns | 0.262 ns | 1.00 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 30.28 ns | 0.204 ns | 0.181 ns | 0.77 | - | - | - | - | -| Hyperlinq_Array_SIMD | Array | 100 | 23.08 ns | 0.070 ns | 0.066 ns | 0.59 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 630.38 ns | 3.890 ns | 3.449 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 213.68 ns | 2.687 ns | 2.382 ns | 0.34 | 0.0191 | - | - | 40 B | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 36.47 ns | 0.259 ns | 0.230 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 37.04 ns | 0.240 ns | 0.200 ns | 1.02 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 37.53 ns | 0.226 ns | 0.201 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 40.39 ns | 0.201 ns | 0.178 ns | 1.08 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,633.17 ns | 6.551 ns | 6.128 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 948.62 ns | 2.231 ns | 1.978 ns | 0.58 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 628.50 ns | 3.975 ns | 3.719 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 758.41 ns | 6.989 ns | 6.537 ns | 1.21 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 36.32 ns | 0.205 ns | 0.192 ns | 1.00 | - | - | - | - | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 35.42 ns | 0.170 ns | 0.159 ns | 0.98 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 37.41 ns | 0.137 ns | 0.121 ns | 1.00 | - | - | - | - | -| Hyperlinq_List_Reference | List_Reference | 100 | 40.65 ns | 0.173 ns | 0.154 ns | 1.09 | - | - | - | - | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,630.05 ns | 6.055 ns | 5.368 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,749.10 ns | 5.811 ns | 4.537 ns | 1.07 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|-------------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 40.84 ns | 0.155 ns | 0.137 ns | baseline | | - | - | - | - | +| Hyperlinq_Array | Array | 100 | 39.48 ns | 0.544 ns | 0.509 ns | 1.04x faster | 0.01x | - | - | - | - | +| Hyperlinq_Array_SIMD | Array | 100 | 24.73 ns | 0.106 ns | 0.094 ns | 1.65x faster | 0.01x | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 698.87 ns | 4.071 ns | 3.808 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 131.79 ns | 0.836 ns | 0.699 ns | 5.30x faster | 0.04x | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 41.31 ns | 0.190 ns | 0.178 ns | baseline | | - | - | - | - | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 48.15 ns | 0.182 ns | 0.161 ns | 1.17x slower | 0.01x | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 42.47 ns | 0.369 ns | 0.327 ns | baseline | | - | - | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 48.39 ns | 0.315 ns | 0.263 ns | 1.14x slower | 0.01x | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,117.62 ns | 24.109 ns | 22.552 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,065.50 ns | 3.295 ns | 2.572 ns | 1.99x faster | 0.02x | - | - | - | - | +| | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 701.55 ns | 11.099 ns | 9.839 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 723.25 ns | 3.170 ns | 2.965 ns | 1.03x slower | 0.01x | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 44.63 ns | 0.412 ns | 0.344 ns | baseline | | - | - | - | - | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 46.06 ns | 0.179 ns | 0.140 ns | 1.03x slower | 0.01x | - | - | - | - | +| | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 44.93 ns | 0.386 ns | 0.342 ns | baseline | | - | - | - | - | +| Hyperlinq_List_Reference | List_Reference | 100 | 47.14 ns | 0.188 ns | 0.167 ns | 1.05x slower | 0.01x | - | - | - | - | +| | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,104.73 ns | 7.920 ns | 6.183 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,061.42 ns | 4.170 ns | 3.697 ns | 1.02x faster | 0.00x | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ContainsComparerBenchmarks.md b/Benchmarks/ContainsComparerBenchmarks.md index d231f742c..16391d05b 100644 --- a/Benchmarks/ContainsComparerBenchmarks.md +++ b/Benchmarks/ContainsComparerBenchmarks.md @@ -4,50 +4,50 @@ [ContainsComparerBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsComparerBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.0.1561-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + Job-AXHCLI : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|--------:|--------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 572.5 ns | 2.79 ns | 2.33 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Array | Array | 100 | 197.9 ns | 0.70 ns | 0.55 ns | 0.35 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 793.3 ns | 4.90 ns | 4.34 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 281.1 ns | 1.73 ns | 1.54 ns | 0.35 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 786.9 ns | 3.22 ns | 2.68 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 281.9 ns | 0.96 ns | 0.80 ns | 0.36 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 781.4 ns | 5.11 ns | 4.78 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Value | List_Value | 100 | 769.3 ns | 3.61 ns | 3.37 ns | 0.98 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,720.2 ns | 3.38 ns | 3.16 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 933.5 ns | 1.89 ns | 1.67 ns | 0.54 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 797.8 ns | 8.44 ns | 7.48 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 782.4 ns | 3.13 ns | 2.77 ns | 0.98 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 781.4 ns | 3.37 ns | 3.15 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 787.2 ns | 3.71 ns | 3.29 ns | 1.01 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 787.1 ns | 2.73 ns | 2.42 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 774.0 ns | 6.55 ns | 5.47 ns | 0.98 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,728.8 ns | 3.36 ns | 2.81 ns | 1.00 | 0.0153 | - | - | 32 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,720.0 ns | 5.65 ns | 5.28 ns | 0.99 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|-----------:|-----------:|------------:|--------------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 1,048.66 ns | 107.295 ns | 316.361 ns | 903.87 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_Array | Array | 100 | 268.14 ns | 2.061 ns | 1.827 ns | 267.28 ns | 4.81x faster | 1.19x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 881.92 ns | 6.470 ns | 5.735 ns | 880.29 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 302.87 ns | 1.992 ns | 1.864 ns | 302.07 ns | 2.91x faster | 0.03x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 938.13 ns | 9.760 ns | 9.129 ns | 936.36 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 48.95 ns | 0.239 ns | 0.212 ns | 48.90 ns | 19.18x faster | 0.20x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 933.26 ns | 9.635 ns | 8.046 ns | 929.66 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Value | List_Value | 100 | 48.66 ns | 0.173 ns | 0.144 ns | 48.65 ns | 19.18x faster | 0.20x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,158.84 ns | 9.131 ns | 8.542 ns | 2,155.35 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,191.03 ns | 3.012 ns | 2.670 ns | 1,189.75 ns | 1.81x faster | 0.01x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 882.52 ns | 5.452 ns | 4.833 ns | 881.50 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 857.25 ns | 3.404 ns | 2.842 ns | 856.86 ns | 1.03x faster | 0.01x | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 889.74 ns | 13.979 ns | 12.392 ns | 887.60 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 47.00 ns | 0.515 ns | 0.457 ns | 46.82 ns | 18.93x faster | 0.31x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 932.31 ns | 6.806 ns | 5.314 ns | 930.35 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 47.98 ns | 0.277 ns | 0.217 ns | 47.97 ns | 19.43x faster | 0.10x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,159.99 ns | 7.158 ns | 6.695 ns | 2,158.15 ns | baseline | | 0.0153 | - | - | 32 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,157.65 ns | 6.057 ns | 5.369 ns | 2,156.09 ns | 1.00x faster | 0.00x | 0.0153 | - | - | 32 B | diff --git a/Benchmarks/ToArrayArrayPoolBenchmarks.md b/Benchmarks/ToArrayArrayPoolBenchmarks.md new file mode 100644 index 000000000..57c8f6341 --- /dev/null +++ b/Benchmarks/ToArrayArrayPoolBenchmarks.md @@ -0,0 +1,53 @@ +## ToArrayArrayPoolBenchmarks + +### Source +[ToArrayArrayPoolBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs) + +### References: +- Linq: 6.0.0-preview.7.21377.19 +- System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) +- System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) +- System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) + +### Results: +``` ini + +BenchmarkDotNet=v0.13.0.1561-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + Job-WKXHDN : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + +Runtime=.NET 6.0 + +``` +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------------------------------------- |-------------------------- |------ |------------:|----------:|----------:|-------------:|--------:|-------:|------:|------:|----------:| +| Hyperlinq_Array | Array | 100 | 71.55 ns | 0.539 ns | 0.504 ns | baseline | | 0.2027 | - | - | 424 B | +| Hyperlinq_Array_ArrayPool | Array | 100 | 88.19 ns | 1.409 ns | 1.249 ns | 1.23x slower | 0.02x | - | - | - | - | +| | | | | | | | | | | | | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 574.98 ns | 6.409 ns | 5.681 ns | baseline | | 0.2022 | - | - | 424 B | +| Hyperlinq_Enumerable_Value_ArrayPool | Enumerable_Value | 100 | 592.11 ns | 11.686 ns | 12.000 ns | 1.03x slower | 0.02x | - | - | - | - | +| | | | | | | | | | | | | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 194.76 ns | 2.327 ns | 1.943 ns | baseline | | 0.2217 | - | - | 464 B | +| Hyperlinq_Collection_Value_ArrayPool | Collection_Value | 100 | 198.94 ns | 3.513 ns | 3.286 ns | 1.02x slower | 0.02x | 0.0191 | - | - | 40 B | +| | | | | | | | | | | | | +| Hyperlinq_List_Value | List_Value | 100 | 81.78 ns | 1.630 ns | 1.878 ns | baseline | | 0.2142 | - | - | 448 B | +| Hyperlinq_List_Value_ArrayPool | List_Value | 100 | 90.87 ns | 1.200 ns | 1.064 ns | 1.11x slower | 0.03x | 0.0114 | - | - | 24 B | +| | | | | | | | | | | | | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,581.94 ns | 7.917 ns | 6.611 ns | baseline | | 0.5646 | - | - | 1,184 B | +| Hyperlinq_AsyncEnumerable_Value_ArrayPool | AsyncEnumerable_Value | 100 | 1,595.35 ns | 9.042 ns | 7.550 ns | 1.01x slower | 0.01x | 0.3624 | - | - | 760 B | +| | | | | | | | | | | | | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,176.25 ns | 9.371 ns | 8.766 ns | baseline | | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference_ArrayPool | Enumerable_Reference | 100 | 1,160.29 ns | 16.363 ns | 15.306 ns | 1.01x faster | 0.02x | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 85.97 ns | 1.027 ns | 0.961 ns | baseline | | 0.2142 | - | - | 448 B | +| Hyperlinq_Collection_Reference_ArrayPool | Collection_Reference | 100 | 96.72 ns | 1.965 ns | 2.103 ns | 1.12x slower | 0.02x | 0.0114 | - | - | 24 B | +| | | | | | | | | | | | | +| Hyperlinq_List_Reference | List_Reference | 100 | 81.42 ns | 1.266 ns | 1.184 ns | baseline | | 0.2142 | - | - | 448 B | +| Hyperlinq_List_Reference_ArrayPool | List_Reference | 100 | 90.73 ns | 1.831 ns | 1.880 ns | 1.11x slower | 0.02x | 0.0114 | - | - | 24 B | +| | | | | | | | | | | | | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,605.91 ns | 11.347 ns | 10.614 ns | baseline | | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference_ArrayPool | AsyncEnumerable_Reference | 100 | 2,670.44 ns | 37.433 ns | 35.015 ns | 1.02x slower | 0.01x | 0.3777 | - | - | 792 B | diff --git a/Benchmarks/ToArrayBenchmarks.md b/Benchmarks/ToArrayBenchmarks.md index 44bf8d0f7..b742acf96 100644 --- a/Benchmarks/ToArrayBenchmarks.md +++ b/Benchmarks/ToArrayBenchmarks.md @@ -4,57 +4,66 @@ [ToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.0.1561-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + Job-NRTSBV : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 51.99 ns | 0.388 ns | 0.344 ns | 51.98 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Array | Array | 100 | 88.24 ns | 1.817 ns | 3.671 ns | 86.44 ns | 1.80 | 0.05 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 38.94 ns | 0.855 ns | 2.222 ns | 37.84 ns | 0.72 | 0.03 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 938.66 ns | 5.905 ns | 5.523 ns | 939.96 ns | 1.00 | 0.00 | 0.5646 | - | - | 1,184 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 914.83 ns | 18.130 ns | 20.152 ns | 926.03 ns | 0.97 | 0.03 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 553.19 ns | 2.745 ns | 2.433 ns | 553.33 ns | 0.59 | 0.00 | 0.2213 | - | - | 464 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 50.42 ns | 0.667 ns | 0.591 ns | 50.51 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 893.83 ns | 4.701 ns | 3.926 ns | 893.72 ns | 17.75 | 0.21 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 122.53 ns | 2.136 ns | 1.998 ns | 121.88 ns | 2.43 | 0.05 | 0.2217 | - | - | 464 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 47.30 ns | 0.782 ns | 0.732 ns | 47.49 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Value | List_Value | 100 | 248.65 ns | 1.309 ns | 1.225 ns | 248.55 ns | 5.26 | 0.08 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 64.00 ns | 0.635 ns | 0.594 ns | 64.08 ns | 1.35 | 0.02 | 0.2142 | - | - | 448 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,936.42 ns | 7.609 ns | 6.745 ns | 1,934.24 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,163.24 ns | 4.662 ns | 4.133 ns | 1,162.48 ns | 0.60 | 0.00 | 0.5646 | - | - | 1,184 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,010.97 ns | 7.290 ns | 6.819 ns | 1,009.86 ns | 1.00 | 0.00 | 0.5655 | - | - | 1,184 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 892.07 ns | 4.902 ns | 3.827 ns | 891.46 ns | 0.88 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 983.87 ns | 4.211 ns | 3.733 ns | 983.44 ns | 0.97 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 45.61 ns | 0.839 ns | 0.784 ns | 45.79 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 933.35 ns | 14.980 ns | 13.279 ns | 937.10 ns | 20.49 | 0.49 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 57.47 ns | 1.221 ns | 2.973 ns | 57.08 ns | 1.28 | 0.06 | 0.2142 | - | - | 448 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 46.85 ns | 0.781 ns | 0.731 ns | 46.91 ns | 1.00 | 0.00 | 0.2027 | - | - | 424 B | -| StructLinq_List_Reference | List_Reference | 100 | 894.50 ns | 5.397 ns | 4.784 ns | 894.58 ns | 19.05 | 0.28 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 58.53 ns | 0.781 ns | 0.730 ns | 58.43 ns | 1.25 | 0.02 | 0.2142 | - | - | 448 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,937.50 ns | 6.890 ns | 5.379 ns | 1,938.36 ns | 1.00 | 0.00 | 0.7668 | - | - | 1,608 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,987.66 ns | 5.304 ns | 4.702 ns | 1,987.87 ns | 1.03 | 0.00 | 0.5798 | - | - | 1,216 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------------------------------------- |-------------------------- |------ |------------:|-----------:|------------:|------------:|--------------:|--------:|-------:|------:|------:|----------:| +| Linq_Array | Array | 100 | 163.04 ns | 17.071 ns | 48.43 ns | 151.20 ns | baseline | | 0.2027 | - | - | 424 B | +| StructLinq_Array | Array | 100 | 306.86 ns | 14.754 ns | 43.04 ns | 310.49 ns | 2.04x slower | 0.59x | 0.2027 | - | - | 424 B | +| Hyperlinq_Array | Array | 100 | 88.98 ns | 6.099 ns | 17.98 ns | 84.58 ns | 1.86x faster | 0.65x | 0.2027 | - | - | 424 B | +| Hyperlinq_Array_ArrayPool | Array | 100 | 163.95 ns | 14.690 ns | 41.43 ns | 148.74 ns | 1.09x slower | 0.41x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 2,354.70 ns | 237.865 ns | 701.35 ns | 2,088.55 ns | baseline | | 0.5646 | - | - | 1,184 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 3,409.14 ns | 191.945 ns | 553.80 ns | 3,355.16 ns | 1.56x slower | 0.51x | 0.2136 | - | - | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1,247.87 ns | 116.048 ns | 342.17 ns | 1,124.28 ns | 2.01x faster | 0.76x | 0.2213 | - | - | 464 B | +| Hyperlinq_Enumerable_Value_ArrayPool | Enumerable_Value | 100 | 1,262.16 ns | 153.002 ns | 431.54 ns | 1,170.54 ns | 2.03x faster | 0.72x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 128.85 ns | 12.178 ns | 35.52 ns | 114.80 ns | baseline | | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 2,101.36 ns | 175.955 ns | 518.81 ns | 1,884.01 ns | 17.03x slower | 5.13x | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 348.20 ns | 27.074 ns | 78.55 ns | 326.34 ns | 2.87x slower | 0.91x | 0.2213 | - | - | 464 B | +| Hyperlinq_Collection_Value_ArrayPool | Collection_Value | 100 | 420.59 ns | 39.264 ns | 112.66 ns | 408.15 ns | 3.54x slower | 1.46x | - | - | - | - | +| | | | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 136.70 ns | 14.382 ns | 42.41 ns | 121.74 ns | baseline | | 0.2027 | - | - | 424 B | +| StructLinq_List_Value | List_Value | 100 | 654.04 ns | 57.795 ns | 170.41 ns | 569.22 ns | 5.25x slower | 2.10x | 0.2022 | - | - | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 141.58 ns | 14.635 ns | 41.04 ns | 133.28 ns | 1.09x slower | 0.42x | 0.2136 | - | - | 448 B | +| Hyperlinq_List_Value_ArrayPool | List_Value | 100 | 2,639.47 ns | 343.889 ns | 969.94 ns | 2,341.53 ns | 20.96x slower | 10.56x | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,433.84 ns | 280.479 ns | 818.17 ns | 4,172.04 ns | baseline | | 0.7668 | - | - | 1,608 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,986.15 ns | 210.448 ns | 607.19 ns | 2,804.33 ns | 1.55x faster | 0.43x | 0.5646 | - | - | 1,184 B | +| Hyperlinq_AsyncEnumerable_Value_ArrayPool | AsyncEnumerable_Value | 100 | 4,198.43 ns | 440.451 ns | 1,205.73 ns | 3,826.17 ns | 1.15x faster | 0.35x | 0.3624 | - | - | 760 B | +| | | | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2,189.65 ns | 194.003 ns | 572.02 ns | 1,999.68 ns | baseline | | 0.5646 | - | - | 1,184 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2,393.79 ns | 227.705 ns | 671.39 ns | 2,364.41 ns | 1.17x slower | 0.46x | 0.2136 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2,799.73 ns | 284.878 ns | 821.94 ns | 2,585.37 ns | 1.34x slower | 0.49x | 0.2174 | - | - | 456 B | +| Hyperlinq_Enumerable_Reference_ArrayPool | Enumerable_Reference | 100 | 2,360.88 ns | 161.513 ns | 476.22 ns | 2,396.03 ns | 1.14x slower | 0.34x | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 115.65 ns | 8.905 ns | 25.41 ns | 106.26 ns | baseline | | 0.2027 | - | - | 424 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 2,091.15 ns | 217.124 ns | 640.19 ns | 1,745.16 ns | 19.18x slower | 7.50x | 0.2174 | - | - | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 193.10 ns | 25.659 ns | 74.03 ns | 171.64 ns | 1.75x slower | 0.72x | 0.2141 | - | - | 448 B | +| Hyperlinq_Collection_Reference_ArrayPool | Collection_Reference | 100 | 1,402.92 ns | 105.127 ns | 309.97 ns | 1,237.28 ns | 12.84x slower | 3.86x | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 164.70 ns | 13.638 ns | 40.21 ns | 161.30 ns | baseline | | 0.2027 | - | - | 424 B | +| StructLinq_List_Reference | List_Reference | 100 | 2,247.33 ns | 206.354 ns | 601.94 ns | 2,141.67 ns | 14.50x slower | 5.23x | 0.2174 | - | - | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 155.51 ns | 19.107 ns | 55.13 ns | 143.08 ns | 1.00x slower | 0.40x | 0.2142 | - | - | 448 B | +| Hyperlinq_List_Reference_ArrayPool | List_Reference | 100 | 1,517.09 ns | 120.567 ns | 355.49 ns | 1,462.84 ns | 9.78x slower | 3.37x | 0.0153 | - | - | 32 B | +| | | | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,261.83 ns | 271.077 ns | 790.75 ns | 5,092.51 ns | baseline | | 0.7629 | - | - | 1,608 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,319.42 ns | 795.422 ns | 2,320.28 ns | 5,607.97 ns | 1.22x slower | 0.46x | 0.5798 | - | - | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference_ArrayPool | AsyncEnumerable_Reference | 100 | 4,795.02 ns | 619.269 ns | 1,746.66 ns | 4,093.43 ns | 1.19x faster | 0.33x | 0.3738 | - | - | 792 B | diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs index 9fa4e28de..2debd4f30 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/AnyPredicateBenchmarks.cs @@ -85,7 +85,7 @@ public bool Hyperlinq_List_Value() public ValueTask Hyperlinq_AsyncEnumerable_Value() => asyncEnumerableValue .AsAsyncValueEnumerable() - .AnyAsync((item, _) => new ValueTask((item & 0x01) == 0)); + .AnyAsync((_, _) => default); [BenchmarkCategory("Enumerable_Reference")] [Benchmark] @@ -113,6 +113,6 @@ public bool Hyperlinq_List_Reference() public ValueTask Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() - .AnyAsync((item, _) => new ValueTask((item & 0x01) == 0)); + .AnyAsync((_, _) => default); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs index 504b607f9..acd3ad7e4 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ContainsBenchmarks.cs @@ -22,7 +22,7 @@ public bool Linq_Enumerable_Value() [BenchmarkCategory("Collection_Value")] [Benchmark(Baseline = true)] public bool Linq_Collection_Value() - => Enumerable.Contains(collectionValue, Count - 1); + => collectionValue.Contains(Count - 1); [BenchmarkCategory("List_Value")] [Benchmark(Baseline = true)] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs index 6ea55184e..42cafd441 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/CountBenchmarks.cs @@ -111,18 +111,22 @@ public int StructLinq_List_Reference() [BenchmarkCategory("Array")] [Benchmark] public int Hyperlinq_Array() - => array.AsValueEnumerable().Count(); + => array + .AsValueEnumerable() + .Count(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public int Hyperlinq_Enumerable_Value() - => enumerableValue.AsValueEnumerable() + => enumerableValue + .AsValueEnumerable() .Count(); [BenchmarkCategory("Collection_Value")] [Benchmark] public int Hyperlinq_Collection_Value() - => collectionValue.AsValueEnumerable() + => collectionValue + .AsValueEnumerable() .Count(); [BenchmarkCategory("List_Value")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs index e3da04835..ede1a3a8d 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/DistinctBenchmarks.cs @@ -4,6 +4,8 @@ using System; using System.Linq; using System.Threading.Tasks; +// ReSharper disable ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator +// ReSharper disable LoopCanBeConvertedToQuery namespace NetFabric.Hyperlinq.Benchmarks { diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs index 42bf8369c..1d525448f 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ElementAtBenchmarks.cs @@ -59,18 +59,22 @@ public ValueTask Linq_AsyncEnumerable_Reference() [BenchmarkCategory("Array")] [Benchmark] public Option Hyperlinq_Array() - => array.AsValueEnumerable().ElementAt(Count - 1); + => array + .AsValueEnumerable() + .ElementAt(Count - 1); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public Option Hyperlinq_Enumerable_Value() - => enumerableValue.AsValueEnumerable() + => enumerableValue + .AsValueEnumerable() .ElementAt(Count - 1); [BenchmarkCategory("Collection_Value")] [Benchmark] public Option Hyperlinq_Collection_Value() - => collectionValue.AsValueEnumerable() + => collectionValue + .AsValueEnumerable() .ElementAt(Count - 1); [BenchmarkCategory("List_Value")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs index a1d579f19..8c31d799d 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/FirstBenchmarks.cs @@ -59,18 +59,22 @@ public ValueTask Linq_AsyncEnumerable_Reference() [BenchmarkCategory("Array")] [Benchmark] public Option Hyperlinq_Array() - => array.AsValueEnumerable().First(); + => array + .AsValueEnumerable() + .First(); [BenchmarkCategory("Enumerable_Value")] [Benchmark] public Option Hyperlinq_Enumerable_Value() - => enumerableValue.AsValueEnumerable() + => enumerableValue + .AsValueEnumerable() .First(); [BenchmarkCategory("Collection_Value")] [Benchmark] public Option Hyperlinq_Collection_Value() - => collectionValue.AsValueEnumerable() + => collectionValue + .AsValueEnumerable() .First(); [BenchmarkCategory("List_Value")] diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs index 0b1112e3a..d3d495f81 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ListIterationBenchmarks.cs @@ -6,6 +6,8 @@ using System.Collections.Immutable; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +// ReSharper disable ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator +// ReSharper disable ForCanBeConvertedToForeach namespace NetFabric.Hyperlinq.Benchmarks.Benchmarks { diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs index a7f454b18..33735309d 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeBenchmarks.cs @@ -3,6 +3,8 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; +// ReSharper disable ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator +// ReSharper disable LoopCanBeConvertedToQuery namespace NetFabric.Hyperlinq.Benchmarks { diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs new file mode 100644 index 000000000..cf564b9bf --- /dev/null +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs @@ -0,0 +1,162 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using StructLinq; +using System.Buffers; +using System.Linq; +using System.Threading.Tasks; + +namespace NetFabric.Hyperlinq.Benchmarks +{ + [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] + [CategoriesColumn] + public class ToArrayArrayPoolBenchmarks: RandomBenchmarksBase + { + + [BenchmarkCategory("Array")] + [Benchmark(Baseline = true)] + public int Hyperlinq_Array() + { + var values = array.AsValueEnumerable().ToArray(); + return values.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("Enumerable_Value")] + [Benchmark(Baseline = true)] + public int Hyperlinq_Enumerable_Value() + { + var values = enumerableValue.AsValueEnumerable().ToArray(); + return values.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("Collection_Value")] + [Benchmark(Baseline = true)] + public int Hyperlinq_Collection_Value() + { + var values = collectionValue.AsValueEnumerable().ToArray(); + return values.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("List_Value")] + [Benchmark(Baseline = true)] + public int Hyperlinq_List_Value() + { + var values = listValue.AsValueEnumerable().ToArray(); + return values.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark(Baseline = true)] + public async ValueTask Hyperlinq_AsyncEnumerable_Value() + { + var values = await asyncEnumerableValue.AsAsyncValueEnumerable().ToArrayAsync(); + return values.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark(Baseline = true)] + public int Hyperlinq_Enumerable_Reference() + { + var values = enumerableReference.AsValueEnumerable().ToArray(); + return values.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("Collection_Reference")] + [Benchmark(Baseline = true)] + public int Hyperlinq_Collection_Reference() + { + var values = collectionReference.AsValueEnumerable().ToArray(); + return values.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("List_Reference")] + [Benchmark(Baseline = true)] + public int Hyperlinq_List_Reference() + { + var values = listReference.AsValueEnumerable().ToArray(); + return values.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark(Baseline = true)] + public async ValueTask Hyperlinq_AsyncEnumerable_Reference() + { + var values = await asyncEnumerableReference.AsAsyncValueEnumerable().ToArrayAsync(); + return values.AsValueEnumerable().Sum(); + } + + // --------------------------------------------------------------------- + + [BenchmarkCategory("Array")] + [Benchmark] + public int Hyperlinq_Array_ArrayPool() + { + using var values = array.AsValueEnumerable().ToArray(ArrayPool.Shared); + return values.Memory.Span.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("Enumerable_Value")] + [Benchmark] + public int Hyperlinq_Enumerable_Value_ArrayPool() + { + using var values = enumerableValue.AsValueEnumerable().ToArray(ArrayPool.Shared); + return values.Memory.Span.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("Collection_Value")] + [Benchmark] + public int Hyperlinq_Collection_Value_ArrayPool() + { + using var values = collectionValue.AsValueEnumerable().ToArray(ArrayPool.Shared); + return values.Memory.Span.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("List_Value")] + [Benchmark] + public int Hyperlinq_List_Value_ArrayPool() + { + using var values = listValue.AsValueEnumerable().ToArray(ArrayPool.Shared); + return values.Memory.Span.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public async ValueTask Hyperlinq_AsyncEnumerable_Value_ArrayPool() + { + using var values = await asyncEnumerableValue.AsAsyncValueEnumerable().ToArrayAsync(ArrayPool.Shared); + return values.Memory.Span.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark] + public int Hyperlinq_Enumerable_Reference_ArrayPool() + { + using var values = enumerableReference.AsValueEnumerable().ToArray(ArrayPool.Shared); + return values.Memory.Span.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("Collection_Reference")] + [Benchmark] + public int Hyperlinq_Collection_Reference_ArrayPool() + { + using var values = collectionReference.AsValueEnumerable().ToArray(ArrayPool.Shared); + return values.Memory.Span.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("List_Reference")] + [Benchmark] + public int Hyperlinq_List_Reference_ArrayPool() + { + using var values = listReference.AsValueEnumerable().ToArray(ArrayPool.Shared); + return values.Memory.Span.AsValueEnumerable().Sum(); + } + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public async ValueTask Hyperlinq_AsyncEnumerable_Reference_ArrayPool() + { + using var values = await asyncEnumerableReference.AsAsyncValueEnumerable().ToArrayAsync(ArrayPool.Shared); + return values.Memory.Span.AsValueEnumerable().Sum(); + } + + } +} diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs index b25edc3b4..fa8a993fe 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs @@ -1,6 +1,7 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using StructLinq; +using System.Buffers; using System.Linq; using System.Threading.Tasks; @@ -10,6 +11,7 @@ namespace NetFabric.Hyperlinq.Benchmarks [CategoriesColumn] public class ToArrayBenchmarks: RandomBenchmarksBase { + [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int[] Linq_Array() diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs index b5ba9b1ea..a376e4705 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs @@ -138,16 +138,19 @@ public async ValueTask ContainsAsync_With_Comparer_And_NotContains_Must_ReturnFa { // Arrange const int value = int.MaxValue; + var comparer = new TestComparer(); var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act var result = await wrapped.AsAsyncValueEnumerable() - .ContainsAsync(value, TestComparer.Instance) + .ContainsAsync(value, comparer) .ConfigureAwait(false); // Assert _ = result.Must() .BeFalse(); + _ = comparer.EqualsCounter.Must() + .BeEqualTo(source.Length); } [Theory] @@ -158,16 +161,19 @@ public async ValueTask ContainsAsync_With_Comparer_And_Contains_Must_ReturnTrue( // Arrange var value = source .Last(); + var comparer = new TestComparer(); var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act var result = await wrapped.AsAsyncValueEnumerable() - .ContainsAsync(value, TestComparer.Instance) + .ContainsAsync(value, comparer) .ConfigureAwait(false); // Assert _ = result.Must() .BeTrue(); + _ = comparer.EqualsCounter.Must() + .BeEqualTo(source.Length); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs index 84ba5871c..63e3ff40b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs @@ -127,15 +127,18 @@ public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source { // Arrange const int value = int.MaxValue; + var comparer = new TestComparer(); var wrapped = (ReadOnlySpan)source.AsSpan(); // Act var result = wrapped.AsValueEnumerable() - .Contains(value, TestComparer.Instance); + .Contains(value, comparer); // Assert _ = result.Must() .BeFalse(); + _ = comparer.EqualsCounter.Must() + .BeEqualTo(source.Length); } [Theory] @@ -145,15 +148,18 @@ public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange var value = source.Last(); + var comparer = new TestComparer(); var wrapped = (ReadOnlySpan)source.AsSpan(); // Act var result = wrapped.AsValueEnumerable() - .Contains(value, TestComparer.Instance); + .Contains(value, comparer); // Assert _ = result.Must() .BeTrue(); + _ = comparer.EqualsCounter.Must() + .BeEqualTo(source.Length); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs index 0d78459f4..3aaf3b99c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs @@ -130,15 +130,18 @@ public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source { // Arrange const int value = int.MaxValue; + var comparer = new TestComparer(); var wrapped = Wrap.AsValueEnumerable(source); // Act var result = wrapped - .Contains, Wrap.Enumerator, int>(value, TestComparer.Instance); + .Contains, Wrap.Enumerator, int>(value, comparer); // Assert _ = result.Must() .BeFalse(); + _ = comparer.EqualsCounter.Must() + .BeEqualTo(source.Length); } [Theory] @@ -149,15 +152,18 @@ public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) // Arrange var value = source .Last(); + var comparer = new TestComparer(); var wrapped = Wrap.AsValueEnumerable(source); // Act var result = wrapped - .Contains, Wrap.Enumerator, int>(value, TestComparer.Instance); + .Contains, Wrap.Enumerator, int>(value, comparer); // Assert _ = result.Must() .BeTrue(); + _ = comparer.EqualsCounter.Must() + .BeEqualTo(source.Length); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs index db485b9a7..aba068ab1 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs @@ -130,15 +130,18 @@ public void Contains_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source { // Arrange const int value = int.MaxValue; + var comparer = new TestComparer(); var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act var result = wrapped.AsValueEnumerable() - .Contains(value, TestComparer.Instance); + .Contains(value, comparer); // Assert _ = result.Must() .BeFalse(); + _ = comparer.EqualsCounter.Must() + .BeEqualTo(source.Length); } [Theory] @@ -149,15 +152,18 @@ public void Contains_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) // Arrange var value = source .Last(); + var comparer = new TestComparer(); var wrapped = Wrap.AsValueReadOnlyCollection(source); // Act var result = wrapped.AsValueEnumerable() - .Contains(value, TestComparer.Instance); + .Contains(value, comparer); // Assert _ = result.Must() .BeTrue(); + _ = comparer.EqualsCounter.Must() + .BeEqualTo(source.Length); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs b/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs index 35bd6a456..a701931f8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs @@ -20,7 +20,7 @@ public static bool SequenceEqual(this Span first, IEnumerable second, I public static bool SequenceEqual(this ReadOnlySpan first, IEnumerable second, IEqualityComparer? comparer = default) { - if (Utils.UseDefault(comparer)) + if (Utils.IsValueType() && Utils.UseDefault(comparer)) { using var enumerator = second.GetEnumerator(); for (var index = 0; true; index++) diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs b/NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs index 4286316a1..8bfa97648 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs @@ -5,15 +5,19 @@ namespace NetFabric.Hyperlinq.UnitTests { class TestComparer : IEqualityComparer { - TestComparer() { } + public int EqualsCounter { get; private set; } + public int GetHashCodeCounter { get; private set; } - public static TestComparer Instance { get; } - = new(); + public bool Equals(T? x, T? y) + { + EqualsCounter++; + return EqualityComparer.Default.Equals(x, y); + } - public bool Equals(T? x, T? y) - => EqualityComparer.Default.Equals(x, y); - - public int GetHashCode([DisallowNull]T obj) - => EqualityComparer.Default.GetHashCode(obj); + public int GetHashCode([DisallowNull] T obj) + { + GetHashCodeCounter++; + return EqualityComparer.Default.GetHashCode(obj); + } } } diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs index 6304e9481..b9ebad3f9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs @@ -23,13 +23,13 @@ internal CollectionWrapper(T[] source) : base(source) { } - public bool IsReadOnly + bool ICollection.IsReadOnly => true; - public void CopyTo(T[] array, int arrayIndex) + void ICollection.CopyTo(T[] array, int arrayIndex) => source.CopyTo(array, arrayIndex); - public bool Contains(T item) + bool ICollection.Contains(T item) => ((ICollection)source).Contains(item); void ICollection.Add(T item) diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs index f9118a93b..3c2fdac47 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Buffers; +using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; @@ -62,6 +63,18 @@ public AsyncValueEnumerable AsAsyncValueEnumerable() public IAsyncEnumerable AsAsyncEnumerable() => source; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask ToArrayAsync() + => this.ToArrayAsync, AsyncEnumerator, TSource>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + => this.ToArrayAsync, AsyncEnumerator, TSource>(pool, cancellationToken, clearOnDispose); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask> ToListAsync() + => this.ToListAsync, AsyncEnumerator, TSource>(); + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs index c4ae76d5d..791bbfc2a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -77,6 +78,18 @@ public AsyncValueEnumerable source; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask ToArrayAsync() + => this.ToArrayAsync, TEnumerator, TSource>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + => this.ToArrayAsync, TEnumerator, TSource>(pool, cancellationToken, clearOnDispose); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueTask> ToListAsync() + => this.ToListAsync, TEnumerator, TSource>(); + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs index 2065bd521..14cda05d5 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System.Buffers; +using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -39,6 +40,30 @@ public ValueEnumerable AsValueEnumerable() public IEnumerable AsEnumerable() => source; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TSource[] ToArray() + => this.ToArray, ValueEnumerator, TSource>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => this.ToArray, ValueEnumerator, TSource>(pool, clearOnDispose); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => this.ToList, ValueEnumerator, TSource>(); + + #endregion + + #region Quantifier + + public bool Contains(TSource value, IEqualityComparer? comparer = default) + { + if (Utils.UseDefault(comparer) && source is ICollection collection) + return collection.Contains(value); + + return this.Contains, ValueEnumerator, TSource>(value, comparer); + } + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index 1cf6cf678..fc14604c5 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -71,12 +72,8 @@ public void CopyTo(TSource[] array, int arrayIndex) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; + bool ICollection.Contains(TSource item) + => Contains(item, default); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -96,13 +93,24 @@ public ValueEnumerable AsValueEnumerable() public IReadOnlyCollection AsEnumerable() => source; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TSource[] ToArray() + => ValueReadOnlyCollectionExtensions.ToArray, ValueEnumerator, TSource>(this); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ValueReadOnlyCollectionExtensions.ToArray, ValueEnumerator, TSource>(this, pool, clearOnDispose); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => ValueReadOnlyCollectionExtensions.ToList, ValueEnumerator, TSource>(this); + #endregion #region Quantifier - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer) + public bool Contains(TSource value, IEqualityComparer? comparer = default) => Count is not 0 && source.Contains(value, comparer); - + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs index cbc18a5b3..4a3a9f374 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -82,9 +83,11 @@ public void CopyTo(TSource[] array, int arrayIndex) { switch (source) { + // ReSharper disable once HeapView.PossibleBoxingAllocation case ICollection collection: collection.CopyTo(array, arrayIndex); break; + default: CopyTo(array.AsSpan(arrayIndex)); break; @@ -92,14 +95,16 @@ public void CopyTo(TSource[] array, int arrayIndex) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => Count is not 0 && source.Contains(item); + bool ICollection.Contains(TSource item) + => Contains(item, default); public int IndexOf(TSource item) { return source switch { + // ReSharper disable once HeapView.PossibleBoxingAllocation IList list => list.IndexOf(item), + _ => IndexOfEnumerable(this, item), }; @@ -146,12 +151,27 @@ public SkipTakeEnumerable, TSource> Take(int cou #region Conversion + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerable AsValueEnumerable() => this; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IReadOnlyCollection AsEnumerable() + // ReSharper disable once HeapView.PossibleBoxingAllocation => source; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TSource[] ToArray() + => ValueReadOnlyCollectionExtensions.ToArray, ValueEnumerator, TSource>(this); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ValueReadOnlyCollectionExtensions.ToArray, ValueEnumerator, TSource>(this, pool, clearOnDispose); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => ValueReadOnlyCollectionExtensions.ToList, ValueEnumerator, TSource>(this); + #endregion #region Projection @@ -175,6 +195,14 @@ public ValueReadOnlyListExtensions.SelectAtEnumerable ValueReadOnlyListExtensions.SelectAt, ValueEnumerator, TSource, TResult, TSelector>(this, selector); #endregion + + #region Quantifier + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TSource value, IEqualityComparer? comparer = default) + => Count is not 0 && source.Contains(value); + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs index 20977d65b..037622de7 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs @@ -45,6 +45,18 @@ public IEnumerable AsEnumerable() => source; #endregion + + #region Quantifier + + public bool Contains(TSource value, IEqualityComparer? comparer = default) + { + if (Utils.UseDefault(comparer) && source is ICollection collection) + return collection.Contains(value); + + return source.Contains, TEnumerator, TSource>(value, comparer); + } + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index 470a699b5..4a400b0c0 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -67,12 +67,8 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; + bool ICollection.Contains(TSource item) + => Contains(item, default); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -93,6 +89,20 @@ public IReadOnlyCollection AsEnumerable() => source; #endregion + + #region Quantifier + + public bool Contains(TSource value, IEqualityComparer? comparer = default) + { + if (Count is 0) + return false; + + if (Utils.UseDefault(comparer) && source is ICollection collection) + return collection.Contains(value); + + return source.Contains, TEnumerator, TSource>(value, comparer); + } + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs index c13c74c9e..1c8d98203 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -1,6 +1,8 @@ using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -71,12 +73,39 @@ IEnumerator IEnumerable.GetEnumerator() #region Conversion + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerable AsValueEnumerable() => this; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TEnumerable AsEnumerable() => source; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TSource[] ToArray() + => this.ToArray, TEnumerator, TSource>(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => this.ToArray, TEnumerator, TSource>(pool, clearOnDispose); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => this.ToList, TEnumerator, TSource>(); + + #endregion + + #region Quantifier + + public bool Contains(TSource value, IEqualityComparer? comparer = default) + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (Utils.UseDefault(comparer) && source is ICollection collection) + return collection.Contains(value); + + return this.Contains, TEnumerator, TSource>(value, comparer); + } + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index 64450742e..c4d252b6f 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -104,12 +105,8 @@ public void CopyTo(TSource[] array, int arrayIndex) [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; + bool ICollection.Contains(TSource item) + => Contains(item, default); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -123,12 +120,32 @@ bool ICollection.Remove(TSource item) #region Conversion + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerable AsValueEnumerable() => this; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TEnumerable AsEnumerable() => source; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TSource[] ToArray() + => ValueReadOnlyCollectionExtensions.ToArray, TEnumerator, TSource>(this); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => ValueReadOnlyCollectionExtensions.ToArray, TEnumerator, TSource>(this, pool, clearOnDispose); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => ValueReadOnlyCollectionExtensions.ToList, TEnumerator, TSource>(this); + + #endregion + #region Quantifier + + public bool Contains(TSource value, IEqualityComparer? comparer = default) + => Count is not 0 && source.Contains(value, comparer); + #endregion } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs index 263dc8353..e5de4a7fb 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs @@ -81,6 +81,19 @@ public TEnumerable AsEnumerable() => source; #endregion + + #region Quantifier + + public bool Contains(TSource value, IEqualityComparer? comparer = default) + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (Utils.UseDefault(comparer) && source is ICollection collection) + return collection.Contains(value); + + return source.Contains(value, comparer); + } + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index 5d43faa04..ace418be4 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -113,12 +113,8 @@ public void CopyTo(TSource[] array, int arrayIndex) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; + bool ICollection.Contains(TSource item) + => Contains(item, default); [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) @@ -139,6 +135,22 @@ public TEnumerable AsEnumerable() => source; #endregion + + #region Quantifier + + public bool Contains(TSource value, IEqualityComparer? comparer = default) + { + if (Count is 0) + return false; + + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (Utils.UseDefault(comparer) && source is ICollection collection) + return collection.Contains(value); + + return ValueReadOnlyCollectionExtensions.Contains(source, value, comparer); + } + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs index d148e92e7..936d903ff 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs @@ -114,6 +114,7 @@ public void CopyTo(TSource[] array, int arrayIndex) { switch (source) { + // ReSharper disable once HeapView.PossibleBoxingAllocation case ICollection collection: collection.CopyTo(array, arrayIndex); break; @@ -124,12 +125,8 @@ public void CopyTo(TSource[] array, int arrayIndex) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; + bool ICollection.Contains(TSource item) + => Contains(item, default); public readonly int IndexOf(TSource item) { @@ -206,6 +203,22 @@ public readonly SelectAtEnumerable SelectAt, TEnumerator, TSource, TResult, TSelector>(this, selector); #endregion + + #region Quantifier + + public bool Contains(TSource value, IEqualityComparer? comparer = default) + { + if (Count is 0) + return false; + + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (Utils.UseDefault(comparer) && source is ICollection collection) + return collection.Contains(value); + + return ValueReadOnlyCollectionExtensions.Contains(source, value, comparer); + } + + #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index 1bb92e5bd..f900ab9a1 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -159,6 +159,14 @@ public ArraySegment AsEnumerable() public TSource[] ToArray() => source.AsSpan().ToArray(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + => source.AsSpan().ToArray(pool, clearOnDispose); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => ((ReadOnlySpan)source.AsSpan()).ToList(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs new file mode 100644 index 000000000..c5665efbb --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs @@ -0,0 +1,15 @@ +using System; +using System.Buffers; +using System.Numerics; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class ArrayExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueMemoryOwner ToArray(this Memory source, ArrayPool pool, bool clearOnDispose = default) + => ((ReadOnlyMemory)source).Span.ToArray(pool, clearOnDispose); + } +} + diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs new file mode 100644 index 000000000..0c5bde854 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs @@ -0,0 +1,15 @@ +using System; +using System.Buffers; +using System.Numerics; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class ArrayExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueMemoryOwner ToArray(this ReadOnlyMemory source, ArrayPool pool, bool clearOnDispose = default) + => source.Span.ToArray(pool, clearOnDispose); + } +} + diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index af038d46f..3fa1b0dcc 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -14,7 +14,7 @@ static TSource[] ToArray(this ReadOnlySpan source) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentSliced(source.Length, clearOnDispose); + var result = pool.RentDisposable(source.Length, clearOnDispose); Copy(source, result.Memory.Span); return result; } @@ -130,7 +130,7 @@ static ValueMemoryOwner ToArrayVector ToArrayVector ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { - var result = pool.RentSliced(source.Length, clearOnDispose); + var result = pool.RentDisposable(source.Length, clearOnDispose); Copy(source, result.Memory.Span, selector); return result; } @@ -171,7 +171,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) static ValueMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { - var result = pool.RentSliced(source.Length, clearOnDispose); + var result = pool.RentDisposable(source.Length, clearOnDispose); CopyAt(source, result.Memory.Span, selector); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs new file mode 100644 index 000000000..f1445f007 --- /dev/null +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs @@ -0,0 +1,15 @@ +using System; +using System.Buffers; +using System.Numerics; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class ArrayExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueMemoryOwner ToArray(this Span source, ArrayPool pool, bool clearOnDispose = default) + => ((ReadOnlySpan)source).ToArray(pool, clearOnDispose); + } +} + diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index 14544f098..1bda4082c 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -14,20 +14,14 @@ public static TSource[] ToArray(this TEnumera { return source switch { - ICollection collection => BuildArrayFromCollectionOfTSource(collection), + // ReSharper disable once HeapView.PossibleBoxingAllocation // ReSharper disable once SuspiciousTypeConversion.Global - ICollection collection => BuildArrayFromCollection(collection), + ICollection collection => BuildArrayFromCollection(collection), + _ => BuildArray(source) }; - static TSource[] BuildArrayFromCollectionOfTSource(ICollection collection) - { - var result = Utils.AllocateUninitializedArray(collection.Count); - collection.CopyTo(result, 0); - return result; - } - - static TSource[] BuildArrayFromCollection(ICollection collection) + static TSource[] BuildArrayFromCollection(ICollection collection) { var result = Utils.AllocateUninitializedArray(collection.Count); collection.CopyTo(result, 0); @@ -46,8 +40,27 @@ public static ValueMemoryOwner ToArray where TEnumerator : struct, IEnumerator { - using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose); - return arrayBuilder.ToArray(pool, clearOnDispose); + return source switch + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + // ReSharper disable once SuspiciousTypeConversion.Global + ICollection collection => BuildArrayFromCollection(collection, pool, clearOnDispose), + + _ => BuildArray(source, pool, clearOnDispose) + }; + + static ValueMemoryOwner BuildArrayFromCollection(ICollection collection, ArrayPool pool, bool clearOnDispose) + { + var result = pool.RentDisposable(collection.Count, clearOnDispose); + collection.CopyTo(result.Rented, 0); + return result; + } + + static ValueMemoryOwner BuildArray(TEnumerable source, ArrayPool pool, bool clearOnDispose) + { + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose); + return arrayBuilder.ToArray(pool, clearOnDispose); + } } ////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index 8378eadd4..28dd4f414 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -20,23 +20,12 @@ public static TSource[] ToArray(this TEnumera // ReSharper disable once HeapView.PossibleBoxingAllocation // ReSharper disable once SuspiciousTypeConversion.Global - ICollection collection => BuildArrayFromCollectionOfTSource(collection), - - // ReSharper disable once HeapView.PossibleBoxingAllocation - // ReSharper disable once SuspiciousTypeConversion.Global - ICollection collection => BuildArrayFromCollection(collection), + ICollection collection => BuildArrayFromCollection(collection), _ => BuildArray(source) }; - static TSource[] BuildArrayFromCollectionOfTSource(ICollection collection) - { - var result = Utils.AllocateUninitializedArray(collection.Count); - collection.CopyTo(result, 0); - return result; - } - - static TSource[] BuildArrayFromCollection(ICollection collection) + static TSource[] BuildArrayFromCollection(ICollection collection) { var result = Utils.AllocateUninitializedArray(collection.Count); collection.CopyTo(result, 0); @@ -56,9 +45,28 @@ public static ValueMemoryOwner ToArray where TEnumerator : struct, IEnumerator { - var result = pool.RentSliced(source.Count, clearOnDispose); - Copy(source, result.Memory.Span); - return result; + return source switch + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + // ReSharper disable once SuspiciousTypeConversion.Global + ICollection collection => BuildArrayFromCollection(collection, pool, clearOnDispose), + + _ => BuildArray(source, pool, clearOnDispose) + }; + + static ValueMemoryOwner BuildArrayFromCollection(ICollection collection, ArrayPool pool, bool clearOnDispose) + { + var result = pool.RentDisposable(collection.Count, clearOnDispose); + collection.CopyTo(result.Rented, 0); + return result; + } + + static ValueMemoryOwner BuildArray(TEnumerable source, ArrayPool pool, bool clearOnDispose) + { + var result = pool.RentDisposable(source.Count, clearOnDispose); + Copy(source, result.Memory.Span); + return result; + } } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -136,8 +144,8 @@ internal static ValueMemoryOwner ToArray where TSelector : struct, IFunction { - var result = pool.RentSliced(source.Count, clearOnDispose); - Copy(source, result.Memory.Span, selector); + var result = pool.RentDisposable(source.Count, clearOnDispose); + Copy(source, result.Rented, selector); return result; } @@ -173,8 +181,8 @@ internal static ValueMemoryOwner ToArrayAt where TSelector : struct, IFunction { - var result = pool.RentSliced(source.Count, clearOnDispose); - CopyAt(source, result.Memory.Span, selector); + var result = pool.RentDisposable(source.Count, clearOnDispose); + CopyAt(source, result.Rented, selector); return result; } diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs index ba6b650aa..112ddbee9 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs @@ -182,7 +182,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) { - var result = pool.RentSliced(count, clearOnDispose); + var result = pool.RentDisposable(count, clearOnDispose); var array = result.Memory.Span; var end = count - 1; for (var index = 0; index <= end; index++) diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs index e8f8cbdff..8b1b6cebb 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs @@ -260,7 +260,7 @@ public int[] ToArray() public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentSliced(Count, clearOnDispose); + var result = pool.RentDisposable(Count, clearOnDispose); ArrayExtensions.CopyRange(start, Count, result.Memory.Span); return result; } diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs index 0e90f3a15..f848c6b0a 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs @@ -185,7 +185,7 @@ public TSource[] ToArray() public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentSliced(Count, clearOnDispose); + var result = pool.RentDisposable(Count, clearOnDispose); CopyTo(result.Memory.Span); return result; } @@ -239,7 +239,7 @@ public static TSource[] ToArrayVector(this RepeatEnumerable so public static ValueMemoryOwner ToArrayVector(this RepeatEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TSource : struct { - var result = pool.RentSliced(source.count, clearOnDispose); + var result = pool.RentDisposable(source.count, clearOnDispose); source.CopyToVector(result.Memory.Span); return result; } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs index 5ed43848c..2df86b67e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs @@ -88,7 +88,7 @@ public TResult[] ToArray() [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentSliced(count, clearOnDispose); + var result = pool.RentDisposable(count, clearOnDispose); ArrayExtensions.CopyRange(start, count, result.Memory.Span, vectorSelector, selector); return result; } diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs index 87cbe3e94..a843d834e 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs @@ -10,12 +10,12 @@ internal static bool Contains(this TEnumerable source, TSo { if (Utils.UseDefault(comparer)) { - return source switch - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - ICollection collection => collection.Contains(value), - _ => DefaultContains(source, value), - }; + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + return collection.Contains(value); + + if (Utils.IsValueType()) + return DefaultContains(source, value); } return ComparerContains(source, value, comparer); diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs index 24ee9d08b..7c7a83b00 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -10,12 +10,12 @@ public static bool Contains(this TEnumerable { if (Utils.UseDefault(comparer)) { - return source switch - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - ICollection collection => collection.Contains(value), - _ => DefaultContains(source, value), - }; + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + return collection.Contains(value); + + if (Utils.IsValueType()) + return DefaultContains(source, value); } return ComparerContains(source, value, comparer); diff --git a/NetFabric.Hyperlinq/Resource.Designer.cs b/NetFabric.Hyperlinq/Resource.Designer.cs index 194580233..ff4ee5dc4 100644 --- a/NetFabric.Hyperlinq/Resource.Designer.cs +++ b/NetFabric.Hyperlinq/Resource.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -12,46 +11,32 @@ namespace NetFabric.Hyperlinq { using System; - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resource { - private static global::System.Resources.ResourceManager resourceMan; + private static System.Resources.ResourceManager resourceMan; - private static global::System.Globalization.CultureInfo resourceCulture; + private static System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resource() { } - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NetFabric.Hyperlinq.Resource", typeof(Resource).Assembly); + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("NetFabric.Hyperlinq.Resource", typeof(Resource).Assembly); resourceMan = temp; } return resourceMan; } } - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -60,36 +45,24 @@ internal Resource() { } } - /// - /// Looks up a localized string similar to The array in the ArraySegment is null. - /// internal static string ArraySegmentNull { get { return ResourceManager.GetString("ArraySegmentNull", resourceCulture); } } - /// - /// Looks up a localized string similar to Destination array was not long enough. Check the destination index, length, and the array's lower bounds.. - /// internal static string DestinationNotLongEnough { get { return ResourceManager.GetString("DestinationNotLongEnough", resourceCulture); } } - /// - /// Looks up a localized string similar to Sequence contains no elements. - /// internal static string EmptySequence { get { return ResourceManager.GetString("EmptySequence", resourceCulture); } } - /// - /// Looks up a localized string similar to Sequence contains more than one element. - /// internal static string NotSingleSequence { get { return ResourceManager.GetString("NotSingleSequence", resourceCulture); diff --git a/NetFabric.Hyperlinq/Resource.resx b/NetFabric.Hyperlinq/Resource.resx index 05b1efb3f..260aed1d5 100644 --- a/NetFabric.Hyperlinq/Resource.resx +++ b/NetFabric.Hyperlinq/Resource.resx @@ -121,7 +121,7 @@ The array in the ArraySegment is null - Destination array was not long enough. Check the destination index, length, and the array's lower bounds. + Destination array was not long enough. Check the destination index, length, and the rentedArray's lower bounds. Sequence contains no elements diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index 1a1f1f649..cec24d32f 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -172,7 +172,7 @@ public readonly TElement[] ToArray() public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) { - var result = pool.RentSliced(Count, clearOnDispose); + var result = pool.RentDisposable(Count, clearOnDispose); CopyTo(result.Memory.Span); return result; } diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs index 4e3c52904..3c9a81977 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs @@ -152,7 +152,7 @@ public readonly T[] ToArray() public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) { - var result = pool.RentSliced(Count, clearOnDispose); + var result = pool.RentDisposable(Count, clearOnDispose); if (Count is not 0) CopyTo(result.Memory.Span); return result; diff --git a/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs b/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs index f8979b38b..0febc292c 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs @@ -7,48 +7,53 @@ namespace NetFabric.Hyperlinq static class ArrayPoolExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueMemoryOwner RentMemory(this ArrayPool pool, int length, bool clearOnDispose) - => new(pool, length, sliced: false, clearOnDispose); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueMemoryOwner RentSliced(this ArrayPool pool, int length, bool clearOnDispose) - => new(pool, length, sliced: true, clearOnDispose); + public static ValueMemoryOwner RentDisposable(this ArrayPool pool, int length, bool clearOnDispose) + => new(pool, length, clearOnDispose); } public struct ValueMemoryOwner : IMemoryOwner { readonly ArrayPool pool; - T[]? array; readonly int length; readonly bool clearOnDispose; + T[]? rented; - internal ValueMemoryOwner(ArrayPool pool, int length, bool sliced, bool clearOnDispose) + internal ValueMemoryOwner(ArrayPool pool, int length, bool clearOnDispose) { this.pool = pool; - array = pool.Rent(length); - this.length = sliced ? length : array.Length; + this.length = length; this.clearOnDispose = clearOnDispose; + rented = this.pool.Rent(length); } - public Memory Memory + public readonly T[] Rented { get { - var array = this.array; + var array = rented; + if (array is null) + Throw.ObjectDisposedException(nameof(ValueMemoryOwner)); + return array; + } + } + public readonly Memory Memory + { + get + { + var array = rented; if (array is null) Throw.ObjectDisposedException(nameof(ValueMemoryOwner)); - return new Memory(array, 0, length); } } public void Dispose() { - var array = this.array; + var array = rented; if (array is not null) { - this.array = null; + rented = null; pool.Return(array, clearOnDispose); } } diff --git a/NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs b/NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs index 84992d303..2ebdba04b 100644 --- a/NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs +++ b/NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs @@ -15,7 +15,7 @@ public static void CopyRange(int start, int count, Span destination) destination = destination.Slice(0, count); - if (Vector.IsHardwareAccelerated && count > Vector.Count * 2) + if (Vector.IsHardwareAccelerated && count >= Vector.Count) { var destinationVectors = MemoryMarshal.Cast>(destination); diff --git a/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs b/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs index 34d54d99d..b2f8ac98e 100644 --- a/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs +++ b/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs @@ -11,7 +11,6 @@ public static bool IsValueType() [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool UseDefault(IEqualityComparer? comparer) - => IsValueType() - && (comparer is null || ReferenceEquals(comparer, EqualityComparer.Default)); + => comparer is null || ReferenceEquals(comparer, EqualityComparer.Default); } } From 647af4c3618a4705e3f834eb31646adddd9cd2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Sun, 5 Sep 2021 22:44:09 +0100 Subject: [PATCH 46/61] Review ToArray() (#378) * Review ToArray() * Review ArrayBuilder and LargeArrayBuilder --- Benchmarks/ArrayIterationBenchmarks.md | 44 ++--- Benchmarks/ArrayToArrayBenchmarks.md | 50 ++--- Benchmarks/RangeToArrayBenchmarks.md | 36 ++-- Benchmarks/RepeatToArrayBenchmarks.md | 38 ++-- Benchmarks/SelectToArrayBenchmarks.md | 92 ++++----- Benchmarks/SelectToListBenchmarks.md | 90 ++++----- Benchmarks/ToArrayArrayPoolBenchmarks.md | 53 ----- Benchmarks/ToArrayBenchmarks.md | 94 ++++----- Benchmarks/ToListBenchmarks.md | 88 ++++----- Benchmarks/WhereBenchmarks.md | 92 ++++----- Benchmarks/WhereToArrayBenchmarks.md | 88 ++++----- Benchmarks/WhereToListBenchmarks.md | 88 ++++----- NetFabric.Hyperlinq.Abstractions/IFunction.cs | 14 +- .../Benchmarks/ToArrayArrayPoolBenchmarks.cs | 162 ---------------- .../Benchmarks/ToArrayBenchmarks.cs | 90 ++++++++- .../NetFabric.Hyperlinq.Benchmarks.csproj | 2 +- NetFabric.Hyperlinq.Benchmarks/Program.cs | 8 +- .../Utils/SpanExtensions.cs | 2 +- ...sAsyncValueEnumerable'1.AsyncEnumerable.cs | 2 +- ...sAsyncValueEnumerable'6.AsyncEnumerable.cs | 2 +- .../AsValueEnumerable'1.Enumerable.cs | 4 +- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 71 ++++--- .../AsValueEnumerable'1.ReadOnlyList.cs | 73 ++++--- .../AsValueEnumerable'1.ValueEnumerable.cs | 2 +- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 71 +++++-- .../AsValueEnumerable'6.Enumerable.cs | 4 +- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 64 +++++-- .../AsValueEnumerable'6.ValueEnumerable.cs | 2 +- ...lueEnumerable'6.ValueReadOnlyCollection.cs | 74 +++++-- .../AsValueEnumerable'6.ValueReadOnlyList.cs | 76 ++++++-- .../AsValueEnumerable.ArraySegment.cs | 19 +- .../AsValueEnumerable.ReadOnlyMemory.cs | 6 +- .../Conversion/ToArray/ToArray.Memory.cs | 3 +- .../ToArray/ToArray.ReadOnlyMemory.cs | 3 +- .../ToArray/ToArray.ReadOnlySpan.cs | 164 ++++++++-------- .../Conversion/ToArray/ToArray.Span.cs | 3 +- .../ToArray/ToArray.ValueEnumerable.cs | 85 ++++---- .../ToArray.ValueReadOnlyCollection.cs | 181 +++++++----------- .../ToArrayAsync.AsyncValueEnumerable.cs | 24 ++- .../Where/Where/Where.ArraySegment.cs | 2 +- .../Where/Where/Where.AsyncValueEnumerable.cs | 2 +- .../Where/Where/Where.ReadOnlyMemory.cs | 2 +- .../Where/Where/Where.ReadOnlySpan.cs | 2 +- .../Where/Where/Where.ValueEnumerable.cs | 2 +- .../Where/Where.ValueReadOnlyCollection.cs | 2 +- .../Where/WhereAt/WhereAt.ArraySegment.cs | 2 +- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 2 +- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 2 +- .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 2 +- .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 2 +- .../WhereAt.ValueReadOnlyCollection.cs | 2 +- .../WhereSelect/WhereSelect.ArraySegment.cs | 2 +- .../WhereSelect.AsyncValueEnumerable.cs | 2 +- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 2 +- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 2 +- .../WhereSelect.ValueEnumerable.cs | 2 +- .../WhereSelect.ValueReadOnlyCollection.cs | 2 +- .../Generation/AsyncValueEnumerable/Repeat.cs | 4 +- .../Generation/ValueEnumerable/Empty.cs | 5 - .../Generation/ValueEnumerable/Range.cs | 4 +- .../Generation/ValueEnumerable/Repeat.cs | 4 +- .../SkipTake/SkipTake.ReadOnlyList.cs | 3 +- .../SkipTake.ValueReadOnlyCollection.cs | 2 +- .../Select/Select/Select.ArraySegment.cs | 2 +- .../Select/Select.AsyncValueEnumerable.cs | 2 +- .../Select/Select/Select.ReadOnlyMemory.cs | 2 +- .../Select/Select/Select.ReadOnlySpan.cs | 2 +- .../Select/Select/Select.ValueEnumerable.cs | 2 +- .../Select/Select.ValueReadOnlyCollection.cs | 2 +- .../Select/Select/Select.ValueReadOnlyList.cs | 2 +- .../Select/SelectAt/SelectAt.ArraySegment.cs | 2 +- .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 2 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 2 +- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 2 +- .../SelectAt/SelectAt.ValueEnumerable.cs | 2 +- .../SelectAt.ValueReadOnlyCollection.cs | 2 +- .../SelectAt/SelectAt.ValueReadOnlyList.cs | 2 +- .../Select/SelectVector/SelectVector.Range.cs | 2 +- .../SelectVector/SelectVector.ReadOnlySpan.cs | 2 +- .../Contains/Contains.Enumerable.cs | 4 +- .../Contains/Contains.ReadOnlySpan.cs | 4 +- .../Contains/Contains.ValueEnumerable.cs | 4 +- .../ContainsAsync.AsyncValueEnumerable.cs | 2 +- .../Set/Distinct/Distinct.ArraySegment.cs | 2 +- .../Distinct/Distinct.AsyncValueEnumerable.cs | 2 +- .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 2 +- .../Set/Distinct/Distinct.ReadOnlySpan.cs | 2 +- .../Set/Distinct/Distinct.ValueEnumerable.cs | 2 +- NetFabric.Hyperlinq/Set/Distinct/Set.cs | 4 +- .../Utils/ArrayBuilder/ArrayBuilder.cs | 115 +++++------ .../Utils/ArrayBuilder/LargeArrayBuilder.cs | 140 +++++++------- .../ToArrayBuilder.ReadOnlyList.cs | 70 ------- .../ToArrayBuilder.ValueEnumerable.cs | 15 +- .../Utils/ArrayPoolExtensions.cs | 31 ++- .../Utils/SkipLocalsInitAttribute.cs | 21 ++ NetFabric.Hyperlinq/Utils/Throw.cs | 5 + .../Utils/Utils.AllocateUninitializedArray.cs | 4 +- .../Utils/Utils.EqualityComparer.cs | 4 +- 98 files changed, 1281 insertions(+), 1306 deletions(-) delete mode 100644 Benchmarks/ToArrayArrayPoolBenchmarks.md delete mode 100644 NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs delete mode 100644 NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq/Utils/SkipLocalsInitAttribute.cs diff --git a/Benchmarks/ArrayIterationBenchmarks.md b/Benchmarks/ArrayIterationBenchmarks.md index 62db6529b..0385d6cc1 100644 --- a/Benchmarks/ArrayIterationBenchmarks.md +++ b/Benchmarks/ArrayIterationBenchmarks.md @@ -4,35 +4,35 @@ [ArrayIterationBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1081 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-SLIMHF : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|--------------------- |-------- |-----------:|---------:|---------:|-------------:|--------:|------:|------:|------:|----------:| -| Foreach | 1000000 | 432.4 μs | 3.92 μs | 3.06 μs | baseline | | - | - | - | - | -| For | 1000000 | 435.1 μs | 8.19 μs | 7.26 μs | 1.01x slower | 0.02x | - | - | - | - | -| For_Unsafe | 1000000 | 434.8 μs | 8.67 μs | 8.11 μs | 1.00x slower | 0.02x | - | - | - | - | -| ForAdamczewski | 1000000 | 369.4 μs | 6.03 μs | 5.03 μs | 1.17x faster | 0.02x | - | - | - | - | -| ForAdamczewskiUnsafe | 1000000 | 436.1 μs | 4.05 μs | 3.38 μs | 1.01x slower | 0.01x | - | - | - | - | -| Span | 1000000 | 431.5 μs | 2.91 μs | 2.43 μs | 1.00x faster | 0.01x | - | - | - | - | -| ArraySegment_Foreach | 1000000 | 2,890.1 μs | 34.93 μs | 30.97 μs | 6.69x slower | 0.07x | - | - | - | 1 B | -| ArraySegment_For | 1000000 | 836.4 μs | 9.11 μs | 7.60 μs | 1.94x slower | 0.02x | - | - | - | - | -| ArraySegment_AsSpan | 1000000 | 430.0 μs | 4.37 μs | 3.65 μs | 1.01x faster | 0.01x | - | - | - | - | -| ArraySegment_AsArray | 1000000 | 575.1 μs | 3.28 μs | 2.91 μs | 1.33x slower | 0.01x | - | - | - | - | -| Vector | 1000000 | 118.6 μs | 1.91 μs | 2.12 μs | 3.63x faster | 0.08x | - | - | - | - | +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Allocated | +|--------------------- |-------- |-----------:|---------:|---------:|-------------:|--------:|----------:| +| Foreach | 1000000 | 459.6 μs | 2.49 μs | 1.95 μs | baseline | | 13 B | +| For | 1000000 | 460.4 μs | 2.37 μs | 2.21 μs | 1.00x slower | 0.01x | - | +| For_Unsafe | 1000000 | 460.7 μs | 2.86 μs | 2.54 μs | 1.00x slower | 0.00x | - | +| ForAdamczewski | 1000000 | 386.4 μs | 2.78 μs | 2.60 μs | 1.19x faster | 0.01x | - | +| ForAdamczewskiUnsafe | 1000000 | 387.7 μs | 4.10 μs | 3.84 μs | 1.18x faster | 0.01x | - | +| Span | 1000000 | 460.5 μs | 2.08 μs | 1.85 μs | 1.00x slower | 0.01x | - | +| ArraySegment_Foreach | 1000000 | 1,746.3 μs | 12.53 μs | 11.72 μs | 3.80x slower | 0.02x | 1 B | +| ArraySegment_For | 1000000 | 646.1 μs | 7.65 μs | 6.39 μs | 1.41x slower | 0.01x | - | +| ArraySegment_AsSpan | 1000000 | 461.5 μs | 3.82 μs | 3.19 μs | 1.00x slower | 0.01x | 1 B | +| ArraySegment_AsArray | 1000000 | 626.8 μs | 3.41 μs | 3.03 μs | 1.36x slower | 0.01x | 1 B | +| Vector | 1000000 | 119.9 μs | 1.72 μs | 1.61 μs | 3.83x faster | 0.06x | - | diff --git a/Benchmarks/ArrayToArrayBenchmarks.md b/Benchmarks/ArrayToArrayBenchmarks.md index 3b22c8010..08614ccc0 100644 --- a/Benchmarks/ArrayToArrayBenchmarks.md +++ b/Benchmarks/ArrayToArrayBenchmarks.md @@ -4,38 +4,38 @@ [ArrayToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.0.1561-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|----------------- |------ |-----------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| **ArrayClone** | **10** | **92.985 ns** | **1.9170 ns** | **2.4926 ns** | **1.00** | **0.00** | **0.0303** | **-** | **-** | **64 B** | -| SpanToArray | 10 | 7.493 ns | 0.1325 ns | 0.1175 ns | 0.08 | 0.00 | 0.0306 | - | - | 64 B | -| SpanCopyTo | 10 | 8.646 ns | 0.1475 ns | 0.1307 ns | 0.09 | 0.00 | 0.0306 | - | - | 64 B | -| CollectionCopyTo | 10 | 14.323 ns | 0.1582 ns | 0.1403 ns | 0.16 | 0.01 | 0.0305 | - | - | 64 B | -| | | | | | | | | | | | -| **ArrayClone** | **100** | **92.451 ns** | **1.1867 ns** | **1.1101 ns** | **1.00** | **0.00** | **0.2021** | **-** | **-** | **424 B** | -| SpanToArray | 100 | 31.352 ns | 0.6448 ns | 0.6031 ns | 0.34 | 0.01 | 0.2027 | - | - | 424 B | -| SpanCopyTo | 100 | 33.141 ns | 0.8588 ns | 2.4914 ns | 0.36 | 0.02 | 0.2027 | - | - | 424 B | -| CollectionCopyTo | 100 | 34.238 ns | 0.5767 ns | 0.5394 ns | 0.37 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | -| **ArrayClone** | **1000** | **286.609 ns** | **2.1636 ns** | **1.8067 ns** | **1.00** | **0.00** | **1.9155** | **-** | **-** | **4,024 B** | -| SpanToArray | 1000 | 269.321 ns | 4.8332 ns | 4.5210 ns | 0.94 | 0.01 | 1.9226 | - | - | 4,024 B | -| SpanCopyTo | 1000 | 242.775 ns | 3.5268 ns | 3.2990 ns | 0.85 | 0.01 | 1.9155 | - | - | 4,024 B | -| CollectionCopyTo | 1000 | 243.677 ns | 4.2879 ns | 4.0109 ns | 0.85 | 0.02 | 1.9155 | - | - | 4,024 B | +| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | +|----------------- |------ |----------:|---------:|---------:|-------------:|--------:|-------:|------:|------:|----------:| +| **ArrayClone** | **10** | **106.79 ns** | **0.520 ns** | **0.486 ns** | **baseline** | **** | **0.0305** | **-** | **-** | **64 B** | +| SpanToArray | 10 | 11.76 ns | 0.116 ns | 0.097 ns | 9.08x faster | 0.09x | 0.0306 | - | - | 64 B | +| SpanCopyTo | 10 | 12.71 ns | 0.228 ns | 0.213 ns | 8.41x faster | 0.15x | 0.0306 | - | - | 64 B | +| CollectionCopyTo | 10 | 16.74 ns | 0.099 ns | 0.093 ns | 6.38x faster | 0.04x | 0.0306 | - | - | 64 B | +| | | | | | | | | | | | +| **ArrayClone** | **100** | **115.18 ns** | **0.865 ns** | **0.810 ns** | **baseline** | **** | **0.2019** | **-** | **-** | **424 B** | +| SpanToArray | 100 | 38.58 ns | 0.355 ns | 0.297 ns | 2.98x faster | 0.03x | 0.2027 | - | - | 424 B | +| SpanCopyTo | 100 | 40.01 ns | 0.462 ns | 0.432 ns | 2.88x faster | 0.03x | 0.2027 | - | - | 424 B | +| CollectionCopyTo | 100 | 43.68 ns | 0.381 ns | 0.356 ns | 2.64x faster | 0.03x | 0.2027 | - | - | 424 B | +| | | | | | | | | | | | +| **ArrayClone** | **1000** | **310.98 ns** | **3.725 ns** | **3.302 ns** | **baseline** | **** | **1.9155** | **-** | **-** | **4,024 B** | +| SpanToArray | 1000 | 308.84 ns | 1.502 ns | 1.254 ns | 1.01x faster | 0.01x | 1.9226 | - | - | 4,024 B | +| SpanCopyTo | 1000 | 295.58 ns | 5.032 ns | 4.707 ns | 1.05x faster | 0.01x | 1.9155 | - | - | 4,024 B | +| CollectionCopyTo | 1000 | 299.15 ns | 3.317 ns | 3.102 ns | 1.04x faster | 0.01x | 1.9155 | - | - | 4,024 B | diff --git a/Benchmarks/RangeToArrayBenchmarks.md b/Benchmarks/RangeToArrayBenchmarks.md index d00219d01..f3a177647 100644 --- a/Benchmarks/RangeToArrayBenchmarks.md +++ b/Benchmarks/RangeToArrayBenchmarks.md @@ -4,31 +4,31 @@ [RangeToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RangeToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------ |------ |----------:|---------:|---------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Range | 100 | 91.33 ns | 0.704 ns | 0.588 ns | 91.48 ns | 1.00 | 0.00 | 0.2218 | - | - | 464 B | -| StructLinq | Range | 100 | 86.82 ns | 1.396 ns | 1.305 ns | 86.72 ns | 0.95 | 0.01 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Range | 100 | 40.31 ns | 0.879 ns | 2.452 ns | 39.02 ns | 0.44 | 0.02 | 0.2027 | - | - | 424 B | -| Hyperlinq | Range | 100 | 45.34 ns | 0.366 ns | 0.342 ns | 45.35 ns | 0.50 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Async | Range_Async | 100 | 105.08 ns | 1.318 ns | 1.232 ns | 105.44 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Range_Async | 100 | 145.72 ns | 0.949 ns | 0.793 ns | 145.54 ns | 1.39 | 0.02 | 0.2027 | - | - | 424 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Allocated | +|---------------- |------------ |------ |----------:|---------:|---------:|-------------:|--------:|-------:|----------:| +| Linq | Range | 100 | 98.10 ns | 0.503 ns | 0.393 ns | baseline | | 0.2217 | 464 B | +| StructLinq | Range | 100 | 106.79 ns | 2.013 ns | 1.785 ns | 1.09x slower | 0.02x | 0.2142 | 448 B | +| LinqFaster_SIMD | Range | 100 | 46.08 ns | 0.330 ns | 0.292 ns | 2.13x faster | 0.02x | 0.2027 | 424 B | +| Hyperlinq | Range | 100 | 52.06 ns | 0.499 ns | 0.417 ns | 1.88x faster | 0.02x | 0.2027 | 424 B | +| | | | | | | | | | | +| Linq_Async | Range_Async | 100 | 129.59 ns | 1.059 ns | 0.884 ns | baseline | | 0.2255 | 472 B | +| Hyperlinq_Async | Range_Async | 100 | 166.08 ns | 1.368 ns | 1.213 ns | 1.28x slower | 0.01x | 0.2027 | 424 B | diff --git a/Benchmarks/RepeatToArrayBenchmarks.md b/Benchmarks/RepeatToArrayBenchmarks.md index e8a16bea4..68118ad44 100644 --- a/Benchmarks/RepeatToArrayBenchmarks.md +++ b/Benchmarks/RepeatToArrayBenchmarks.md @@ -4,32 +4,32 @@ [RepeatToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/RepeatToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------- |------------- |------ |----------:|---------:|---------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq | Repeat | 100 | 90.72 ns | 1.491 ns | 2.450 ns | 90.20 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq | Repeat | 100 | 77.89 ns | 1.265 ns | 1.183 ns | 77.83 ns | 0.86 | 0.03 | 0.2142 | - | - | 448 B | -| LinqFaster_SIMD | Repeat | 100 | 29.47 ns | 0.658 ns | 0.808 ns | 29.45 ns | 0.32 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq | Repeat | 100 | 34.85 ns | 0.589 ns | 0.522 ns | 34.97 ns | 0.38 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_SIMD | Repeat | 100 | 42.00 ns | 0.914 ns | 2.593 ns | 40.72 ns | 0.46 | 0.03 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | | -| Linq_Async | Repeat_Async | 100 | 101.03 ns | 1.027 ns | 0.961 ns | 101.12 ns | 1.00 | 0.00 | 0.2257 | - | - | 472 B | -| Hyperlinq_Async | Repeat_Async | 100 | 166.58 ns | 1.317 ns | 1.100 ns | 166.15 ns | 1.65 | 0.01 | 0.2027 | - | - | 424 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Allocated | +|---------------- |------------- |------ |----------:|---------:|---------:|-------------:|--------:|-------:|----------:| +| Linq | Repeat | 100 | 48.20 ns | 0.986 ns | 1.923 ns | baseline | | 0.2180 | 456 B | +| StructLinq | Repeat | 100 | 87.02 ns | 0.783 ns | 0.694 ns | 1.72x slower | 0.06x | 0.2142 | 448 B | +| LinqFaster_SIMD | Repeat | 100 | 40.09 ns | 0.580 ns | 0.542 ns | 1.25x faster | 0.05x | 0.2027 | 424 B | +| Hyperlinq | Repeat | 100 | 42.98 ns | 0.979 ns | 1.690 ns | 1.12x faster | 0.05x | 0.2027 | 424 B | +| Hyperlinq_SIMD | Repeat | 100 | 51.60 ns | 1.154 ns | 1.830 ns | 1.07x slower | 0.03x | 0.2027 | 424 B | +| | | | | | | | | | | +| Linq_Async | Repeat_Async | 100 | 120.20 ns | 1.425 ns | 1.333 ns | baseline | | 0.2255 | 472 B | +| Hyperlinq_Async | Repeat_Async | 100 | 146.16 ns | 2.165 ns | 2.025 ns | 1.22x slower | 0.03x | 0.2027 | 424 B | diff --git a/Benchmarks/SelectToArrayBenchmarks.md b/Benchmarks/SelectToArrayBenchmarks.md index 7253ae362..d78393d54 100644 --- a/Benchmarks/SelectToArrayBenchmarks.md +++ b/Benchmarks/SelectToArrayBenchmarks.md @@ -4,59 +4,59 @@ [SelectToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 240.54 ns | 1.365 ns | 1.210 ns | 1.00 | 0.00 | 0.2255 | - | - | 472 B | -| StructLinq_Array | Array | 100 | 273.57 ns | 1.555 ns | 1.454 ns | 1.14 | 0.01 | 0.2027 | - | - | 424 B | -| LinqFasterSIMD_Array | Array | 100 | 64.64 ns | 1.071 ns | 1.002 ns | 0.27 | 0.00 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 251.62 ns | 0.888 ns | 0.831 ns | 1.05 | 0.01 | 0.2027 | - | - | 424 B | -| Hyperlinq_Array_SIMD | Array | 100 | 85.58 ns | 1.113 ns | 1.041 ns | 0.36 | 0.01 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,071.24 ns | 5.051 ns | 4.725 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,052.71 ns | 5.609 ns | 4.972 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 610.37 ns | 7.465 ns | 6.233 ns | 0.57 | 0.01 | 0.2022 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,152.86 ns | 6.149 ns | 5.752 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,057.94 ns | 3.803 ns | 3.175 ns | 0.92 | 0.00 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 366.46 ns | 2.656 ns | 2.355 ns | 0.32 | 0.00 | 0.2027 | - | - | 424 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 481.36 ns | 2.718 ns | 2.270 ns | 1.00 | 0.00 | 0.2289 | - | - | 480 B | -| StructLinq_List_Value | List_Value | 100 | 420.23 ns | 8.393 ns | 12.037 ns | 0.86 | 0.03 | 0.2027 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 860.09 ns | 3.344 ns | 2.792 ns | 1.79 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,727.46 ns | 38.027 ns | 31.754 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,347.46 ns | 8.091 ns | 7.568 ns | 0.30 | 0.00 | 0.5646 | - | - | 1,184 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,181.79 ns | 7.270 ns | 6.801 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,059.90 ns | 3.879 ns | 3.439 ns | 0.90 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,137.82 ns | 7.782 ns | 6.898 ns | 0.96 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,091.31 ns | 6.064 ns | 5.375 ns | 1.00 | 0.00 | 0.5913 | - | - | 1,240 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,064.82 ns | 5.197 ns | 4.607 ns | 0.98 | 0.01 | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 778.34 ns | 3.808 ns | 3.376 ns | 0.71 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 446.99 ns | 1.802 ns | 1.407 ns | 1.00 | 0.00 | 0.2294 | - | - | 480 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,092.56 ns | 6.810 ns | 6.037 ns | 2.44 | 0.02 | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 841.76 ns | 3.431 ns | 3.042 ns | 1.88 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,716.34 ns | 35.734 ns | 29.840 ns | 1.00 | 0.00 | 0.7935 | - | - | 1,672 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,145.91 ns | 8.983 ns | 8.403 ns | 0.41 | 0.00 | 0.5798 | - | - | 1,216 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|-----------:|-----------:|------------:|-------------:|--------:|-------:|----------:| +| Linq_Array | Array | 100 | 473.47 ns | 8.574 ns | 13.093 ns | 474.67 ns | baseline | | 0.2251 | 472 B | +| StructLinq_Array | Array | 100 | 279.61 ns | 4.617 ns | 4.093 ns | 282.23 ns | 1.72x faster | 0.04x | 0.2027 | 424 B | +| LinqFasterSIMD_Array | Array | 100 | 85.80 ns | 1.640 ns | 2.455 ns | 85.24 ns | 5.53x faster | 0.21x | 0.2027 | 424 B | +| Hyperlinq_Array | Array | 100 | 280.63 ns | 5.198 ns | 7.115 ns | 277.93 ns | 1.70x faster | 0.05x | 0.2027 | 424 B | +| Hyperlinq_Array_SIMD | Array | 100 | 102.08 ns | 1.429 ns | 1.336 ns | 102.36 ns | 4.70x faster | 0.09x | 0.2027 | 424 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,201.02 ns | 102.339 ns | 298.527 ns | 1,025.14 ns | baseline | | 0.5913 | 1,240 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 805.17 ns | 3.606 ns | 3.011 ns | 804.47 ns | 1.52x faster | 0.38x | 0.2174 | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 715.93 ns | 14.451 ns | 14.840 ns | 711.77 ns | 1.63x faster | 0.42x | 0.2022 | 424 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 1,183.52 ns | 77.980 ns | 229.924 ns | 1,133.48 ns | baseline | | 0.5913 | 1,240 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 805.63 ns | 3.765 ns | 3.522 ns | 804.45 ns | 1.39x faster | 0.27x | 0.2174 | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 289.68 ns | 1.739 ns | 1.542 ns | 289.81 ns | 3.86x faster | 0.78x | 0.2027 | 424 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 394.66 ns | 27.126 ns | 75.166 ns | 353.41 ns | baseline | | 0.2289 | 480 B | +| StructLinq_List_Value | List_Value | 100 | 403.84 ns | 8.158 ns | 7.631 ns | 404.80 ns | 1.21x faster | 0.06x | 0.2027 | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 524.14 ns | 10.475 ns | 11.643 ns | 524.80 ns | 1.09x slower | 0.07x | 0.2174 | 456 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 8,846.07 ns | 165.241 ns | 176.806 ns | 8,888.90 ns | baseline | | 0.7935 | 1,672 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,086.01 ns | 8.120 ns | 7.198 ns | 3,083.77 ns | 2.87x faster | 0.06x | 0.5646 | 1,184 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 702.52 ns | 14.093 ns | 18.814 ns | 695.92 ns | baseline | | 0.5922 | 1,240 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 805.96 ns | 12.195 ns | 12.523 ns | 802.69 ns | 1.15x slower | 0.03x | 0.2174 | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 872.85 ns | 14.855 ns | 13.895 ns | 871.81 ns | 1.25x slower | 0.04x | 0.2174 | 456 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 692.92 ns | 13.428 ns | 17.925 ns | 690.88 ns | baseline | | 0.5922 | 1,240 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 804.78 ns | 2.292 ns | 2.032 ns | 804.27 ns | 1.16x slower | 0.04x | 0.2174 | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 439.96 ns | 7.570 ns | 7.081 ns | 442.66 ns | 1.57x faster | 0.05x | 0.2179 | 456 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 336.83 ns | 1.248 ns | 1.106 ns | 336.54 ns | baseline | | 0.2294 | 480 B | +| StructLinq_List_Reference | List_Reference | 100 | 870.21 ns | 30.533 ns | 89.066 ns | 817.73 ns | 3.07x slower | 0.10x | 0.2174 | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 523.11 ns | 10.507 ns | 12.904 ns | 520.44 ns | 1.56x slower | 0.04x | 0.2174 | 456 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 8,857.84 ns | 146.367 ns | 136.912 ns | 8,931.34 ns | baseline | | 0.7935 | 1,672 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,237.06 ns | 56.426 ns | 50.020 ns | 3,214.50 ns | 2.73x faster | 0.07x | 0.5798 | 1,216 B | diff --git a/Benchmarks/SelectToListBenchmarks.md b/Benchmarks/SelectToListBenchmarks.md index b0d3fb5f6..a74b7e096 100644 --- a/Benchmarks/SelectToListBenchmarks.md +++ b/Benchmarks/SelectToListBenchmarks.md @@ -4,58 +4,58 @@ [SelectToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/SelectToListBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 338.38 ns | 2.006 ns | 1.876 ns | 338.43 ns | 1.00 | 0.00 | 0.2408 | - | - | 504 B | -| StructLinq_Array | Array | 100 | 263.67 ns | 5.286 ns | 7.056 ns | 265.41 ns | 0.77 | 0.03 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 285.53 ns | 1.874 ns | 1.565 ns | 285.41 ns | 0.84 | 0.01 | 0.2179 | - | - | 456 B | -| Hyperlinq_Array_SIMD | Array | 100 | 91.48 ns | 1.203 ns | 1.126 ns | 91.78 ns | 0.27 | 0.00 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,033.64 ns | 5.686 ns | 5.318 ns | 1,033.44 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,083.62 ns | 5.790 ns | 5.416 ns | 1,083.91 ns | 1.05 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 627.44 ns | 9.992 ns | 20.185 ns | 618.87 ns | 0.59 | 0.01 | 0.2174 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,035.14 ns | 7.299 ns | 6.470 ns | 1,033.06 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,068.83 ns | 5.827 ns | 5.165 ns | 1,069.30 ns | 1.03 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 282.33 ns | 0.968 ns | 0.858 ns | 282.33 ns | 0.27 | 0.00 | 0.2179 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 464.89 ns | 1.236 ns | 1.096 ns | 464.88 ns | 1.00 | 0.00 | 0.2446 | - | - | 512 B | -| StructLinq_List_Value | List_Value | 100 | 443.45 ns | 2.158 ns | 1.913 ns | 443.73 ns | 0.95 | 0.00 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 844.44 ns | 5.911 ns | 5.240 ns | 845.39 ns | 1.82 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 7,488.02 ns | 54.654 ns | 51.124 ns | 7,503.97 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,433.89 ns | 20.006 ns | 18.713 ns | 2,437.28 ns | 0.33 | 0.00 | 0.5798 | - | - | 1,216 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,043.46 ns | 4.850 ns | 4.050 ns | 1,042.38 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,080.29 ns | 4.157 ns | 3.685 ns | 1,079.25 ns | 1.04 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,144.40 ns | 7.280 ns | 6.810 ns | 1,145.30 ns | 1.10 | 0.01 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,044.52 ns | 4.615 ns | 4.317 ns | 1,043.08 ns | 1.00 | 0.00 | 0.6065 | - | - | 1,272 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,062.79 ns | 6.705 ns | 5.944 ns | 1,061.99 ns | 1.02 | 0.01 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 837.38 ns | 3.721 ns | 3.107 ns | 836.64 ns | 0.80 | 0.00 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 508.62 ns | 2.907 ns | 2.720 ns | 507.65 ns | 1.00 | 0.00 | 0.2441 | - | - | 512 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,083.30 ns | 6.355 ns | 4.962 ns | 1,082.39 ns | 2.13 | 0.02 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 838.80 ns | 16.450 ns | 20.804 ns | 849.94 ns | 1.63 | 0.05 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 7,339.88 ns | 20.278 ns | 16.933 ns | 7,342.17 ns | 1.00 | 0.00 | 0.6104 | - | - | 1,280 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,191.47 ns | 11.989 ns | 10.628 ns | 3,191.26 ns | 0.43 | 0.00 | 0.5951 | - | - | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|----------:|------------:|------------:|-------------:|--------:|-------:|----------:| +| Linq_Array | Array | 100 | 499.4 ns | 42.91 ns | 126.52 ns | 424.5 ns | baseline | | 0.2403 | 504 B | +| StructLinq_Array | Array | 100 | 447.4 ns | 37.68 ns | 111.09 ns | 375.6 ns | 1.16x faster | 0.32x | 0.2179 | 456 B | +| Hyperlinq_Array | Array | 100 | 395.9 ns | 27.26 ns | 80.39 ns | 353.2 ns | 1.31x faster | 0.42x | 0.2179 | 456 B | +| Hyperlinq_Array_SIMD | Array | 100 | 152.7 ns | 11.64 ns | 34.13 ns | 131.7 ns | 3.47x faster | 1.26x | 0.2179 | 456 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 963.8 ns | 83.58 ns | 246.45 ns | 827.4 ns | baseline | | 0.6075 | 1,272 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 838.4 ns | 9.00 ns | 7.03 ns | 836.9 ns | 1.05x faster | 0.26x | 0.2327 | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 977.0 ns | 75.52 ns | 222.68 ns | 837.1 ns | 1.09x slower | 0.39x | 0.2174 | 456 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 884.4 ns | 63.72 ns | 186.87 ns | 770.8 ns | baseline | | 0.6075 | 1,272 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,093.3 ns | 87.91 ns | 259.22 ns | 1,007.2 ns | 1.29x slower | 0.42x | 0.2327 | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 347.6 ns | 6.99 ns | 6.86 ns | 347.5 ns | 2.48x faster | 0.47x | 0.2179 | 456 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 595.9 ns | 49.90 ns | 147.13 ns | 544.4 ns | baseline | | 0.2446 | 512 B | +| StructLinq_List_Value | List_Value | 100 | 566.4 ns | 41.64 ns | 122.78 ns | 485.8 ns | 1.01x slower | 0.35x | 0.2174 | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 703.2 ns | 60.70 ns | 178.02 ns | 592.7 ns | 1.24x slower | 0.41x | 0.2327 | 488 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 11,551.1 ns | 633.63 ns | 1,868.27 ns | 11,329.3 ns | baseline | | 0.6104 | 1,280 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,334.4 ns | 252.18 ns | 743.57 ns | 4,145.6 ns | 2.72x faster | 0.54x | 0.5798 | 1,216 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 901.0 ns | 64.70 ns | 190.76 ns | 782.3 ns | baseline | | 0.6075 | 1,272 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 994.9 ns | 62.26 ns | 183.58 ns | 877.2 ns | 1.15x slower | 0.31x | 0.2327 | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,237.7 ns | 104.77 ns | 307.28 ns | 1,124.8 ns | 1.43x slower | 0.46x | 0.2327 | 488 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 736.4 ns | 9.91 ns | 9.74 ns | 733.0 ns | baseline | | 0.6065 | 1,272 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 856.6 ns | 17.26 ns | 21.19 ns | 852.4 ns | 1.16x slower | 0.04x | 0.2327 | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 631.3 ns | 54.20 ns | 159.81 ns | 524.5 ns | 1.18x faster | 0.34x | 0.2327 | 488 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 573.6 ns | 45.82 ns | 135.10 ns | 510.4 ns | baseline | | 0.2441 | 512 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,082.1 ns | 87.71 ns | 258.61 ns | 972.5 ns | 2.00x slower | 0.69x | 0.2327 | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 724.9 ns | 66.44 ns | 195.91 ns | 606.8 ns | 1.30x slower | 0.34x | 0.2327 | 488 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 11,006.0 ns | 599.34 ns | 1,748.30 ns | 10,037.5 ns | baseline | | 0.6104 | 1,280 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,231.7 ns | 10.46 ns | 8.73 ns | 3,229.7 ns | 3.40x faster | 0.33x | 0.5951 | 1,248 B | diff --git a/Benchmarks/ToArrayArrayPoolBenchmarks.md b/Benchmarks/ToArrayArrayPoolBenchmarks.md deleted file mode 100644 index 57c8f6341..000000000 --- a/Benchmarks/ToArrayArrayPoolBenchmarks.md +++ /dev/null @@ -1,53 +0,0 @@ -## ToArrayArrayPoolBenchmarks - -### Source -[ToArrayArrayPoolBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs) - -### References: -- Linq: 6.0.0-preview.7.21377.19 -- System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) -- System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) -- System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) -- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) - -### Results: -``` ini - -BenchmarkDotNet=v0.13.0.1561-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] -Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.7.21379.14 - [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT - Job-WKXHDN : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT - -Runtime=.NET 6.0 - -``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------------------------------------- |-------------------------- |------ |------------:|----------:|----------:|-------------:|--------:|-------:|------:|------:|----------:| -| Hyperlinq_Array | Array | 100 | 71.55 ns | 0.539 ns | 0.504 ns | baseline | | 0.2027 | - | - | 424 B | -| Hyperlinq_Array_ArrayPool | Array | 100 | 88.19 ns | 1.409 ns | 1.249 ns | 1.23x slower | 0.02x | - | - | - | - | -| | | | | | | | | | | | | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 574.98 ns | 6.409 ns | 5.681 ns | baseline | | 0.2022 | - | - | 424 B | -| Hyperlinq_Enumerable_Value_ArrayPool | Enumerable_Value | 100 | 592.11 ns | 11.686 ns | 12.000 ns | 1.03x slower | 0.02x | - | - | - | - | -| | | | | | | | | | | | | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 194.76 ns | 2.327 ns | 1.943 ns | baseline | | 0.2217 | - | - | 464 B | -| Hyperlinq_Collection_Value_ArrayPool | Collection_Value | 100 | 198.94 ns | 3.513 ns | 3.286 ns | 1.02x slower | 0.02x | 0.0191 | - | - | 40 B | -| | | | | | | | | | | | | -| Hyperlinq_List_Value | List_Value | 100 | 81.78 ns | 1.630 ns | 1.878 ns | baseline | | 0.2142 | - | - | 448 B | -| Hyperlinq_List_Value_ArrayPool | List_Value | 100 | 90.87 ns | 1.200 ns | 1.064 ns | 1.11x slower | 0.03x | 0.0114 | - | - | 24 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,581.94 ns | 7.917 ns | 6.611 ns | baseline | | 0.5646 | - | - | 1,184 B | -| Hyperlinq_AsyncEnumerable_Value_ArrayPool | AsyncEnumerable_Value | 100 | 1,595.35 ns | 9.042 ns | 7.550 ns | 1.01x slower | 0.01x | 0.3624 | - | - | 760 B | -| | | | | | | | | | | | | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,176.25 ns | 9.371 ns | 8.766 ns | baseline | | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference_ArrayPool | Enumerable_Reference | 100 | 1,160.29 ns | 16.363 ns | 15.306 ns | 1.01x faster | 0.02x | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 85.97 ns | 1.027 ns | 0.961 ns | baseline | | 0.2142 | - | - | 448 B | -| Hyperlinq_Collection_Reference_ArrayPool | Collection_Reference | 100 | 96.72 ns | 1.965 ns | 2.103 ns | 1.12x slower | 0.02x | 0.0114 | - | - | 24 B | -| | | | | | | | | | | | | -| Hyperlinq_List_Reference | List_Reference | 100 | 81.42 ns | 1.266 ns | 1.184 ns | baseline | | 0.2142 | - | - | 448 B | -| Hyperlinq_List_Reference_ArrayPool | List_Reference | 100 | 90.73 ns | 1.831 ns | 1.880 ns | 1.11x slower | 0.02x | 0.0114 | - | - | 24 B | -| | | | | | | | | | | | | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,605.91 ns | 11.347 ns | 10.614 ns | baseline | | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Reference_ArrayPool | AsyncEnumerable_Reference | 100 | 2,670.44 ns | 37.433 ns | 35.015 ns | 1.02x slower | 0.01x | 0.3777 | - | - | 792 B | diff --git a/Benchmarks/ToArrayBenchmarks.md b/Benchmarks/ToArrayBenchmarks.md index b742acf96..90e3bec8a 100644 --- a/Benchmarks/ToArrayBenchmarks.md +++ b/Benchmarks/ToArrayBenchmarks.md @@ -14,56 +14,56 @@ ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1561-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores .NET SDK=6.0.100-preview.7.21379.14 [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT - Job-NRTSBV : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|---------------------------------------------- |-------------------------- |------ |------------:|-----------:|------------:|------------:|--------------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 163.04 ns | 17.071 ns | 48.43 ns | 151.20 ns | baseline | | 0.2027 | - | - | 424 B | -| StructLinq_Array | Array | 100 | 306.86 ns | 14.754 ns | 43.04 ns | 310.49 ns | 2.04x slower | 0.59x | 0.2027 | - | - | 424 B | -| Hyperlinq_Array | Array | 100 | 88.98 ns | 6.099 ns | 17.98 ns | 84.58 ns | 1.86x faster | 0.65x | 0.2027 | - | - | 424 B | -| Hyperlinq_Array_ArrayPool | Array | 100 | 163.95 ns | 14.690 ns | 41.43 ns | 148.74 ns | 1.09x slower | 0.41x | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 2,354.70 ns | 237.865 ns | 701.35 ns | 2,088.55 ns | baseline | | 0.5646 | - | - | 1,184 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 3,409.14 ns | 191.945 ns | 553.80 ns | 3,355.16 ns | 1.56x slower | 0.51x | 0.2136 | - | - | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1,247.87 ns | 116.048 ns | 342.17 ns | 1,124.28 ns | 2.01x faster | 0.76x | 0.2213 | - | - | 464 B | -| Hyperlinq_Enumerable_Value_ArrayPool | Enumerable_Value | 100 | 1,262.16 ns | 153.002 ns | 431.54 ns | 1,170.54 ns | 2.03x faster | 0.72x | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 128.85 ns | 12.178 ns | 35.52 ns | 114.80 ns | baseline | | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 2,101.36 ns | 175.955 ns | 518.81 ns | 1,884.01 ns | 17.03x slower | 5.13x | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 348.20 ns | 27.074 ns | 78.55 ns | 326.34 ns | 2.87x slower | 0.91x | 0.2213 | - | - | 464 B | -| Hyperlinq_Collection_Value_ArrayPool | Collection_Value | 100 | 420.59 ns | 39.264 ns | 112.66 ns | 408.15 ns | 3.54x slower | 1.46x | - | - | - | - | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 136.70 ns | 14.382 ns | 42.41 ns | 121.74 ns | baseline | | 0.2027 | - | - | 424 B | -| StructLinq_List_Value | List_Value | 100 | 654.04 ns | 57.795 ns | 170.41 ns | 569.22 ns | 5.25x slower | 2.10x | 0.2022 | - | - | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 141.58 ns | 14.635 ns | 41.04 ns | 133.28 ns | 1.09x slower | 0.42x | 0.2136 | - | - | 448 B | -| Hyperlinq_List_Value_ArrayPool | List_Value | 100 | 2,639.47 ns | 343.889 ns | 969.94 ns | 2,341.53 ns | 20.96x slower | 10.56x | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,433.84 ns | 280.479 ns | 818.17 ns | 4,172.04 ns | baseline | | 0.7668 | - | - | 1,608 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,986.15 ns | 210.448 ns | 607.19 ns | 2,804.33 ns | 1.55x faster | 0.43x | 0.5646 | - | - | 1,184 B | -| Hyperlinq_AsyncEnumerable_Value_ArrayPool | AsyncEnumerable_Value | 100 | 4,198.43 ns | 440.451 ns | 1,205.73 ns | 3,826.17 ns | 1.15x faster | 0.35x | 0.3624 | - | - | 760 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 2,189.65 ns | 194.003 ns | 572.02 ns | 1,999.68 ns | baseline | | 0.5646 | - | - | 1,184 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 2,393.79 ns | 227.705 ns | 671.39 ns | 2,364.41 ns | 1.17x slower | 0.46x | 0.2136 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 2,799.73 ns | 284.878 ns | 821.94 ns | 2,585.37 ns | 1.34x slower | 0.49x | 0.2174 | - | - | 456 B | -| Hyperlinq_Enumerable_Reference_ArrayPool | Enumerable_Reference | 100 | 2,360.88 ns | 161.513 ns | 476.22 ns | 2,396.03 ns | 1.14x slower | 0.34x | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 115.65 ns | 8.905 ns | 25.41 ns | 106.26 ns | baseline | | 0.2027 | - | - | 424 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 2,091.15 ns | 217.124 ns | 640.19 ns | 1,745.16 ns | 19.18x slower | 7.50x | 0.2174 | - | - | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 193.10 ns | 25.659 ns | 74.03 ns | 171.64 ns | 1.75x slower | 0.72x | 0.2141 | - | - | 448 B | -| Hyperlinq_Collection_Reference_ArrayPool | Collection_Reference | 100 | 1,402.92 ns | 105.127 ns | 309.97 ns | 1,237.28 ns | 12.84x slower | 3.86x | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 164.70 ns | 13.638 ns | 40.21 ns | 161.30 ns | baseline | | 0.2027 | - | - | 424 B | -| StructLinq_List_Reference | List_Reference | 100 | 2,247.33 ns | 206.354 ns | 601.94 ns | 2,141.67 ns | 14.50x slower | 5.23x | 0.2174 | - | - | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 155.51 ns | 19.107 ns | 55.13 ns | 143.08 ns | 1.00x slower | 0.40x | 0.2142 | - | - | 448 B | -| Hyperlinq_List_Reference_ArrayPool | List_Reference | 100 | 1,517.09 ns | 120.567 ns | 355.49 ns | 1,462.84 ns | 9.78x slower | 3.37x | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,261.83 ns | 271.077 ns | 790.75 ns | 5,092.51 ns | baseline | | 0.7629 | - | - | 1,608 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 6,319.42 ns | 795.422 ns | 2,320.28 ns | 5,607.97 ns | 1.22x slower | 0.46x | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Reference_ArrayPool | AsyncEnumerable_Reference | 100 | 4,795.02 ns | 619.269 ns | 1,746.66 ns | 4,093.43 ns | 1.19x faster | 0.33x | 0.3738 | - | - | 792 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Allocated | +|---------------------------------------------- |-------------------------- |------ |------------:|----------:|----------:|------------:|--------------:|--------:|-------:|----------:| +| Linq_Array | Array | 100 | 67.13 ns | 1.472 ns | 1.752 ns | 66.92 ns | baseline | | 0.2027 | 424 B | +| StructLinq_Array | Array | 100 | 92.84 ns | 0.390 ns | 0.326 ns | 92.71 ns | 1.38x slower | 0.04x | 0.2027 | 424 B | +| Hyperlinq_Array | Array | 100 | 44.95 ns | 0.745 ns | 0.696 ns | 44.66 ns | 1.49x faster | 0.03x | 0.2027 | 424 B | +| Hyperlinq_Array_ArrayPool | Array | 100 | 73.87 ns | 0.320 ns | 0.300 ns | 73.70 ns | 1.10x slower | 0.03x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 674.86 ns | 11.069 ns | 10.354 ns | 670.18 ns | baseline | | 0.5655 | 1,184 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 575.61 ns | 9.396 ns | 8.789 ns | 579.51 ns | 1.17x faster | 0.02x | 0.2174 | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 538.30 ns | 2.627 ns | 2.457 ns | 538.50 ns | 1.25x faster | 0.02x | 0.2213 | 464 B | +| Hyperlinq_Enumerable_ArrayPool_Value | Enumerable_Value | 100 | 535.51 ns | 1.851 ns | 1.731 ns | 534.80 ns | 1.26x faster | 0.02x | 0.0381 | 80 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 49.47 ns | 1.079 ns | 2.345 ns | 48.60 ns | baseline | | 0.2027 | 424 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 557.60 ns | 4.299 ns | 4.022 ns | 557.04 ns | 10.61x slower | 0.33x | 0.2174 | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 53.89 ns | 1.080 ns | 0.958 ns | 53.47 ns | 1.03x slower | 0.04x | 0.2027 | 424 B | +| Hyperlinq_Collection_ArrayPool_Value | Collection_Value | 100 | 71.53 ns | 0.117 ns | 0.091 ns | 71.52 ns | 1.37x slower | 0.04x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 53.53 ns | 1.137 ns | 1.008 ns | 53.19 ns | baseline | | 0.2027 | 424 B | +| StructLinq_List_Value | List_Value | 100 | 184.43 ns | 0.656 ns | 0.581 ns | 184.38 ns | 3.45x slower | 0.07x | 0.2027 | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 52.27 ns | 0.146 ns | 0.122 ns | 52.29 ns | 1.03x faster | 0.02x | 0.2027 | 424 B | +| Hyperlinq_List_ArrayPool_Value | List_Value | 100 | 63.73 ns | 0.422 ns | 0.394 ns | 63.53 ns | 1.19x slower | 0.02x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,476.54 ns | 3.687 ns | 3.449 ns | 1,474.90 ns | baseline | | 0.7687 | 1,608 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,405.04 ns | 2.552 ns | 2.262 ns | 1,404.32 ns | 1.05x faster | 0.00x | 0.5646 | 1,184 B | +| Hyperlinq_AsyncEnumerable_ArrayPool_Value | AsyncEnumerable_Value | 100 | 1,480.90 ns | 4.645 ns | 3.879 ns | 1,479.78 ns | 1.00x slower | 0.00x | 0.3815 | 800 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 654.78 ns | 13.184 ns | 14.107 ns | 656.55 ns | baseline | | 0.5655 | 1,184 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 554.36 ns | 0.847 ns | 0.661 ns | 554.21 ns | 1.19x faster | 0.02x | 0.2174 | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 653.44 ns | 4.970 ns | 4.406 ns | 652.06 ns | 1.01x faster | 0.02x | 0.2174 | 456 B | +| Hyperlinq_Enumerable_ArrayPool_Reference | Enumerable_Reference | 100 | 645.39 ns | 2.636 ns | 2.466 ns | 644.32 ns | 1.02x faster | 0.02x | 0.0343 | 72 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 49.07 ns | 1.069 ns | 1.632 ns | 48.85 ns | baseline | | 0.2027 | 424 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 561.90 ns | 11.090 ns | 12.771 ns | 555.53 ns | 11.32x slower | 0.33x | 0.2174 | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 49.80 ns | 0.280 ns | 0.248 ns | 49.78 ns | 1.01x faster | 0.02x | 0.2027 | 424 B | +| Hyperlinq_Collection_ArrayPool_Reference | Collection_Reference | 100 | 61.29 ns | 0.466 ns | 0.413 ns | 61.16 ns | 1.21x slower | 0.03x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 51.95 ns | 1.133 ns | 2.210 ns | 51.54 ns | baseline | | 0.2027 | 424 B | +| StructLinq_List_Reference | List_Reference | 100 | 557.68 ns | 2.742 ns | 2.290 ns | 556.38 ns | 10.48x slower | 0.31x | 0.2174 | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 52.05 ns | 0.319 ns | 0.299 ns | 52.02 ns | 1.03x faster | 0.04x | 0.2027 | 424 B | +| Hyperlinq_List_ArrayPool_Reference | List_Reference | 100 | 62.97 ns | 0.317 ns | 0.297 ns | 62.77 ns | 1.18x slower | 0.04x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,483.38 ns | 3.662 ns | 3.246 ns | 1,482.68 ns | baseline | | 0.7687 | 1,608 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,613.54 ns | 3.046 ns | 2.700 ns | 1,612.45 ns | 1.09x slower | 0.00x | 0.5798 | 1,216 B | +| Hyperlinq_AsyncEnumerable_ArrayPool_Reference | AsyncEnumerable_Reference | 100 | 1,639.47 ns | 4.508 ns | 3.996 ns | 1,639.51 ns | 1.11x slower | 0.00x | 0.3967 | 832 B | diff --git a/Benchmarks/ToListBenchmarks.md b/Benchmarks/ToListBenchmarks.md index 643030fa9..82e6074e4 100644 --- a/Benchmarks/ToListBenchmarks.md +++ b/Benchmarks/ToListBenchmarks.md @@ -4,57 +4,57 @@ [ToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToListBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|----------:|----------:|------------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 58.81 ns | 0.505 ns | 0.473 ns | 58.83 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Array | Array | 100 | 94.06 ns | 1.231 ns | 1.151 ns | 93.99 ns | 1.60 | 0.02 | 0.2180 | - | - | 456 B | -| Hyperlinq_Array | Array | 100 | 48.82 ns | 1.053 ns | 2.661 ns | 47.60 ns | 0.85 | 0.05 | 0.2180 | - | - | 456 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 859.60 ns | 17.141 ns | 34.625 ns | 837.18 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 972.46 ns | 7.019 ns | 6.565 ns | 973.93 ns | 1.09 | 0.04 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 618.71 ns | 4.105 ns | 3.428 ns | 618.72 ns | 0.68 | 0.01 | 0.2365 | - | - | 496 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 57.86 ns | 0.921 ns | 0.816 ns | 57.93 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 919.81 ns | 4.114 ns | 3.849 ns | 921.58 ns | 15.91 | 0.20 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 147.30 ns | 2.179 ns | 2.038 ns | 146.28 ns | 2.54 | 0.06 | 0.2370 | - | - | 496 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 54.34 ns | 0.603 ns | 0.535 ns | 54.40 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Value | List_Value | 100 | 257.40 ns | 1.623 ns | 1.518 ns | 257.40 ns | 4.74 | 0.06 | 0.2179 | - | - | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 78.38 ns | 1.240 ns | 1.099 ns | 78.55 ns | 1.44 | 0.02 | 0.2295 | - | - | 480 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,933.29 ns | 37.450 ns | 48.695 ns | 1,962.87 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,218.93 ns | 6.225 ns | 5.198 ns | 1,219.33 ns | 0.64 | 0.02 | 0.5798 | - | - | 1,216 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 836.68 ns | 3.132 ns | 2.776 ns | 836.44 ns | 1.00 | 0.00 | 0.5808 | - | - | 1,216 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 919.99 ns | 5.034 ns | 4.462 ns | 919.05 ns | 1.10 | 0.00 | 0.2327 | - | - | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,041.93 ns | 20.075 ns | 24.653 ns | 1,046.08 ns | 1.24 | 0.03 | 0.2327 | - | - | 488 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 52.49 ns | 0.880 ns | 0.780 ns | 52.71 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 943.89 ns | 17.853 ns | 23.215 ns | 931.73 ns | 18.19 | 0.41 | 0.2327 | - | - | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 68.72 ns | 0.533 ns | 0.655 ns | 68.60 ns | 1.31 | 0.02 | 0.2295 | - | - | 480 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 56.89 ns | 1.213 ns | 3.280 ns | 54.95 ns | 1.00 | 0.00 | 0.2180 | - | - | 456 B | -| StructLinq_List_Reference | List_Reference | 100 | 929.09 ns | 3.788 ns | 3.358 ns | 929.08 ns | 15.78 | 0.64 | 0.2327 | - | - | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 84.47 ns | 1.761 ns | 4.252 ns | 82.38 ns | 1.48 | 0.13 | 0.2295 | - | - | 480 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,954.13 ns | 37.510 ns | 36.840 ns | 1,969.88 ns | 1.00 | 0.00 | 0.5798 | - | - | 1,216 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,041.94 ns | 11.426 ns | 10.688 ns | 2,039.66 ns | 1.05 | 0.02 | 0.5951 | - | - | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Allocated | +|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|--------------:|--------:|-------:|----------:| +| Linq_Array | Array | 100 | 78.12 ns | 0.344 ns | 0.305 ns | baseline | | 0.2180 | 456 B | +| StructLinq_Array | Array | 100 | 105.98 ns | 0.367 ns | 0.307 ns | 1.36x slower | 0.01x | 0.2180 | 456 B | +| Hyperlinq_Array | Array | 100 | 54.08 ns | 0.374 ns | 0.350 ns | 1.44x faster | 0.01x | 0.2180 | 456 B | +| | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 472.95 ns | 2.738 ns | 2.561 ns | baseline | | 0.5808 | 1,216 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 565.69 ns | 2.407 ns | 2.251 ns | 1.20x slower | 0.01x | 0.2327 | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 550.85 ns | 1.197 ns | 0.999 ns | 1.16x slower | 0.01x | 0.2365 | 496 B | +| | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 56.91 ns | 0.274 ns | 0.243 ns | baseline | | 0.2180 | 456 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 586.92 ns | 2.851 ns | 2.527 ns | 10.31x slower | 0.07x | 0.2327 | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 66.44 ns | 0.648 ns | 0.606 ns | 1.17x slower | 0.01x | 0.2180 | 456 B | +| | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 60.17 ns | 0.425 ns | 0.355 ns | baseline | | 0.2180 | 456 B | +| StructLinq_List_Value | List_Value | 100 | 140.00 ns | 1.232 ns | 1.152 ns | 2.33x slower | 0.02x | 0.2179 | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 65.30 ns | 0.520 ns | 0.487 ns | 1.09x slower | 0.01x | 0.2180 | 456 B | +| | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,466.73 ns | 4.006 ns | 3.551 ns | baseline | | 0.5798 | 1,216 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,472.88 ns | 4.559 ns | 4.265 ns | 1.00x slower | 0.00x | 0.5798 | 1,216 B | +| | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 473.62 ns | 2.557 ns | 2.392 ns | baseline | | 0.5808 | 1,216 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 570.95 ns | 1.489 ns | 1.243 ns | 1.21x slower | 0.01x | 0.2327 | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 653.91 ns | 2.104 ns | 1.969 ns | 1.38x slower | 0.01x | 0.2327 | 488 B | +| | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 57.16 ns | 0.823 ns | 0.687 ns | baseline | | 0.2180 | 456 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 569.44 ns | 2.948 ns | 2.757 ns | 9.96x slower | 0.13x | 0.2327 | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 61.24 ns | 0.481 ns | 0.376 ns | 1.07x slower | 0.01x | 0.2180 | 456 B | +| | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 60.14 ns | 0.348 ns | 0.326 ns | baseline | | 0.2180 | 456 B | +| StructLinq_List_Reference | List_Reference | 100 | 578.80 ns | 8.282 ns | 6.915 ns | 9.63x slower | 0.13x | 0.2327 | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 64.81 ns | 0.398 ns | 0.353 ns | 1.08x slower | 0.01x | 0.2180 | 456 B | +| | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,466.21 ns | 3.947 ns | 3.692 ns | baseline | | 0.5798 | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,616.07 ns | 4.787 ns | 4.478 ns | 1.10x slower | 0.00x | 0.5951 | 1,248 B | diff --git a/Benchmarks/WhereBenchmarks.md b/Benchmarks/WhereBenchmarks.md index c3616afcf..5ed672ec5 100644 --- a/Benchmarks/WhereBenchmarks.md +++ b/Benchmarks/WhereBenchmarks.md @@ -4,59 +4,59 @@ [WhereBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 472.6 ns | 3.25 ns | 2.71 ns | 1.00 | 0.0229 | - | - | 48 B | -| StructLinq_Array | Array | 100 | 284.5 ns | 5.02 ns | 4.70 ns | 0.60 | - | - | - | - | -| Hyperlinq_Array | Array | 100 | 456.0 ns | 2.66 ns | 2.49 ns | 0.97 | - | - | - | - | -| Hyperlinq_Span | Array | 100 | 275.9 ns | 3.54 ns | 3.32 ns | 0.58 | - | - | - | - | -| Hyperlinq_Memory | Array | 100 | 293.9 ns | 3.16 ns | 2.80 ns | 0.62 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,360.8 ns | 11.11 ns | 9.85 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,245.3 ns | 4.40 ns | 3.90 ns | 0.92 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 317.4 ns | 3.56 ns | 3.15 ns | 0.23 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,351.8 ns | 5.37 ns | 4.76 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,266.1 ns | 6.69 ns | 5.93 ns | 0.94 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 262.3 ns | 2.27 ns | 2.01 ns | 0.19 | - | - | - | - | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,355.8 ns | 7.63 ns | 7.14 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Value | List_Value | 100 | 647.4 ns | 4.18 ns | 3.70 ns | 0.48 | - | - | - | - | -| Hyperlinq_List_Value | List_Value | 100 | 1,209.3 ns | 6.51 ns | 5.43 ns | 0.89 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,643.9 ns | 27.76 ns | 25.96 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,781.5 ns | 14.49 ns | 12.85 ns | 1.03 | - | - | - | - | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,311.4 ns | 5.54 ns | 4.91 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,241.9 ns | 8.64 ns | 7.66 ns | 0.95 | 0.0153 | - | - | 32 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,213.4 ns | 5.06 ns | 4.74 ns | 0.93 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,364.9 ns | 6.06 ns | 5.06 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,263.3 ns | 7.59 ns | 6.73 ns | 0.93 | 0.0153 | - | - | 32 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,222.9 ns | 5.99 ns | 5.60 ns | 0.90 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,316.6 ns | 7.06 ns | 6.61 ns | 1.00 | 0.0420 | - | - | 88 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,274.7 ns | 7.04 ns | 6.59 ns | 0.97 | 0.0153 | - | - | 32 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,205.3 ns | 9.70 ns | 15.38 ns | 0.91 | 0.0153 | - | - | 32 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,492.6 ns | 31.99 ns | 28.36 ns | 1.00 | 0.0458 | - | - | 96 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,754.4 ns | 17.22 ns | 16.11 ns | 1.06 | 0.0153 | - | - | 32 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|----------:|-----------:|-------------:|--------:|-------:|----------:| +| Linq_Array | Array | 100 | 528.6 ns | 47.16 ns | 139.06 ns | 442.5 ns | baseline | | 0.0229 | 48 B | +| StructLinq_Array | Array | 100 | 352.1 ns | 6.21 ns | 7.85 ns | 353.0 ns | 1.50x faster | 0.45x | - | - | +| Hyperlinq_Array | Array | 100 | 342.8 ns | 4.60 ns | 4.30 ns | 341.9 ns | 1.69x faster | 0.51x | - | - | +| Hyperlinq_Span | Array | 100 | 341.2 ns | 4.70 ns | 4.40 ns | 341.4 ns | 1.70x faster | 0.52x | - | - | +| Hyperlinq_Memory | Array | 100 | 389.4 ns | 2.50 ns | 2.21 ns | 389.3 ns | 1.45x faster | 0.44x | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 700.4 ns | 60.47 ns | 177.33 ns | 589.6 ns | baseline | | 0.0420 | 88 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 484.1 ns | 6.15 ns | 5.14 ns | 482.3 ns | 1.21x faster | 0.13x | 0.0153 | 32 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 331.4 ns | 4.30 ns | 4.02 ns | 332.4 ns | 1.77x faster | 0.21x | - | - | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 641.3 ns | 29.34 ns | 79.82 ns | 617.6 ns | baseline | | 0.0420 | 88 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 482.8 ns | 3.83 ns | 3.59 ns | 482.9 ns | 1.48x faster | 0.14x | 0.0153 | 32 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 369.8 ns | 6.14 ns | 5.74 ns | 366.9 ns | 1.93x faster | 0.17x | - | - | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 506.5 ns | 6.73 ns | 6.30 ns | 505.0 ns | baseline | | 0.0420 | 88 B | +| StructLinq_List_Value | List_Value | 100 | 341.2 ns | 2.57 ns | 2.41 ns | 340.5 ns | 1.48x faster | 0.02x | - | - | +| Hyperlinq_List_Value | List_Value | 100 | 406.5 ns | 3.99 ns | 3.33 ns | 405.9 ns | 1.25x faster | 0.02x | 0.0153 | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,012.0 ns | 45.64 ns | 40.45 ns | 5,007.0 ns | baseline | | 0.0458 | 96 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 4,672.8 ns | 28.87 ns | 25.59 ns | 4,663.9 ns | 1.07x faster | 0.01x | - | - | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 525.5 ns | 14.55 ns | 42.21 ns | 502.9 ns | baseline | | 0.0420 | 88 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 475.2 ns | 8.83 ns | 7.83 ns | 472.5 ns | 1.23x faster | 0.07x | 0.0153 | 32 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 423.4 ns | 8.31 ns | 11.92 ns | 425.0 ns | 1.38x faster | 0.08x | 0.0153 | 32 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 506.3 ns | 6.18 ns | 5.16 ns | 507.1 ns | baseline | | 0.0420 | 88 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 481.6 ns | 3.45 ns | 3.06 ns | 481.7 ns | 1.05x faster | 0.01x | 0.0153 | 32 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 403.2 ns | 2.46 ns | 1.92 ns | 403.6 ns | 1.25x faster | 0.01x | 0.0153 | 32 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 509.9 ns | 7.13 ns | 6.67 ns | 506.9 ns | baseline | | 0.0420 | 88 B | +| StructLinq_List_Reference | List_Reference | 100 | 486.1 ns | 4.01 ns | 3.75 ns | 485.3 ns | 1.05x faster | 0.02x | 0.0153 | 32 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 405.0 ns | 1.29 ns | 1.14 ns | 404.9 ns | 1.26x faster | 0.02x | 0.0153 | 32 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,000.2 ns | 37.85 ns | 35.41 ns | 4,984.2 ns | baseline | | 0.0458 | 96 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,690.6 ns | 53.19 ns | 47.15 ns | 4,666.9 ns | 1.07x faster | 0.01x | 0.0153 | 32 B | diff --git a/Benchmarks/WhereToArrayBenchmarks.md b/Benchmarks/WhereToArrayBenchmarks.md index 62dc3c37a..1e2b1d668 100644 --- a/Benchmarks/WhereToArrayBenchmarks.md +++ b/Benchmarks/WhereToArrayBenchmarks.md @@ -4,57 +4,57 @@ [WhereToArrayBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToArrayBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 424.1 ns | 8.54 ns | 16.45 ns | 415.1 ns | 1.00 | 0.00 | 0.3519 | - | - | 736 B | -| StructLinq_Array | Array | 100 | 410.3 ns | 7.67 ns | 13.23 ns | 403.1 ns | 0.97 | 0.02 | 0.1144 | - | - | 240 B | -| Hyperlinq_Array | Array | 100 | 513.2 ns | 5.71 ns | 5.06 ns | 512.0 ns | 1.16 | 0.05 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,389.3 ns | 8.52 ns | 7.55 ns | 1,387.9 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,179.6 ns | 6.07 ns | 5.68 ns | 1,179.8 ns | 0.85 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 545.9 ns | 5.84 ns | 5.47 ns | 545.0 ns | 0.39 | 0.00 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,300.4 ns | 8.52 ns | 7.97 ns | 1,300.4 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,185.6 ns | 5.33 ns | 4.72 ns | 1,186.7 ns | 0.91 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 522.6 ns | 2.02 ns | 1.69 ns | 522.5 ns | 0.40 | 0.00 | 0.1144 | - | - | 240 B | -| | | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,355.6 ns | 25.15 ns | 27.96 ns | 1,367.7 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Value | List_Value | 100 | 812.9 ns | 3.54 ns | 3.14 ns | 813.1 ns | 0.60 | 0.01 | 0.1144 | - | - | 240 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,370.0 ns | 8.07 ns | 7.15 ns | 1,366.5 ns | 1.02 | 0.02 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,086.6 ns | 49.27 ns | 43.68 ns | 5,070.8 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,883.8 ns | 10.40 ns | 9.22 ns | 2,883.1 ns | 0.57 | 0.01 | 0.3357 | - | - | 720 B | -| | | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,282.7 ns | 4.93 ns | 4.37 ns | 1,282.7 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,192.7 ns | 8.80 ns | 7.80 ns | 1,191.1 ns | 0.93 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,327.2 ns | 20.85 ns | 19.50 ns | 1,329.5 ns | 1.03 | 0.02 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,355.8 ns | 7.95 ns | 7.43 ns | 1,354.1 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,190.5 ns | 9.14 ns | 7.13 ns | 1,188.1 ns | 0.88 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,324.2 ns | 22.65 ns | 21.19 ns | 1,331.9 ns | 0.98 | 0.02 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,283.1 ns | 7.13 ns | 6.32 ns | 1,281.3 ns | 1.00 | 0.00 | 0.3700 | - | - | 776 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,226.3 ns | 10.26 ns | 9.60 ns | 1,225.4 ns | 0.96 | 0.01 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,343.9 ns | 7.08 ns | 6.28 ns | 1,344.4 ns | 1.05 | 0.01 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,045.7 ns | 22.45 ns | 17.53 ns | 5,052.5 ns | 1.00 | 0.00 | 0.4501 | - | - | 952 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,620.7 ns | 12.19 ns | 11.40 ns | 3,622.7 ns | 0.72 | 0.00 | 0.3548 | - | - | 752 B | +| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-------------:|--------:|-------:|----------:| +| Linq_Array | Array | 100 | 434.2 ns | 1.36 ns | 1.27 ns | baseline | | 0.3519 | 736 B | +| StructLinq_Array | Array | 100 | 437.4 ns | 2.51 ns | 2.35 ns | 1.01x slower | 0.00x | 0.1144 | 240 B | +| Hyperlinq_Array | Array | 100 | 577.6 ns | 6.89 ns | 6.11 ns | 1.33x slower | 0.02x | 0.1144 | 240 B | +| | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 555.0 ns | 2.43 ns | 2.27 ns | baseline | | 0.3710 | 776 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 616.8 ns | 1.73 ns | 1.45 ns | 1.11x slower | 0.00x | 0.1297 | 272 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 614.7 ns | 3.39 ns | 3.00 ns | 1.11x slower | 0.01x | 0.1144 | 240 B | +| | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 584.4 ns | 3.80 ns | 3.56 ns | baseline | | 0.3710 | 776 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 610.2 ns | 4.36 ns | 3.86 ns | 1.04x slower | 0.01x | 0.1297 | 272 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 596.2 ns | 5.27 ns | 4.11 ns | 1.02x slower | 0.01x | 0.1144 | 240 B | +| | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 576.4 ns | 2.46 ns | 2.06 ns | baseline | | 0.3710 | 776 B | +| StructLinq_List_Value | List_Value | 100 | 502.4 ns | 3.02 ns | 2.82 ns | 1.15x faster | 0.01x | 0.1144 | 240 B | +| Hyperlinq_List_Value | List_Value | 100 | 750.1 ns | 5.04 ns | 4.72 ns | 1.30x slower | 0.01x | 0.1297 | 272 B | +| | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,109.9 ns | 21.88 ns | 20.47 ns | baseline | | 0.4501 | 952 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,017.0 ns | 10.32 ns | 9.66 ns | 1.69x faster | 0.01x | 0.3433 | 720 B | +| | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 555.3 ns | 2.73 ns | 2.56 ns | baseline | | 0.3710 | 776 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 616.8 ns | 8.58 ns | 8.02 ns | 1.11x slower | 0.02x | 0.1297 | 272 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 717.4 ns | 13.31 ns | 11.11 ns | 1.29x slower | 0.02x | 0.1297 | 272 B | +| | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 585.6 ns | 11.67 ns | 23.58 ns | baseline | | 0.3710 | 776 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 612.1 ns | 11.94 ns | 14.66 ns | 1.03x slower | 0.06x | 0.1297 | 272 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 712.0 ns | 14.18 ns | 18.44 ns | 1.20x slower | 0.07x | 0.1297 | 272 B | +| | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 577.9 ns | 3.49 ns | 3.09 ns | baseline | | 0.3710 | 776 B | +| StructLinq_List_Reference | List_Reference | 100 | 601.2 ns | 0.76 ns | 0.60 ns | 1.04x slower | 0.01x | 0.1297 | 272 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 725.8 ns | 4.94 ns | 4.62 ns | 1.26x slower | 0.01x | 0.1297 | 272 B | +| | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,201.5 ns | 24.53 ns | 22.94 ns | baseline | | 0.4501 | 952 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,198.6 ns | 10.74 ns | 8.97 ns | 1.63x faster | 0.01x | 0.3586 | 752 B | diff --git a/Benchmarks/WhereToListBenchmarks.md b/Benchmarks/WhereToListBenchmarks.md index dbb732e7e..a51bbca4b 100644 --- a/Benchmarks/WhereToListBenchmarks.md +++ b/Benchmarks/WhereToListBenchmarks.md @@ -4,57 +4,57 @@ [WhereToListBenchmarks.cs](../NetFabric.Hyperlinq.Benchmarks/Benchmarks/WhereToListBenchmarks.cs) ### References: -- Linq: 6.0.0-preview.5.21301.5 +- Linq: 6.0.0-preview.7.21377.19 - System.Linq.Async: [5.0.0](https://www.nuget.org/packages/System.Linq.Async/5.0.0) - System.Interactive: [5.0.0](https://www.nuget.org/packages/System.Interactive/5.0.0) - System.Interactive.Async: [5.0.0](https://www.nuget.org/packages/System.Interactive.Async/5.0.0) -- StructLinq: [0.26.0](https://www.nuget.org/packages/StructLinq/0.26.0) -- NetFabric.Hyperlinq: [3.0.0-beta44](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta44) +- StructLinq: [0.27.0](https://www.nuget.org/packages/StructLinq/0.27.0) +- NetFabric.Hyperlinq: [3.0.0-beta45](https://www.nuget.org/packages/NetFabric.Hyperlinq/3.0.0-beta45) ### Results: ``` ini -BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1055 (21H1/May2021Update) -Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores -.NET SDK=6.0.100-preview.5.21302.13 - [Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT - Job-UNTOJZ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT +BenchmarkDotNet=v0.13.1.1606-nightly, OS=macOS Catalina 10.15.7 (19H1323) [Darwin 19.6.0] +Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores +.NET SDK=6.0.100-preview.7.21379.14 + [Host] : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT + .NET 6 PGO : .NET 6.0.0 (6.0.21.37719), X64 RyuJIT -Runtime=.NET 6.0 +Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated | -|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:| -| Linq_Array | Array | 100 | 373.4 ns | 2.74 ns | 2.29 ns | 1.00 | 0.00 | 0.3328 | - | - | 696 B | -| StructLinq_Array | Array | 100 | 403.2 ns | 8.08 ns | 10.50 ns | 1.06 | 0.03 | 0.1297 | - | - | 272 B | -| Hyperlinq_Array | Array | 100 | 523.5 ns | 5.29 ns | 4.94 ns | 1.40 | 0.02 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,146.8 ns | 8.29 ns | 7.34 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,187.8 ns | 5.78 ns | 5.41 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 557.3 ns | 3.76 ns | 3.14 ns | 0.49 | 0.00 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 1,141.7 ns | 5.63 ns | 4.99 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 1,189.0 ns | 6.01 ns | 5.32 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 529.1 ns | 3.03 ns | 2.53 ns | 0.46 | 0.00 | 0.1297 | - | - | 272 B | -| | | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 1,203.5 ns | 23.17 ns | 29.30 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Value | List_Value | 100 | 852.3 ns | 13.88 ns | 12.30 ns | 0.72 | 0.02 | 0.1297 | - | - | 272 B | -| Hyperlinq_List_Value | List_Value | 100 | 1,354.1 ns | 18.55 ns | 17.35 ns | 1.13 | 0.04 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,047.5 ns | 79.12 ns | 74.01 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,963.9 ns | 57.98 ns | 56.94 ns | 0.59 | 0.01 | 0.3586 | - | - | 752 B | -| | | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,140.2 ns | 6.42 ns | 6.01 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,199.0 ns | 5.03 ns | 4.46 ns | 1.05 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,333.4 ns | 7.53 ns | 6.68 ns | 1.17 | 0.01 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 1,199.3 ns | 23.37 ns | 22.95 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,242.0 ns | 13.75 ns | 12.19 ns | 1.04 | 0.01 | 0.1450 | - | - | 304 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 1,320.5 ns | 5.12 ns | 4.28 ns | 1.10 | 0.02 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 1,157.6 ns | 20.87 ns | 28.57 ns | 1.00 | 0.00 | 0.3510 | - | - | 736 B | -| StructLinq_List_Reference | List_Reference | 100 | 1,210.0 ns | 23.79 ns | 23.37 ns | 1.04 | 0.02 | 0.1450 | - | - | 304 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 1,408.2 ns | 7.30 ns | 6.48 ns | 1.20 | 0.03 | 0.1450 | - | - | 304 B | -| | | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 4,964.4 ns | 21.77 ns | 19.30 ns | 1.00 | 0.00 | 0.3510 | - | - | 744 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,551.4 ns | 10.45 ns | 9.26 ns | 0.72 | 0.00 | 0.3738 | - | - | 784 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|---------:|---------:|-----------:|-------------:|--------:|-------:|----------:| +| Linq_Array | Array | 100 | 397.0 ns | 1.32 ns | 1.10 ns | 396.7 ns | baseline | | 0.3328 | 696 B | +| StructLinq_Array | Array | 100 | 467.5 ns | 6.04 ns | 5.35 ns | 466.2 ns | 1.18x slower | 0.01x | 0.1297 | 272 B | +| Hyperlinq_Array | Array | 100 | 616.5 ns | 10.59 ns | 8.84 ns | 617.4 ns | 1.55x slower | 0.02x | 0.1297 | 272 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 516.6 ns | 5.42 ns | 5.07 ns | 515.2 ns | baseline | | 0.3519 | 736 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 611.8 ns | 6.76 ns | 6.00 ns | 610.1 ns | 1.18x slower | 0.02x | 0.1450 | 304 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 668.4 ns | 16.30 ns | 43.80 ns | 649.7 ns | 1.35x slower | 0.10x | 0.1297 | 272 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 525.4 ns | 5.74 ns | 5.37 ns | 523.4 ns | baseline | | 0.3519 | 736 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 576.8 ns | 4.23 ns | 3.54 ns | 576.6 ns | 1.10x slower | 0.01x | 0.1450 | 304 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 703.4 ns | 15.04 ns | 41.93 ns | 687.7 ns | 1.41x slower | 0.10x | 0.1297 | 272 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 517.3 ns | 5.27 ns | 4.67 ns | 515.5 ns | baseline | | 0.3519 | 736 B | +| StructLinq_List_Value | List_Value | 100 | 536.5 ns | 3.80 ns | 3.37 ns | 535.7 ns | 1.04x slower | 0.01x | 0.1297 | 272 B | +| Hyperlinq_List_Value | List_Value | 100 | 836.0 ns | 9.89 ns | 7.72 ns | 835.3 ns | 1.62x slower | 0.02x | 0.1450 | 304 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 5,264.3 ns | 17.15 ns | 14.32 ns | 5,263.1 ns | baseline | | 0.3510 | 744 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 3,202.6 ns | 56.35 ns | 47.05 ns | 3,200.3 ns | 1.64x faster | 0.03x | 0.3586 | 752 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 520.4 ns | 6.68 ns | 5.92 ns | 517.4 ns | baseline | | 0.3519 | 736 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 610.1 ns | 5.59 ns | 4.95 ns | 609.4 ns | 1.17x slower | 0.02x | 0.1450 | 304 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 770.1 ns | 15.17 ns | 19.72 ns | 768.2 ns | 1.47x slower | 0.04x | 0.1450 | 304 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 519.3 ns | 4.43 ns | 4.14 ns | 518.1 ns | baseline | | 0.3519 | 736 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 624.5 ns | 18.32 ns | 49.83 ns | 606.0 ns | 1.22x slower | 0.11x | 0.1450 | 304 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 754.0 ns | 11.22 ns | 9.37 ns | 753.6 ns | 1.45x slower | 0.02x | 0.1450 | 304 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 518.8 ns | 5.66 ns | 5.29 ns | 517.9 ns | baseline | | 0.3519 | 736 B | +| StructLinq_List_Reference | List_Reference | 100 | 652.0 ns | 12.89 ns | 18.07 ns | 648.6 ns | 1.25x slower | 0.03x | 0.1450 | 304 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 815.1 ns | 16.32 ns | 27.71 ns | 809.2 ns | 1.58x slower | 0.06x | 0.1450 | 304 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 5,203.8 ns | 20.01 ns | 16.71 ns | 5,196.0 ns | baseline | | 0.3510 | 744 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 3,274.2 ns | 49.93 ns | 46.71 ns | 3,252.6 ns | 1.59x faster | 0.02x | 0.3738 | 784 B | diff --git a/NetFabric.Hyperlinq.Abstractions/IFunction.cs b/NetFabric.Hyperlinq.Abstractions/IFunction.cs index 446d2eba0..1133f3133 100644 --- a/NetFabric.Hyperlinq.Abstractions/IFunction.cs +++ b/NetFabric.Hyperlinq.Abstractions/IFunction.cs @@ -1,52 +1,64 @@ -namespace NetFabric.Hyperlinq +using System.Diagnostics.Contracts; + +namespace NetFabric.Hyperlinq { public interface IFunction { + [Pure] TResult Invoke(); } public interface IFunction { + [Pure] TResult Invoke(T arg); } public interface IFunction { + [Pure] TResult Invoke(T1 arg1, T2 arg2); } public interface IFunction { + [Pure] TResult Invoke(T1 arg1, T2 arg2, T3 arg3); } public interface IFunction { + [Pure] TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4); } public interface IFunction { + [Pure] TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); } public interface IFunction { + [Pure] TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); } public interface IFunction { + [Pure] TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); } public interface IFunction { + [Pure] TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); } public interface IFunction { + [Pure] TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); } } diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs deleted file mode 100644 index cf564b9bf..000000000 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayArrayPoolBenchmarks.cs +++ /dev/null @@ -1,162 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Configs; -using StructLinq; -using System.Buffers; -using System.Linq; -using System.Threading.Tasks; - -namespace NetFabric.Hyperlinq.Benchmarks -{ - [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] - [CategoriesColumn] - public class ToArrayArrayPoolBenchmarks: RandomBenchmarksBase - { - - [BenchmarkCategory("Array")] - [Benchmark(Baseline = true)] - public int Hyperlinq_Array() - { - var values = array.AsValueEnumerable().ToArray(); - return values.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("Enumerable_Value")] - [Benchmark(Baseline = true)] - public int Hyperlinq_Enumerable_Value() - { - var values = enumerableValue.AsValueEnumerable().ToArray(); - return values.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("Collection_Value")] - [Benchmark(Baseline = true)] - public int Hyperlinq_Collection_Value() - { - var values = collectionValue.AsValueEnumerable().ToArray(); - return values.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("List_Value")] - [Benchmark(Baseline = true)] - public int Hyperlinq_List_Value() - { - var values = listValue.AsValueEnumerable().ToArray(); - return values.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("AsyncEnumerable_Value")] - [Benchmark(Baseline = true)] - public async ValueTask Hyperlinq_AsyncEnumerable_Value() - { - var values = await asyncEnumerableValue.AsAsyncValueEnumerable().ToArrayAsync(); - return values.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("Enumerable_Reference")] - [Benchmark(Baseline = true)] - public int Hyperlinq_Enumerable_Reference() - { - var values = enumerableReference.AsValueEnumerable().ToArray(); - return values.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("Collection_Reference")] - [Benchmark(Baseline = true)] - public int Hyperlinq_Collection_Reference() - { - var values = collectionReference.AsValueEnumerable().ToArray(); - return values.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("List_Reference")] - [Benchmark(Baseline = true)] - public int Hyperlinq_List_Reference() - { - var values = listReference.AsValueEnumerable().ToArray(); - return values.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("AsyncEnumerable_Reference")] - [Benchmark(Baseline = true)] - public async ValueTask Hyperlinq_AsyncEnumerable_Reference() - { - var values = await asyncEnumerableReference.AsAsyncValueEnumerable().ToArrayAsync(); - return values.AsValueEnumerable().Sum(); - } - - // --------------------------------------------------------------------- - - [BenchmarkCategory("Array")] - [Benchmark] - public int Hyperlinq_Array_ArrayPool() - { - using var values = array.AsValueEnumerable().ToArray(ArrayPool.Shared); - return values.Memory.Span.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("Enumerable_Value")] - [Benchmark] - public int Hyperlinq_Enumerable_Value_ArrayPool() - { - using var values = enumerableValue.AsValueEnumerable().ToArray(ArrayPool.Shared); - return values.Memory.Span.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("Collection_Value")] - [Benchmark] - public int Hyperlinq_Collection_Value_ArrayPool() - { - using var values = collectionValue.AsValueEnumerable().ToArray(ArrayPool.Shared); - return values.Memory.Span.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("List_Value")] - [Benchmark] - public int Hyperlinq_List_Value_ArrayPool() - { - using var values = listValue.AsValueEnumerable().ToArray(ArrayPool.Shared); - return values.Memory.Span.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("AsyncEnumerable_Value")] - [Benchmark] - public async ValueTask Hyperlinq_AsyncEnumerable_Value_ArrayPool() - { - using var values = await asyncEnumerableValue.AsAsyncValueEnumerable().ToArrayAsync(ArrayPool.Shared); - return values.Memory.Span.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("Enumerable_Reference")] - [Benchmark] - public int Hyperlinq_Enumerable_Reference_ArrayPool() - { - using var values = enumerableReference.AsValueEnumerable().ToArray(ArrayPool.Shared); - return values.Memory.Span.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("Collection_Reference")] - [Benchmark] - public int Hyperlinq_Collection_Reference_ArrayPool() - { - using var values = collectionReference.AsValueEnumerable().ToArray(ArrayPool.Shared); - return values.Memory.Span.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("List_Reference")] - [Benchmark] - public int Hyperlinq_List_Reference_ArrayPool() - { - using var values = listReference.AsValueEnumerable().ToArray(ArrayPool.Shared); - return values.Memory.Span.AsValueEnumerable().Sum(); - } - - [BenchmarkCategory("AsyncEnumerable_Reference")] - [Benchmark] - public async ValueTask Hyperlinq_AsyncEnumerable_Reference_ArrayPool() - { - using var values = await asyncEnumerableReference.AsAsyncValueEnumerable().ToArrayAsync(ArrayPool.Shared); - return values.Memory.Span.AsValueEnumerable().Sum(); - } - - } -} diff --git a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs index fa8a993fe..ea474c86c 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Benchmarks/ToArrayBenchmarks.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq.Benchmarks [CategoriesColumn] public class ToArrayBenchmarks: RandomBenchmarksBase { - [BenchmarkCategory("Array")] [Benchmark(Baseline = true)] public int[] Linq_Array() @@ -171,5 +170,94 @@ public ValueTask Hyperlinq_AsyncEnumerable_Reference() => asyncEnumerableReference .AsAsyncValueEnumerable() .ToArrayAsync(); + + // --------------------------------------------------------------------- + + [BenchmarkCategory("Array")] + [Benchmark] + public IMemoryOwner Hyperlinq_Array_ArrayPool() + { + using var buffer = array.AsValueEnumerable() + .ToArray(ArrayPool.Shared); + return buffer; + } + + [BenchmarkCategory("Enumerable_Value")] + [Benchmark] + public IMemoryOwner Hyperlinq_Enumerable_ArrayPool_Value() + { + using var buffer = enumerableValue.AsValueEnumerable() + .ToArray(ArrayPool.Shared); + return buffer; + } + + [BenchmarkCategory("Collection_Value")] + [Benchmark] + public IMemoryOwner Hyperlinq_Collection_ArrayPool_Value() + { + using var buffer = collectionValue.AsValueEnumerable() + .ToArray(ArrayPool.Shared); + return buffer; + } + + [BenchmarkCategory("List_Value")] + [Benchmark] + public IMemoryOwner Hyperlinq_List_ArrayPool_Value() + { + using var buffer = listValue + .AsValueEnumerable() + .ToArray(ArrayPool.Shared); + return buffer; + } + + [BenchmarkCategory("AsyncEnumerable_Value")] + [Benchmark] + public async ValueTask> Hyperlinq_AsyncEnumerable_ArrayPool_Value() + { + using var buffer = await asyncEnumerableValue + .AsAsyncValueEnumerable() + .ToArrayAsync(ArrayPool.Shared); + return buffer; + } + + [BenchmarkCategory("Enumerable_Reference")] + [Benchmark] + public IMemoryOwner Hyperlinq_Enumerable_ArrayPool_Reference() + { + using var buffer = enumerableReference + .AsValueEnumerable() + .ToArray(ArrayPool.Shared); + return buffer; + } + + [BenchmarkCategory("Collection_Reference")] + [Benchmark] + public IMemoryOwner Hyperlinq_Collection_ArrayPool_Reference() + { + using var buffer = collectionReference + .AsValueEnumerable() + .ToArray(ArrayPool.Shared); + return buffer; + } + + [BenchmarkCategory("List_Reference")] + [Benchmark] + public IMemoryOwner Hyperlinq_List_ArrayPool_Reference() + { + using var buffer = listReference + .AsValueEnumerable() + .ToArray(ArrayPool.Shared); + return buffer; + } + + [BenchmarkCategory("AsyncEnumerable_Reference")] + [Benchmark] + public async ValueTask> Hyperlinq_AsyncEnumerable_ArrayPool_Reference() + { + using var buffer = await asyncEnumerableReference + .AsAsyncValueEnumerable() + .ToArrayAsync(ArrayPool.Shared); + return buffer; + } } } diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index 794ee51ce..c34ffc150 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -18,7 +18,7 @@ - + diff --git a/NetFabric.Hyperlinq.Benchmarks/Program.cs b/NetFabric.Hyperlinq.Benchmarks/Program.cs index c65e9146c..719f44b07 100644 --- a/NetFabric.Hyperlinq.Benchmarks/Program.cs +++ b/NetFabric.Hyperlinq.Benchmarks/Program.cs @@ -22,7 +22,13 @@ static void Main(string[] args) { var config = DefaultConfig.Instance .WithSummaryStyle(SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend)) - .AddJob(Job.Default.WithRuntime(CoreRuntime.Core60)) + .AddJob(Job.Default + .WithRuntime(CoreRuntime.Core60) + .WithEnvironmentVariables( + new EnvironmentVariable("COMPlus_ReadyToRun", "0"), + new EnvironmentVariable("COMPlus_TC_QuickJitForLoops", "1"), + new EnvironmentVariable("COMPlus_TieredPGO", "1")) + .WithId(".NET 6 PGO")) .AddDiagnoser(MemoryDiagnoser.Default); foreach (var summary in BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config)) diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs b/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs index a701931f8..b2c8dcd37 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs @@ -20,7 +20,7 @@ public static bool SequenceEqual(this Span first, IEnumerable second, I public static bool SequenceEqual(this ReadOnlySpan first, IEnumerable second, IEqualityComparer? comparer = default) { - if (Utils.IsValueType() && Utils.UseDefault(comparer)) + if (Utils.IsValueType() && comparer.UseDefaultComparer()) { using var enumerator = second.GetEnumerator(); for (var index = 0; true; index++) diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs index 3c2fdac47..cdacc0d01 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs @@ -68,7 +68,7 @@ public ValueTask ToArrayAsync() => this.ToArrayAsync, AsyncEnumerator, TSource>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => this.ToArrayAsync, AsyncEnumerator, TSource>(pool, cancellationToken, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs index 791bbfc2a..eb69ce185 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs @@ -83,7 +83,7 @@ public ValueTask ToArrayAsync() => this.ToArrayAsync, TEnumerator, TSource>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => this.ToArrayAsync, TEnumerator, TSource>(pool, cancellationToken, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs index 14cda05d5..b75026b7e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs @@ -45,7 +45,7 @@ public TSource[] ToArray() => this.ToArray, ValueEnumerator, TSource>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => this.ToArray, ValueEnumerator, TSource>(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -58,7 +58,7 @@ public List ToList() public bool Contains(TSource value, IEqualityComparer? comparer = default) { - if (Utils.UseDefault(comparer) && source is ICollection collection) + if (comparer.UseDefaultComparer() && source is ICollection collection) return collection.Contains(value); return this.Contains, ValueEnumerator, TSource>(value, comparer); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index fc14604c5..2a5f15979 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -41,33 +41,39 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - public void CopyTo(Span span) + [SkipLocalsInit] + public void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) return; - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + if (array.Length - arrayIndex < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - using var enumerator = GetEnumerator(); - checked + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; + collection.CopyTo(array, arrayIndex); } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - { - switch (source) + else { - case ICollection collection: - collection.CopyTo(array, arrayIndex); - break; - default: - CopyTo(array.AsSpan(arrayIndex)); - break; + using var enumerator = GetEnumerator(); + if (arrayIndex is 0 && array.Length == Count) + { + for (var index = 0; index < array.Length; index++) + { + _ = enumerator.MoveNext(); + array[index] = enumerator.Current; + } + } + else + { + checked + { + for (var index = arrayIndex; enumerator.MoveNext(); index++) + array[index] = enumerator.Current; + } + } } } @@ -93,17 +99,32 @@ public ValueEnumerable AsValueEnumerable() public IReadOnlyCollection AsEnumerable() => source; - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public TSource[] ToArray() - => ValueReadOnlyCollectionExtensions.ToArray, ValueEnumerator, TSource>(this); + { + if (source.Count is 0) + return Array.Empty(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => ValueReadOnlyCollectionExtensions.ToArray, ValueEnumerator, TSource>(this, pool, clearOnDispose); + var result = Utils.AllocateUninitializedArray(source.Count); + CopyTo(result, 0); + return result; + } + + [SkipLocalsInit] + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + { + if (source.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(source.Count, clearOnDispose); + CopyTo(result.Rented, 0); + return result; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public List ToList() - => ValueReadOnlyCollectionExtensions.ToList, ValueEnumerator, TSource>(this); + => ToArray().AsList(); #endregion #region Quantifier diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs index 4a3a9f374..51198e4df 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs @@ -62,35 +62,39 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - public void CopyTo(Span span) + [SkipLocalsInit] + public void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) return; - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + if (array.Length - arrayIndex < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - using var enumerator = GetEnumerator(); - checked + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; + collection.CopyTo(array, arrayIndex); } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - { - switch (source) + else { - // ReSharper disable once HeapView.PossibleBoxingAllocation - case ICollection collection: - collection.CopyTo(array, arrayIndex); - break; - - default: - CopyTo(array.AsSpan(arrayIndex)); - break; + using var enumerator = GetEnumerator(); + if (arrayIndex is 0 && array.Length == Count) + { + for (var index = 0; index < array.Length; index++) + { + _ = enumerator.MoveNext(); + array[index] = enumerator.Current; + } + } + else + { + checked + { + for (var index = arrayIndex; enumerator.MoveNext(); index++) + array[index] = enumerator.Current; + } + } } } @@ -160,17 +164,32 @@ public IReadOnlyCollection AsEnumerable() // ReSharper disable once HeapView.PossibleBoxingAllocation => source; - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public TSource[] ToArray() - => ValueReadOnlyCollectionExtensions.ToArray, ValueEnumerator, TSource>(this); + { + if (source.Count is 0) + return Array.Empty(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => ValueReadOnlyCollectionExtensions.ToArray, ValueEnumerator, TSource>(this, pool, clearOnDispose); + var result = Utils.AllocateUninitializedArray(source.Count); + CopyTo(result, 0); + return result; + } + + [SkipLocalsInit] + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + { + if (source.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(source.Count, clearOnDispose); + CopyTo(result.Rented, 0); + return result; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public List ToList() - => ValueReadOnlyCollectionExtensions.ToList, ValueEnumerator, TSource>(this); + => ToArray().AsList(); #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs index 037622de7..cf3406b8b 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs @@ -50,7 +50,7 @@ public IEnumerable AsEnumerable() public bool Contains(TSource value, IEqualityComparer? comparer = default) { - if (Utils.UseDefault(comparer) && source is ICollection collection) + if (comparer.UseDefaultComparer() && source is ICollection collection) return collection.Contains(value); return source.Contains, TEnumerator, TSource>(value, comparer); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index 4a400b0c0..f77525e38 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -45,27 +46,42 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - public void CopyTo(Span span) - { + [SkipLocalsInit] + public void CopyTo(TSource[] array, int arrayIndex) + { if (Count is 0) return; - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + if (array.Length - arrayIndex < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - using var enumerator = GetEnumerator(); - checked + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; + collection.CopyTo(array, arrayIndex); + } + else + { + using var enumerator = GetEnumerator(); + if (arrayIndex is 0 && array.Length == Count) + { + for (var index = 0; index < array.Length; index++) + { + _ = enumerator.MoveNext(); + array[index] = enumerator.Current; + } + } + else + { + checked + { + for (var index = arrayIndex; enumerator.MoveNext(); index++) + array[index] = enumerator.Current; + } + } } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan(arrayIndex)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] bool ICollection.Contains(TSource item) => Contains(item, default); @@ -87,6 +103,33 @@ public ValueEnumerable AsValueEnumerable() public IReadOnlyCollection AsEnumerable() => source; + + [SkipLocalsInit] + public TSource[] ToArray() + { + if (source.Count is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(source.Count); + CopyTo(result, 0); + return result; + } + + [SkipLocalsInit] + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + { + if (source.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(source.Count, clearOnDispose); + CopyTo(result.Rented, 0); + return result; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] + public List ToList() + => ToArray().AsList(); #endregion @@ -97,7 +140,7 @@ public bool Contains(TSource value, IEqualityComparer? comparer = defau if (Count is 0) return false; - if (Utils.UseDefault(comparer) && source is ICollection collection) + if (comparer.UseDefaultComparer() && source is ICollection collection) return collection.Contains(value); return source.Contains, TEnumerator, TSource>(value, comparer); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs index 1c8d98203..f6a7dd9ff 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -86,7 +86,7 @@ public TSource[] ToArray() => this.ToArray, TEnumerator, TSource>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => this.ToArray, TEnumerator, TSource>(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -100,7 +100,7 @@ public List ToList() public bool Contains(TSource value, IEqualityComparer? comparer = default) { // ReSharper disable once HeapView.PossibleBoxingAllocation - if (Utils.UseDefault(comparer) && source is ICollection collection) + if (comparer.UseDefaultComparer() && source is ICollection collection) return collection.Contains(value); return this.Contains, TEnumerator, TSource>(value, comparer); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index c4d252b6f..a06085e2f 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -80,31 +80,44 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - public void CopyTo(Span span) + [SkipLocalsInit] + public void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) return; - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + if (array.Length - arrayIndex < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - if (source.Count is not 0) + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + { + collection.CopyTo(array, arrayIndex); + } + else { using var enumerator = getEnumerator.Invoke(source); - checked + if (arrayIndex is 0 && array.Length == Count) + { + for (var index = 0; index < array.Length; index++) + { + _ = enumerator.MoveNext(); + array[index] = enumerator.Current; + } + } + else { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; + checked + { + for (var index = arrayIndex; enumerator.MoveNext(); index++) + array[index] = enumerator.Current; + } } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan(arrayIndex)); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] bool ICollection.Contains(TSource item) => Contains(item, default); @@ -128,17 +141,32 @@ public ValueEnumerable source; - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public TSource[] ToArray() - => ValueReadOnlyCollectionExtensions.ToArray, TEnumerator, TSource>(this); + { + if (source.Count is 0) + return Array.Empty(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => ValueReadOnlyCollectionExtensions.ToArray, TEnumerator, TSource>(this, pool, clearOnDispose); + var result = Utils.AllocateUninitializedArray(source.Count); + CopyTo(result, 0); + return result; + } + + [SkipLocalsInit] + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + { + if (source.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(source.Count, clearOnDispose); + CopyTo(result.Rented, 0); + return result; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public List ToList() - => ValueReadOnlyCollectionExtensions.ToList, TEnumerator, TSource>(this); + => ToArray().AsList(); #endregion #region Quantifier diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs index e5de4a7fb..639bef0d8 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs @@ -87,7 +87,7 @@ public TEnumerable AsEnumerable() public bool Contains(TSource value, IEqualityComparer? comparer = default) { // ReSharper disable once HeapView.PossibleBoxingAllocation - if (Utils.UseDefault(comparer) && source is ICollection collection) + if (comparer.UseDefaultComparer() && source is ICollection collection) return collection.Contains(value); return source.Contains(value, comparer); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index ace418be4..28aabf70a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -82,33 +83,39 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - public void CopyTo(Span span) + [SkipLocalsInit] + public void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) return; - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + if (array.Length - arrayIndex < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - using var enumerator = getEnumerator.Invoke(source); - checked + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; + collection.CopyTo(array, arrayIndex); } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - { - switch (source) + else { - case ICollection collection: - collection.CopyTo(array, arrayIndex); - break; - default: - CopyTo(array.AsSpan(arrayIndex)); - break; + using var enumerator = getEnumerator.Invoke(source); + if (arrayIndex is 0 && array.Length == Count) + { + for (var index = 0; index < array.Length; index++) + { + _ = enumerator.MoveNext(); + array[index] = enumerator.Current; + } + } + else + { + checked + { + for (var index = arrayIndex; enumerator.MoveNext(); index++) + array[index] = enumerator.Current; + } + } } } @@ -133,6 +140,33 @@ public ValueEnumerable source; + + [SkipLocalsInit] + public TSource[] ToArray() + { + if (source.Count is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(source.Count); + CopyTo(result, 0); + return result; + } + + [SkipLocalsInit] + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + { + if (source.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(source.Count, clearOnDispose); + CopyTo(result.Rented, 0); + return result; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] + public List ToList() + => ToArray().AsList(); #endregion @@ -144,7 +178,7 @@ public bool Contains(TSource value, IEqualityComparer? comparer = defau return false; // ReSharper disable once HeapView.PossibleBoxingAllocation - if (Utils.UseDefault(comparer) && source is ICollection collection) + if (comparer.UseDefaultComparer() && source is ICollection collection) return collection.Contains(value); return ValueReadOnlyCollectionExtensions.Contains(source, value, comparer); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs index 936d903ff..957fa250f 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -93,34 +94,40 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - public void CopyTo(Span span) + + [SkipLocalsInit] + public void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) return; - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); + if (array.Length - arrayIndex < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - using var enumerator = getEnumerator.Invoke(source); - checked + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; + collection.CopyTo(array, arrayIndex); } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - { - switch (source) + else { - // ReSharper disable once HeapView.PossibleBoxingAllocation - case ICollection collection: - collection.CopyTo(array, arrayIndex); - break; - default: - CopyTo(array.AsSpan(arrayIndex)); - break; + using var enumerator = getEnumerator.Invoke(source); + if (arrayIndex is 0 && array.Length == Count) + { + for (var index = 0; index < array.Length; index++) + { + _ = enumerator.MoveNext(); + array[index] = enumerator.Current; + } + } + else + { + checked + { + for (var index = arrayIndex; enumerator.MoveNext(); index++) + array[index] = enumerator.Current; + } + } } } @@ -179,6 +186,33 @@ public readonly ValueEnumerable source; + + [SkipLocalsInit] + public TSource[] ToArray() + { + if (source.Count is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(source.Count); + CopyTo(result, 0); + return result; + } + + [SkipLocalsInit] + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + { + if (source.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(source.Count, clearOnDispose); + CopyTo(result.Rented, 0); + return result; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] + public List ToList() + => ToArray().AsList(); #endregion @@ -212,7 +246,7 @@ public bool Contains(TSource value, IEqualityComparer? comparer = defau return false; // ReSharper disable once HeapView.PossibleBoxingAllocation - if (Utils.UseDefault(comparer) && source is ICollection collection) + if (comparer.UseDefaultComparer() && source is ICollection collection) return collection.Contains(value); return ValueReadOnlyCollectionExtensions.Contains(source, value, comparer); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index f900ab9a1..a75b58fe4 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -72,22 +72,23 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(Span span) - => ((ReadOnlySpan)source.AsSpan()).CopyTo(span); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => ((ICollection)source).CopyTo(array, arrayIndex); + => System.Array.Copy(source.Array!, source.Offset, array, arrayIndex, source.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) - => ((ICollection)source).Contains(item); + => source.Contains(item); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int IndexOf(TSource item) - => ((IList)source).IndexOf(item); - + { + var index = System.Array.IndexOf(source.Array!, item, source.Offset, source.Count); + return index >= 0 + ? index - source.Offset + : -1; + } + [ExcludeFromCodeCoverage] void ICollection.Add(TSource item) => Throw.NotSupportedException(); @@ -160,7 +161,7 @@ public TSource[] ToArray() => source.AsSpan().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.AsSpan().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index 554fb5d71..621f02484 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -67,13 +67,9 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(Span span) - => source.Span.CopyTo(span); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan(arrayIndex)); + => source.Span.CopyTo(array.AsSpan(arrayIndex)); [MethodImpl(MethodImplOptions.AggressiveInlining)] bool ICollection.Contains(TSource item) diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs index c5665efbb..d58fc28ff 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs @@ -8,7 +8,8 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueMemoryOwner ToArray(this Memory source, ArrayPool pool, bool clearOnDispose = default) + [SkipLocalsInit] + public static IMemoryOwner ToArray(this Memory source, ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlyMemory)source).Span.ToArray(pool, clearOnDispose); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs index 0c5bde854..ee17c3a1a 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs @@ -8,7 +8,8 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueMemoryOwner ToArray(this ReadOnlyMemory source, ArrayPool pool, bool clearOnDispose = default) + [SkipLocalsInit] + public static IMemoryOwner ToArray(this ReadOnlyMemory source, ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArray(pool, clearOnDispose); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index 3fa1b0dcc..c92d275d3 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -8,12 +8,16 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] static TSource[] ToArray(this ReadOnlySpan source) => source.ToArray(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose = default) + [SkipLocalsInit] + public static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose = default) { + if (source.Length is 0) + return EmptyMemoryOwner.Instance; + var result = pool.RentDisposable(source.Length, clearOnDispose); Copy(source, result.Memory.Span); return result; @@ -22,28 +26,25 @@ public static ValueMemoryOwner ToArray(this ReadOnlySpan(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, predicate) - }; - - static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) - { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate); - return arrayBuilder.ToArray(); - } + if (source.Length is 0) + return Array.Empty(); + + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, clearOnDispose: false, predicate); + return arrayBuilder.ToArray(); } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + [SkipLocalsInit] + static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { + if (source.Length is 0) + return EmptyMemoryOwner.Instance; + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate); return arrayBuilder.ToArray(pool, clearOnDispose); } @@ -52,28 +53,25 @@ static ValueMemoryOwner ToArray(this ReadOnlySpan< [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] static TSource[] ToArrayAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, predicate) - }; - - static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) - { - using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, false, predicate); - return arrayBuilder.ToArray(); - } + if (source.Length is 0) + return Array.Empty(); + + using var arrayBuilder = ToArrayBuilderAt(source, ArrayPool.Shared, clearOnDispose: false, predicate); + return arrayBuilder.ToArray(); } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + [SkipLocalsInit] + static IMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { + if (source.Length is 0) + return EmptyMemoryOwner.Instance; + using var arrayBuilder = ToArrayBuilderAt(source, pool, clearOnDispose, predicate); return arrayBuilder.ToArray(pool, clearOnDispose); } @@ -82,64 +80,58 @@ static ValueMemoryOwner ToArrayAt(this ReadOnlySpa [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] static TResult[] ToArray(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, selector) - }; - - static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) - { - var result = Utils.AllocateUninitializedArray(source.Length); - Copy(source, result.AsSpan(), selector); - return result; - } + if (source.Length is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(source.Length); + Copy(source, result.AsSpan(), selector); + return result; } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] static TResult[] ToArrayVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct where TResult : struct { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, vectorSelector, selector) - }; - - static TResult[] BuildArray(ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) - { - var result = Utils.AllocateUninitializedArray(source.Length); - CopyVector(source, result.AsSpan(), vectorSelector, selector); - return result; - } + if (source.Length is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(source.Length); + CopyVector(source, result.AsSpan(), vectorSelector, selector); + return result; } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArrayVector(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TVectorSelector vectorSelector, TSelector selector) + [SkipLocalsInit] + static IMemoryOwner ToArrayVector(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct where TResult : struct { + if (source.Length is 0) + return EmptyMemoryOwner.Instance; + var result = pool.RentDisposable(source.Length, clearOnDispose); CopyVector(source, result.Memory.Span, vectorSelector, selector); return result; } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) + [SkipLocalsInit] + static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { + if (source.Length is 0) + return EmptyMemoryOwner.Instance; + var result = pool.RentDisposable(source.Length, clearOnDispose); Copy(source, result.Memory.Span, selector); return result; @@ -148,29 +140,26 @@ static ValueMemoryOwner ToArray(this ReadO ////////////////////////////////////////////////////////////////////////////////////////////////// [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] static TResult[] ToArrayAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, selector) - }; - - static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) - { - var result = Utils.AllocateUninitializedArray(source.Length); - CopyAt(source, result.AsSpan(), selector); - return result; - } + if (source.Length is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(source.Length); + CopyAt(source, result.AsSpan(), selector); + return result; } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) + [SkipLocalsInit] + static IMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { + if (source.Length is 0) + return EmptyMemoryOwner.Instance; + var result = pool.RentDisposable(source.Length, clearOnDispose); CopyAt(source, result.Memory.Span, selector); return result; @@ -180,30 +169,27 @@ static ValueMemoryOwner ToArrayAt(this Rea [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] static TResult[] ToArray(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction { - return source switch - { - { Length: 0 } => Array.Empty(), - _ => BuildArray(source, predicate, selector) - }; - - static TResult[] BuildArray(ReadOnlySpan source, TPredicate predicate, TSelector selector) - { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate, selector); - return arrayBuilder.ToArray(); - } + if (source.Length is 0) + return Array.Empty(); + + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false, predicate, selector); + return arrayBuilder.ToArray(); } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) + [SkipLocalsInit] + static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction { + if (source.Length is 0) + return EmptyMemoryOwner.Instance; + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate, selector); return arrayBuilder.ToArray(pool, clearOnDispose); } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs index f1445f007..ba6f4bd92 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs @@ -8,7 +8,8 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueMemoryOwner ToArray(this Span source, ArrayPool pool, bool clearOnDispose = default) + [SkipLocalsInit] + public static IMemoryOwner ToArray(this Span source, ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source).ToArray(pool, clearOnDispose); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index 1bda4082c..3daa011b2 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -1,5 +1,5 @@ -using System.Buffers; -using System.Collections; +using System; +using System.Buffers; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -8,66 +8,51 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { + [SkipLocalsInit] public static TSource[] ToArray(this TEnumerable source) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { - return source switch + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) { - // ReSharper disable once HeapView.PossibleBoxingAllocation - // ReSharper disable once SuspiciousTypeConversion.Global - ICollection collection => BuildArrayFromCollection(collection), + if (collection.Count is 0) + return Array.Empty(); - _ => BuildArray(source) - }; - - static TSource[] BuildArrayFromCollection(ICollection collection) - { var result = Utils.AllocateUninitializedArray(collection.Count); collection.CopyTo(result, 0); - return result; - } - - static TSource[] BuildArray(TEnumerable source) - { - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false); - return arrayBuilder.ToArray(); + return result; } + + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false); + return arrayBuilder.ToArray(); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) + [SkipLocalsInit] + public static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { - return source switch + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) { - // ReSharper disable once HeapView.PossibleBoxingAllocation - // ReSharper disable once SuspiciousTypeConversion.Global - ICollection collection => BuildArrayFromCollection(collection, pool, clearOnDispose), + if (collection.Count is 0) + return EmptyMemoryOwner.Instance; - _ => BuildArray(source, pool, clearOnDispose) - }; - - static ValueMemoryOwner BuildArrayFromCollection(ICollection collection, ArrayPool pool, bool clearOnDispose) - { var result = pool.RentDisposable(collection.Count, clearOnDispose); collection.CopyTo(result.Rented, 0); - return result; + return result; } - static ValueMemoryOwner BuildArray(TEnumerable source, ArrayPool pool, bool clearOnDispose) - { - using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose); - return arrayBuilder.ToArray(pool, clearOnDispose); - } + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose); + return arrayBuilder.ToArray(pool, clearOnDispose); } ////////////////////////////////////////////////////////////////////////////////////////////////// [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] internal static TSource[] ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -78,8 +63,8 @@ internal static TSource[] ToArray } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + [SkipLocalsInit] + internal static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction @@ -92,7 +77,7 @@ internal static ValueMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -103,8 +88,8 @@ internal static TSource[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + [SkipLocalsInit] + internal static IMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction @@ -117,7 +102,7 @@ internal static ValueMemoryOwner ToArrayAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -128,8 +113,8 @@ static TResult[] ToArray( } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + [SkipLocalsInit] + static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -141,7 +126,7 @@ static ValueMemoryOwner ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -152,8 +137,8 @@ static TResult[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + [SkipLocalsInit] + static IMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -166,7 +151,7 @@ static ValueMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -178,8 +163,8 @@ internal static TResult[] ToArray ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) + [SkipLocalsInit] + internal static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index 28dd4f414..20f06db2d 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -1,6 +1,5 @@ using System; using System.Buffers; -using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -9,141 +8,113 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public static TSource[] ToArray(this TEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator { - return source switch - { - { Count: 0 } => Array.Empty(), - - // ReSharper disable once HeapView.PossibleBoxingAllocation - // ReSharper disable once SuspiciousTypeConversion.Global - ICollection collection => BuildArrayFromCollection(collection), - - _ => BuildArray(source) - }; - - static TSource[] BuildArrayFromCollection(ICollection collection) - { - var result = Utils.AllocateUninitializedArray(collection.Count); - collection.CopyTo(result, 0); - return result; - } + if (source.Count is 0) + return Array.Empty(); - static TSource[] BuildArray(TEnumerable source) - { - var result = Utils.AllocateUninitializedArray(source.Count); + var result = Utils.AllocateUninitializedArray(source.Count); + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + collection.CopyTo(result, 0); + else Copy(source, result); - return result; - } + return result; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) + [SkipLocalsInit] + public static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator { - return source switch - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - // ReSharper disable once SuspiciousTypeConversion.Global - ICollection collection => BuildArrayFromCollection(collection, pool, clearOnDispose), - - _ => BuildArray(source, pool, clearOnDispose) - }; - - static ValueMemoryOwner BuildArrayFromCollection(ICollection collection, ArrayPool pool, bool clearOnDispose) - { - var result = pool.RentDisposable(collection.Count, clearOnDispose); + if (source.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(source.Count, clearOnDispose); + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) collection.CopyTo(result.Rented, 0); - return result; - } - - static ValueMemoryOwner BuildArray(TEnumerable source, ArrayPool pool, bool clearOnDispose) - { - var result = pool.RentDisposable(source.Count, clearOnDispose); - Copy(source, result.Memory.Span); - return result; - } + else + Copy(source, result.Rented); + return result; } ////////////////////////////////////////////////////////////////////////////////////////////////// [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static TSource[] ToArray(this TEnumerable source, TPredicate predicate) + [SkipLocalsInit] + static TSource[] ToArray(this TEnumerable source, + TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source switch - { - { Count: 0 } => Array.Empty(), - _ => ValueEnumerableExtensions.ToArray(source, predicate) - }; + where TPredicate : struct, IFunction + => source.Count is 0 + ? Array.Empty() + : ValueEnumerableExtensions.ToArray(source, predicate); [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + [SkipLocalsInit] + static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction - => ValueEnumerableExtensions.ToArray(source, pool, clearOnDispose, predicate); + => source.Count is 0 + ? EmptyMemoryOwner.Instance + : ValueEnumerableExtensions.ToArray(source, pool, clearOnDispose, predicate); ////////////////////////////////////////////////////////////////////////////////////////////////// [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] static TSource[] ToArrayAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction - => source switch - { - { Count: 0 } => Array.Empty(), - _ => ValueEnumerableExtensions.ToArrayAt(source, predicate) - }; + => source.Count is 0 + ? Array.Empty() + : ValueEnumerableExtensions.ToArrayAt(source, predicate); [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + [SkipLocalsInit] + static IMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction - => ValueEnumerableExtensions.ToArrayAt(source, pool, clearOnDispose, predicate); + => source.Count is 0 + ? EmptyMemoryOwner.Instance + : ValueEnumerableExtensions.ToArrayAt(source, pool, clearOnDispose, predicate); ////////////////////////////////////////////////////////////////////////////////////////////////// [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] internal static TResult[] ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - return source switch - { - { Count: 0 } => Array.Empty(), - _ => BuildArray(source, selector) - }; - - static TResult[] BuildArray(TEnumerable source, TSelector selector) - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var array = new TResult[source.Count]; - Copy(source, array, selector); - return array; - } + if (source.Count is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(source.Count); + Copy(source, result, selector); + return result; } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + [SkipLocalsInit] + internal static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { + if (source.Count is 0) + return EmptyMemoryOwner.Instance; + var result = pool.RentDisposable(source.Count, clearOnDispose); Copy(source, result.Rented, selector); return result; @@ -153,34 +124,30 @@ internal static ValueMemoryOwner ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { - return source switch - { - { Count: 0 } => Array.Empty(), - _ => BuildArray(source, selector) - }; - - static TResult[] BuildArray(TEnumerable source, TSelector selector) - { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var array = new TResult[source.Count]; - CopyAt(source, array, selector); - return array; - } + if (source.Count is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(source.Count); + CopyAt(source, result, selector); + return result; } [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + [SkipLocalsInit] + internal static IMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { + if (source.Count is 0) + return EmptyMemoryOwner.Instance; + var result = pool.RentDisposable(source.Count, clearOnDispose); CopyAt(source, result.Rented, selector); return result; @@ -189,25 +156,25 @@ internal static ValueMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction where TSelector : struct, IFunction - => source switch - { - { Count: 0 } => Array.Empty(), - _ => ValueEnumerableExtensions.ToArray(source, predicate, selector) - }; + => source.Count is 0 + ? Array.Empty() + : ValueEnumerableExtensions.ToArray(source, predicate, selector); [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) + [SkipLocalsInit] + static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ValueEnumerableExtensions.ToArray(source, pool, clearOnDispose, predicate, selector); + => source.Count is 0 + ? EmptyMemoryOwner.Instance + : ValueEnumerableExtensions.ToArray(source, pool, clearOnDispose, predicate, selector); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs index d4e826a31..80a755b37 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs @@ -10,13 +10,15 @@ public static partial class AsyncValueEnumerableExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public static async ValueTask ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + [SkipLocalsInit] + public static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator => (await source.ToArrayBuilderAsync(pool, clearOnDispose, cancellationToken).ConfigureAwait(false)).ToArray(pool, clearOnDispose); @@ -25,6 +27,7 @@ public static async ValueTask> ToArrayAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -33,7 +36,8 @@ static async ValueTask ToArrayAsync> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) + [SkipLocalsInit] + static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -43,6 +47,7 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -51,7 +56,8 @@ static async ValueTask ToArrayAtAsync> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) + [SkipLocalsInit] + static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -61,6 +67,7 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -69,7 +76,8 @@ static async ValueTask ToArrayAsync> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) + [SkipLocalsInit] + static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -79,6 +87,7 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -87,7 +96,8 @@ static async ValueTask ToArrayAtAsync> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) + [SkipLocalsInit] + static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -97,6 +107,7 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -106,7 +117,8 @@ static async ValueTask ToArrayAsync> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) + [SkipLocalsInit] + static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index 0af210f36..885346363 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -222,7 +222,7 @@ public TSource[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index 2b945a112..09cae35df 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -329,7 +329,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAsync(pool, clearOnDispose, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index 15018ad65..2fc450e35 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -216,7 +216,7 @@ public Option Single() public TSource[] ToArray() => source.Span.ToArray(predicate); - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArray(pool, clearOnDispose, predicate); public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index 83259a241..2b19d8283 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -157,7 +157,7 @@ public Option Single() public TSource[] ToArray() => source.ToArray(predicate); - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, predicate); public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index 04aa70044..f9ad5835b 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -135,7 +135,7 @@ public TSource[] ToArray() => source.ToArray(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index ee6250540..e647281d6 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -225,7 +225,7 @@ public TSource[] ToArray() => ValueReadOnlyCollectionExtensions.ToArray(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index 6e6093428..c7aa1cc5d 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -220,7 +220,7 @@ public TSource[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index 3100a92c5..6e2dd58ed 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -322,7 +322,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAtAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAtAsync(pool, clearOnDispose, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index c33057a85..95ce60b76 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -204,7 +204,7 @@ public Option Single() public TSource[] ToArray() => source.Span.ToArrayAt(predicate); - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArrayAt(pool, clearOnDispose, predicate); public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index a61545c68..acc79b256 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -147,7 +147,7 @@ public Option Single() public TSource[] ToArray() => source.ToArrayAt(predicate); - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayAt(pool, clearOnDispose, predicate); public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index 81667a8bb..72f079f87 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -222,7 +222,7 @@ public TSource[] ToArray() => source.ToArrayAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayAt(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index 4df20a09f..7338684f4 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -221,7 +221,7 @@ public TSource[] ToArray() => ToArrayAt(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ToArrayAt(source, pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index 2d9c935a6..b79d4bfc1 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -238,7 +238,7 @@ public TResult[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index b8b6863a1..2e9445f69 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -357,7 +357,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAsync(cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAsync(pool, clearOnDispose, cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index 683c97e93..d451ea01a 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -239,7 +239,7 @@ public TResult[] ToArray() => source.Span.ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index 133accd8c..484eb1093 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -112,7 +112,7 @@ public TResult[] ToArray() => source.ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index abeda7695..5853663e9 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -242,7 +242,7 @@ public TResult[] ToArray() => source.ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index 3a9ee6f62..753e32603 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -242,7 +242,7 @@ public TResult[] ToArray() => ValueReadOnlyCollectionExtensions.ToArray(source, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs index 112ddbee9..8f0219275 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs @@ -180,7 +180,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d return new ValueTask(result: array); } - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) { var result = pool.RentDisposable(count, clearOnDispose); var array = result.Memory.Span; @@ -190,7 +190,7 @@ public ValueTask> ToArrayAsync(ArrayPool pool cancellationToken.ThrowIfCancellationRequested(); array[index] = value; } - return new ValueTask>(result: result); + return new ValueTask>(result: result); } public async ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs index e1c1a6521..d8c935d85 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs @@ -45,11 +45,6 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - public void CopyTo(Span span) - { - // nothing to do - } - public void CopyTo(TSource[] array, int arrayIndex) { // nothing to do diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs index 8b1b6cebb..1965d75a9 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs @@ -209,7 +209,7 @@ public bool Contains(int value, IEqualityComparer? comparer) var end = start + Count; - if (Utils.UseDefault(comparer)) + if (comparer.UseDefaultComparer()) return value >= start && value < end; for (var item = start; item < end; item++) @@ -258,7 +258,7 @@ public int[] ToArray() return array; } - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { var result = pool.RentDisposable(Count, clearOnDispose); ArrayExtensions.CopyRange(start, Count, result.Memory.Span); diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs index f848c6b0a..ef600c73e 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs @@ -183,7 +183,7 @@ public TSource[] ToArray() return array; } - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { var result = pool.RentDisposable(Count, clearOnDispose); CopyTo(result.Memory.Span); @@ -236,7 +236,7 @@ public static TSource[] ToArrayVector(this RepeatEnumerable so return array; } - public static ValueMemoryOwner ToArrayVector(this RepeatEnumerable source, ArrayPool pool, bool clearOnDispose = default) + public static IMemoryOwner ToArrayVector(this RepeatEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TSource : struct { var result = pool.RentDisposable(source.count, clearOnDispose); diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs index d553707ea..d98d9f8f1 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs @@ -242,9 +242,10 @@ public bool Contains(TSource value, IEqualityComparer? comparer) if (source.Count is 0) return false; - if (Utils.UseDefault(comparer)) + if (comparer.UseDefaultComparer()) { // ReSharper disable once HeapView.PossibleBoxingAllocation + // ReSharper disable once HeapView.BoxingAllocation if (offset is 0 && Count == source.Count && source is ICollection collection) return collection.Contains(value); diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs index 24ab0a7b0..ab93810ac 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs @@ -176,7 +176,7 @@ public bool Contains(TSource value, IEqualityComparer? comparer) if (source.Count is 0) return false; - if (Utils.UseDefault(comparer)) + if (comparer.UseDefaultComparer()) { // ReSharper disable once HeapView.PossibleBoxingAllocation if (offset is 0 && Count == source.Count && source is ICollection collection) diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 9c4001f46..d48e1ce3e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -213,7 +213,7 @@ public TResult[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs index e1c26f312..ff31c1eeb 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -258,7 +258,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAsync(pool, cancellationToken, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index fc86272de..a06ab0715 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -206,7 +206,7 @@ public TResult[] ToArray() => source.Span.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArray(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index 210e5ed69..09432715e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -101,7 +101,7 @@ public TResult[] ToArray() => source.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index 3043a11c3..62c3351d9 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -160,7 +160,7 @@ public TResult[] ToArray() => source.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index c223d31fe..cd9459c52 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -195,7 +195,7 @@ public TResult[] ToArray() => ValueReadOnlyCollectionExtensions.ToArray(source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs index 5300c6878..8fe332388 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -221,7 +221,7 @@ public readonly TResult[] ToArray() => source.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index a15e1c6d8..5ae7e692d 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -204,7 +204,7 @@ public TResult[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index 658feaa60..67f51cc94 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -260,7 +260,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAtAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAtAsync(pool, cancellationToken, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 64f5d1c20..42867bc67 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -198,7 +198,7 @@ public TResult[] ToArray() => source.Span.ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArrayAt(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index df4ae147e..c075f7256 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -101,7 +101,7 @@ public TResult[] ToArray() => source.ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayAt(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index 7801ac752..b26243b60 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -170,7 +170,7 @@ public TResult[] ToArray() => source.ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayAt(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index fe2d27d49..04ba9313e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -204,7 +204,7 @@ public TResult[] ToArray() => ToArrayAt(source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ToArrayAt(source, pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs index 5e7ac4098..c610c62cf 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -237,7 +237,7 @@ public readonly TResult[] ToArray() => ValueReadOnlyCollectionExtensions.ToArrayAt(source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => ValueReadOnlyCollectionExtensions.ToArrayAt(source, pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs index 2df86b67e..c14c0b4e6 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs @@ -86,7 +86,7 @@ public TResult[] ToArray() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { var result = pool.RentDisposable(count, clearOnDispose); ArrayExtensions.CopyRange(start, count, result.Memory.Span, vectorSelector, selector); diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs index b91d2354f..9fb0254ef 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs @@ -88,7 +88,7 @@ public TResult[] ToArray() => source.ToArrayVector(vectorSelector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayVector(pool, clearOnDispose, vectorSelector, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs index a843d834e..0d061f9d6 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs @@ -8,7 +8,7 @@ public static partial class EnumerableExtensions internal static bool Contains(this TEnumerable source, TSource value, IEqualityComparer? comparer = default) where TEnumerable : IEnumerable { - if (Utils.UseDefault(comparer)) + if (comparer.UseDefaultComparer()) { // ReSharper disable once HeapView.PossibleBoxingAllocation if (source is ICollection collection) @@ -50,7 +50,7 @@ internal static bool Contains where TEnumeratorGenerator : struct, IFunction { - if (Utils.UseDefault(comparer)) + if (comparer.UseDefaultComparer()) { return source switch { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs index 078f638c1..767f1619b 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs @@ -10,7 +10,7 @@ static bool Contains(this ReadOnlySpan source, TSource value, return source switch { { Length: 0 } => false, - _ => Utils.UseDefault(comparer) + _ => comparer.UseDefaultComparer() ? ValueContains(source, value) : ReferenceContains(source, value, comparer) }; @@ -44,7 +44,7 @@ static bool Contains(this ReadOnlySpan sou return source switch { { Length: 0 } => false, - _ => Utils.UseDefault(comparer) + _ => comparer.UseDefaultComparer() ? ValueContains(source, value, selector) : ReferenceContains(source, value, comparer, selector) }; diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs index 7c7a83b00..6f5605ad9 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -8,7 +8,7 @@ public static bool Contains(this TEnumerable where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { - if (Utils.UseDefault(comparer)) + if (comparer.UseDefaultComparer()) { // ReSharper disable once HeapView.PossibleBoxingAllocation if (source is ICollection collection) @@ -51,7 +51,7 @@ internal static bool Contains where TSelector : struct, IFunction { - return Utils.UseDefault(comparer) + return comparer.UseDefaultComparer() ? ValueContains(source, value, selector) : ReferenceContains(source, value, comparer, selector); diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs index acb2cd2bb..be0b66670 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs @@ -30,7 +30,7 @@ public static ValueTask ContainsAsync(t where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator { - return Utils.UseDefault(comparer) + return comparer.UseDefaultComparer() ? DefaultContainsAsync(source, value, cancellationToken) : ComparerContainsAsync(source, value, comparer, cancellationToken); diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs index 2c963c386..60756419b 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs @@ -130,7 +130,7 @@ public TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs index 95fee3686..1aa0ab518 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs @@ -222,7 +222,7 @@ public async ValueTask ToArrayAsync(CancellationToken cancellationTok => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public async ValueTask> ToArrayAsync(ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken = default) + public async ValueTask> ToArrayAsync(ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken = default) => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs index bd737e17b..752b15a79 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -132,7 +132,7 @@ public TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs index b422ba564..8f376df77 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs @@ -96,7 +96,7 @@ public TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs index bd7f01411..269e97125 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs @@ -116,7 +116,7 @@ public TSource[] ToArray() => GetSet().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index cec24d32f..df69e9e1a 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -51,7 +51,7 @@ public Set(IEqualityComparer? comparer = default) { bucketsPool = ArrayPool.Shared; slotsPool = ArrayPool.Shared; - useDefaultComparer = Utils.UseDefault(comparer); + useDefaultComparer = comparer.UseDefaultComparer(); this.comparer = comparer ?? EqualityComparer.Default; buckets = default; slots = default; @@ -170,7 +170,7 @@ public readonly TElement[] ToArray() return array; } - public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) + public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) { var result = pool.RentDisposable(Count, clearOnDispose); CopyTo(result.Memory.Span); diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs index 58ae177ef..3af33d334 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs @@ -7,6 +7,8 @@ using System; using System.Buffers; using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace NetFabric.Hyperlinq { @@ -14,6 +16,7 @@ namespace NetFabric.Hyperlinq /// Helper type for avoiding allocations while building arrays. /// /// The element type. + [StructLayout(LayoutKind.Auto)] struct ArrayBuilder : IDisposable { @@ -21,7 +24,8 @@ struct ArrayBuilder const int maxCoreClrArrayLength = 0x7fefffff; // For byte arrays the limit is slightly larger readonly ArrayPool pool; - T[]? buffer; // Starts out null, initialized on first Add. + T[] buffer; + int index; /// /// Initializes the with a specified capacity. @@ -32,113 +36,88 @@ public ArrayBuilder(int capacity, ArrayPool pool) { Debug.Assert(capacity >= 0); if (capacity > 0) - { buffer = this.pool.Rent(capacity); - } } public ArrayBuilder(ArrayPool pool) { this.pool = pool; - buffer = default; - Count = 0; + buffer = Array.Empty(); + index = 0; } - /// - /// Gets the number of items this instance can store without re-allocating, - /// or 0 if the backing array is null. - /// - public int Capacity - => buffer?.Length ?? 0; - /// /// Gets the number of items in the array currently in use. /// - public int Count { get; private set; } - - // /// - // /// Gets or sets the item at a certain index in the array. - // /// - // /// The index into the array. - // public T this[int index] - // { - // get - // { - // Debug.Assert(index >= 0 && index < Count); - // return buffer![index]; - // } - // } - - public readonly Span AsSpan() - => buffer!.AsSpan(0, Count); + // ReSharper disable once ConvertToAutoPropertyWithPrivateSetter + public int Count => index; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] + public readonly ReadOnlySpan AsSpan() + => buffer.AsSpan(0, index); /// /// Adds an item to the backing array, resizing it if necessary. /// /// The item to add. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public void Add(T item) { - if (Count == Capacity) + var buffer = this.buffer; + var index = this.index; + + // Must be >= and not == to enable range check elimination + if ((uint)index >= (uint)buffer.Length) { - EnsureCapacity(Count + 1); + AddWithBufferAllocation(item); + } + else + { + buffer[index] = item; + this.index = index + 1; } - - UncheckedAdd(item); } - - /// - /// Adds an item to the backing array, without checking if there is room. - /// - /// The item to add. - /// - /// Use this method if you know there is enough space in the - /// for another item, and you are writing performance-sensitive code. - /// - public void UncheckedAdd(T item) + + // Non-inline to improve code quality as uncommon path + [MethodImpl(MethodImplOptions.NoInlining)] + [SkipLocalsInit] + void AddWithBufferAllocation(T item) { - Debug.Assert(buffer is not null); - Debug.Assert(Count < Capacity); - - buffer[Count++] = item; + EnsureCapacity(index + 1); + buffer[index++] = item; } + [SkipLocalsInit] void EnsureCapacity(int minimum) { - Debug.Assert(minimum > Capacity); + Debug.Assert(minimum > index); - var capacity = Capacity; - var nextCapacity = capacity switch - { - 0 => defaultMinCapacity, - _ => 2 * capacity, - }; + var capacity = index; + var nextCapacity = capacity is 0 + ? defaultMinCapacity + : 2 * capacity; if ((uint)nextCapacity > (uint)maxCoreClrArrayLength) - { nextCapacity = Math.Max(capacity + 1, maxCoreClrArrayLength); - } nextCapacity = Math.Max(nextCapacity, minimum); var next = pool.Rent(nextCapacity); - try - { - if (buffer is not null) - { - Array.Copy(buffer, next, Count); - } - } - finally + if (index is not 0) { - if (buffer is not null) - pool.Return(buffer); - buffer = next; + Array.Copy(buffer, next, index); + pool.Return(buffer); } + + buffer = next; } + [SkipLocalsInit] public readonly void Dispose() { - if (buffer is not null) + if (index is not 0) pool.Return(buffer); } } diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs index 3c9a81977..0d009e050 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs @@ -11,6 +11,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace NetFabric.Hyperlinq { @@ -18,6 +19,7 @@ namespace NetFabric.Hyperlinq /// Helper type for building dynamically-sized arrays while minimizing allocations and copying. /// /// The element type. + [StructLayout(LayoutKind.Auto)] struct LargeArrayBuilder : ICollection , IDisposable @@ -25,12 +27,12 @@ struct LargeArrayBuilder const int defaultMinCapacity = 4; readonly ArrayPool pool; + readonly bool clearOnDispose; readonly int maxCapacity; // The maximum capacity this builder can have. ArrayBuilder buffers; // After ResizeLimit * 2, we store previous buffers we've filled out here. T[] current; // Current buffer we're reading into. If _count <= ResizeLimit, this is _first. int index; // Index into the current buffer. - int storedCount; // Number of items stored in buffers. - readonly bool clearOnDispose; + int count; // Total number of items stored /// /// Constructs a new builder. @@ -52,52 +54,54 @@ public LargeArrayBuilder(int maxCapacity, ArrayPool pool, ArrayPool arra Debug.Assert(maxCapacity >= 0); this.pool = pool; + this.clearOnDispose = clearOnDispose; this.maxCapacity = maxCapacity; buffers = new ArrayBuilder(arrayBuilderPool); current = Array.Empty(); index = 0; - storedCount = 0; - this.clearOnDispose = clearOnDispose; + count = 0; } /// /// Gets the number of items added to the builder. /// - public readonly int Count - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => storedCount + index; - } + // ReSharper disable once ConvertToAutoPropertyWhenPossible + public int Count => count; /// /// Adds an item to this builder. /// /// The item to add. /// - /// Use if adding to the builder is a bottleneck for your use case. - /// Otherwise, use . - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public void Add(T item) { - Debug.Assert(maxCapacity > Count); + Debug.Assert(maxCapacity > count); + + var index = this.index; + var current = this.current; // Must be >= and not == to enable range check elimination if ((uint)index >= (uint)current.Length) - AllocateBuffer(); + { + AddWithBufferAllocation(item); + } + else + { + current[index] = item; + this.index = index + 1; + } - current[index++] = item; + count++; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddRef(in T item) + + // Non-inline to improve code quality as uncommon path + [MethodImpl(MethodImplOptions.NoInlining)] + [SkipLocalsInit] + void AddWithBufferAllocation(T item) { - Debug.Assert(maxCapacity > Count); - - // Must be >= and not == to enable range check elimination - if ((uint)index >= (uint)current.Length) - AllocateBuffer(); - + AllocateBuffer(); current[index++] = item; } @@ -106,69 +110,52 @@ public void AddRef(in T item) /// /// The destination array. /// The index in to start copying to. + [SkipLocalsInit] public readonly void CopyTo(T[] array, int arrayIndex) - => CopyTo(array.AsSpan(arrayIndex)); - - public readonly void CopyTo(Span span) { - var arrayIndex = 0; foreach (var buffer in buffers.AsSpan()) { var length = buffer.Length; - buffer.AsSpan().CopyTo(span.Slice(arrayIndex, length)); - + Array.Copy(buffer, 0, array, arrayIndex, length); arrayIndex += length; } - if (arrayIndex < Count) - { - var length = Count - arrayIndex; - current.AsSpan(0, length).CopyTo(span.Slice(arrayIndex, length)); - } + if (arrayIndex < count) + Array.Copy(current, 0, array, arrayIndex, count - arrayIndex); } - /// - /// Adds an item to this builder. - /// - /// The item to add. - /// - /// Use if adding to the builder is a bottleneck for your use case. - /// Otherwise, use . - /// - [MethodImpl(MethodImplOptions.NoInlining)] - public void SlowAdd(T item) - => Add(item); - /// /// Creates an array from the contents of this builder. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public readonly T[] ToArray() { + if (count is 0) + return Array.Empty(); + // ReSharper disable once HeapView.ObjectAllocation.Evident - var array = new T[Count]; - if (Count is not 0) - CopyTo(array); + var array = Utils.AllocateUninitializedArray(count); + CopyTo(array, 0); return array; } - public readonly ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] + public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) { - var result = pool.RentDisposable(Count, clearOnDispose); - if (Count is not 0) - CopyTo(result.Memory.Span); + if (count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(count, clearOnDispose); + CopyTo(result.Rented, 0); return result; } [MethodImpl(MethodImplOptions.NoInlining)] + [SkipLocalsInit] void AllocateBuffer() { - // - On the first few adds, simply resize _first. - // - When we pass ResizeLimit, allocate ResizeLimit elements for _current - // and start reading into _current. Set _index to 0. - // - When _current runs out of space, add it to _buffers and repeat the - // above step, except with _current.Length * 2. - // - Make sure we never pass _maxCapacity in all of the above steps. - - Debug.Assert((uint)maxCapacity > (uint)Count); + Debug.Assert((uint)maxCapacity > (uint)count); Debug.Assert(index == current.Length, $"{nameof(AllocateBuffer)} was called, but there's more space."); // Example scenario: Let's say _count == 64. @@ -179,17 +166,17 @@ void AllocateBuffer() // the rhs the limit minus the amount we've already allocated. var nextCapacity = defaultMinCapacity; - if (Count is not 0) + if (count is not 0) { buffers.Add(current); - nextCapacity = Math.Min(Count, maxCapacity - Count); - storedCount += index; + nextCapacity = Math.Min(count, maxCapacity - count); } current = pool.Rent(nextCapacity); index = 0; } + [SkipLocalsInit] public readonly void Dispose() { pool.Return(current, clearOnDispose); @@ -202,16 +189,27 @@ bool ICollection.IsReadOnly => true; [ExcludeFromCodeCoverage] - IEnumerator IEnumerable.GetEnumerator() => throw new NotSupportedException(); + readonly IEnumerator IEnumerable.GetEnumerator() + => throw new NotSupportedException(); + [ExcludeFromCodeCoverage] - IEnumerator IEnumerable.GetEnumerator() => throw new NotSupportedException(); + readonly IEnumerator IEnumerable.GetEnumerator() + => throw new NotSupportedException(); + [ExcludeFromCodeCoverage] - void ICollection.Add(T item) => throw new NotSupportedException(); + readonly void ICollection.Add(T item) + => throw new NotSupportedException(); + [ExcludeFromCodeCoverage] - void ICollection.Clear() => throw new NotSupportedException(); + readonly void ICollection.Clear() + => throw new NotSupportedException(); + [ExcludeFromCodeCoverage] - bool ICollection.Contains(T item) => throw new NotSupportedException(); + readonly bool ICollection.Contains(T item) + => throw new NotSupportedException(); + [ExcludeFromCodeCoverage] - bool ICollection.Remove(T item) => throw new NotSupportedException(); + readonly bool ICollection.Remove(T item) + => throw new NotSupportedException(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs deleted file mode 100644 index 9688f9b18..000000000 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.Buffers; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ReadOnlyListExtensions - { - - [GeneratorIgnore] - static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate: struct, IFunction - { - var builder = new LargeArrayBuilder(pool, clearOnDispose); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - builder.Add(item); - } - return builder; - } - - [GeneratorIgnore] - static LargeArrayBuilder ToArrayBuilderAt(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) - where TList : struct, IReadOnlyList - where TPredicate: struct, IFunction - { - var builder = new LargeArrayBuilder(pool, clearOnDispose); - var end = count; - if (offset is 0) - { - for (var index = 0; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item, index)) - builder.Add(item); - } - } - else - { - for (var index = 0; index < end; index++) - { - var item = source[index + offset]; - if (predicate.Invoke(item, index)) - builder.Add(item); - } - } - return builder; - } - - [GeneratorIgnore] - static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector, int offset, int count) - where TList : struct, IReadOnlyList - where TSelector: struct, IFunction - where TPredicate: struct, IFunction - { - var builder = new LargeArrayBuilder(pool, clearOnDispose); - var end = offset + count; - for (var index = offset; index < end; index++) - { - var item = source[index]; - if (predicate.Invoke(item)) - builder.Add(selector.Invoke(item)); - } - return builder; - } - } -} diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs index fc060df38..4cc32ece3 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs @@ -14,7 +14,10 @@ static LargeArrayBuilder ToArrayBuilder(arrayPool, clearOnDispose); using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) - builder.Add(enumerator.Current); + { + var item = enumerator.Current; + builder.Add(item); + } return builder; } @@ -61,7 +64,10 @@ static LargeArrayBuilder ToArrayBuilder(arrayPool, clearOnDispose); using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) - builder.Add(selector.Invoke(enumerator.Current)); + { + var item = enumerator.Current; + builder.Add(selector.Invoke(item)); + } return builder; } @@ -76,7 +82,10 @@ static LargeArrayBuilder ToArrayBuilderAt RentDisposable(this ArrayPool pool, int length, bool clearOnDispose) + [SkipLocalsInit] + public static MemoryOwner RentDisposable(this ArrayPool pool, int length, bool clearOnDispose) => new(pool, length, clearOnDispose); } - public struct ValueMemoryOwner + [SkipLocalsInit] + class MemoryOwner : IMemoryOwner { readonly ArrayPool pool; @@ -19,7 +21,7 @@ public struct ValueMemoryOwner readonly bool clearOnDispose; T[]? rented; - internal ValueMemoryOwner(ArrayPool pool, int length, bool clearOnDispose) + internal MemoryOwner(ArrayPool pool, int length, bool clearOnDispose) { this.pool = pool; this.length = length; @@ -27,23 +29,24 @@ internal ValueMemoryOwner(ArrayPool pool, int length, bool clearOnDispose) rented = this.pool.Rent(length); } - public readonly T[] Rented + public T[] Rented { get { var array = rented; if (array is null) - Throw.ObjectDisposedException(nameof(ValueMemoryOwner)); + Throw.ObjectDisposedException(nameof(MemoryOwner)); return array; } } - public readonly Memory Memory + + public Memory Memory { get { var array = rented; if (array is null) - Throw.ObjectDisposedException(nameof(ValueMemoryOwner)); + Throw.ObjectDisposedException(nameof(MemoryOwner)); return new Memory(array, 0, length); } } @@ -58,5 +61,17 @@ public void Dispose() } } } - + + [SkipLocalsInit] + class EmptyMemoryOwner + : IMemoryOwner + { + public static EmptyMemoryOwner Instance => new(); + + private EmptyMemoryOwner() { } + + public Memory Memory => Memory.Empty; + + public void Dispose() { } + } } diff --git a/NetFabric.Hyperlinq/Utils/SkipLocalsInitAttribute.cs b/NetFabric.Hyperlinq/Utils/SkipLocalsInitAttribute.cs new file mode 100644 index 000000000..8c193e3ce --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/SkipLocalsInitAttribute.cs @@ -0,0 +1,21 @@ +#if !NET5_0_OR_GREATER + +namespace System.Runtime.CompilerServices +{ + [AttributeUsage(AttributeTargets.Module + | AttributeTargets.Class + | AttributeTargets.Struct + | AttributeTargets.Interface + | AttributeTargets.Constructor + | AttributeTargets.Method + | AttributeTargets.Property + | AttributeTargets.Event, Inherited = false)] + public sealed class SkipLocalsInitAttribute : Attribute + { + public SkipLocalsInitAttribute() + { + } + } +} + +#endif \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Utils/Throw.cs b/NetFabric.Hyperlinq/Utils/Throw.cs index 26e021d5a..7fda0a647 100644 --- a/NetFabric.Hyperlinq/Utils/Throw.cs +++ b/NetFabric.Hyperlinq/Utils/Throw.cs @@ -101,5 +101,10 @@ public static T NotSupportedException() [MethodImpl(MethodImplOptions.NoInlining)] public static void ObjectDisposedException(string objectName) => throw new ObjectDisposedException(objectName); + + [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] + public static T ObjectDisposedException(string objectName) + => throw new ObjectDisposedException(objectName); } } diff --git a/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs b/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs index 4eeb6f538..3c81508c6 100644 --- a/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs +++ b/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs @@ -5,9 +5,11 @@ namespace NetFabric.Hyperlinq { static partial class Utils { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] public static T[] AllocateUninitializedArray(int count) -#if NET5_0_OR_GREATER +#if NET5_0_OR_GREATER => GC.AllocateUninitializedArray(count, pinned: false); #else // ReSharper disable once HeapView.ObjectAllocation.Evident diff --git a/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs b/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs index b2f8ac98e..8236f5895 100644 --- a/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs +++ b/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs @@ -7,10 +7,10 @@ static partial class Utils { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsValueType() - => default(T) is {}; + => default(T) is not null; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool UseDefault(IEqualityComparer? comparer) + public static bool UseDefaultComparer(this IEqualityComparer? comparer) => comparer is null || ReferenceEquals(comparer, EqualityComparer.Default); } } From c3fa93a27ac1f1de4a3788a5c964a71902eb89e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Mon, 6 Sep 2021 21:30:03 +0100 Subject: [PATCH 47/61] Review ToArray on enumerables (#379) --- Benchmarks/ToArrayBenchmarks.md | 88 +++++++++---------- Benchmarks/ToListBenchmarks.md | 70 +++++++-------- .../Aggregation/Sum/Sum.Range.cs | 2 + .../AsValueEnumerable'1.Enumerable.cs | 43 +++++++-- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 8 +- .../AsValueEnumerable'1.ReadOnlyList.cs | 6 +- .../AsValueEnumerable'1.ValueEnumerable.cs | 44 +++++++++- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 8 +- .../AsValueEnumerable'6.Enumerable.cs | 54 +++++++++--- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 37 ++++---- .../AsValueEnumerable'6.ValueEnumerable.cs | 55 ++++++++++-- ...lueEnumerable'6.ValueReadOnlyCollection.cs | 40 ++++----- .../AsValueEnumerable'6.ValueReadOnlyList.cs | 31 +++---- .../AsValueEnumerable.ArraySegment.cs | 2 +- .../Collections/Generic/ListExtensions.cs | 3 - .../Conversion/ToArray/ToArray.Memory.cs | 1 - .../ToArray/ToArray.ReadOnlyMemory.cs | 1 - .../ToArray/ToArray.ReadOnlySpan.cs | 14 --- .../Conversion/ToArray/ToArray.Span.cs | 1 - .../ToArray/ToArray.ValueEnumerable.cs | 12 --- .../ToArray.ValueReadOnlyCollection.cs | 12 --- .../ToArrayAsync.AsyncValueEnumerable.cs | 12 --- NetFabric.Hyperlinq/Set/Distinct/Set.cs | 3 + .../Utils/ArrayBuilder/ArrayBuilder.cs | 7 +- .../Utils/ArrayBuilder/LargeArrayBuilder.cs | 17 ++-- .../ToArrayBuilder.ValueEnumerable.cs | 2 +- .../Utils/ArrayPoolExtensions.cs | 3 - .../Utils/Utils.AllocateUninitializedArray.cs | 1 - 28 files changed, 315 insertions(+), 262 deletions(-) diff --git a/Benchmarks/ToArrayBenchmarks.md b/Benchmarks/ToArrayBenchmarks.md index 90e3bec8a..aa3e4d4e6 100644 --- a/Benchmarks/ToArrayBenchmarks.md +++ b/Benchmarks/ToArrayBenchmarks.md @@ -23,47 +23,47 @@ Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cor Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Allocated | -|---------------------------------------------- |-------------------------- |------ |------------:|----------:|----------:|------------:|--------------:|--------:|-------:|----------:| -| Linq_Array | Array | 100 | 67.13 ns | 1.472 ns | 1.752 ns | 66.92 ns | baseline | | 0.2027 | 424 B | -| StructLinq_Array | Array | 100 | 92.84 ns | 0.390 ns | 0.326 ns | 92.71 ns | 1.38x slower | 0.04x | 0.2027 | 424 B | -| Hyperlinq_Array | Array | 100 | 44.95 ns | 0.745 ns | 0.696 ns | 44.66 ns | 1.49x faster | 0.03x | 0.2027 | 424 B | -| Hyperlinq_Array_ArrayPool | Array | 100 | 73.87 ns | 0.320 ns | 0.300 ns | 73.70 ns | 1.10x slower | 0.03x | 0.0191 | 40 B | -| | | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 674.86 ns | 11.069 ns | 10.354 ns | 670.18 ns | baseline | | 0.5655 | 1,184 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 575.61 ns | 9.396 ns | 8.789 ns | 579.51 ns | 1.17x faster | 0.02x | 0.2174 | 456 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 538.30 ns | 2.627 ns | 2.457 ns | 538.50 ns | 1.25x faster | 0.02x | 0.2213 | 464 B | -| Hyperlinq_Enumerable_ArrayPool_Value | Enumerable_Value | 100 | 535.51 ns | 1.851 ns | 1.731 ns | 534.80 ns | 1.26x faster | 0.02x | 0.0381 | 80 B | -| | | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 49.47 ns | 1.079 ns | 2.345 ns | 48.60 ns | baseline | | 0.2027 | 424 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 557.60 ns | 4.299 ns | 4.022 ns | 557.04 ns | 10.61x slower | 0.33x | 0.2174 | 456 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 53.89 ns | 1.080 ns | 0.958 ns | 53.47 ns | 1.03x slower | 0.04x | 0.2027 | 424 B | -| Hyperlinq_Collection_ArrayPool_Value | Collection_Value | 100 | 71.53 ns | 0.117 ns | 0.091 ns | 71.52 ns | 1.37x slower | 0.04x | 0.0191 | 40 B | -| | | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 53.53 ns | 1.137 ns | 1.008 ns | 53.19 ns | baseline | | 0.2027 | 424 B | -| StructLinq_List_Value | List_Value | 100 | 184.43 ns | 0.656 ns | 0.581 ns | 184.38 ns | 3.45x slower | 0.07x | 0.2027 | 424 B | -| Hyperlinq_List_Value | List_Value | 100 | 52.27 ns | 0.146 ns | 0.122 ns | 52.29 ns | 1.03x faster | 0.02x | 0.2027 | 424 B | -| Hyperlinq_List_ArrayPool_Value | List_Value | 100 | 63.73 ns | 0.422 ns | 0.394 ns | 63.53 ns | 1.19x slower | 0.02x | 0.0191 | 40 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,476.54 ns | 3.687 ns | 3.449 ns | 1,474.90 ns | baseline | | 0.7687 | 1,608 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,405.04 ns | 2.552 ns | 2.262 ns | 1,404.32 ns | 1.05x faster | 0.00x | 0.5646 | 1,184 B | -| Hyperlinq_AsyncEnumerable_ArrayPool_Value | AsyncEnumerable_Value | 100 | 1,480.90 ns | 4.645 ns | 3.879 ns | 1,479.78 ns | 1.00x slower | 0.00x | 0.3815 | 800 B | -| | | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 654.78 ns | 13.184 ns | 14.107 ns | 656.55 ns | baseline | | 0.5655 | 1,184 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 554.36 ns | 0.847 ns | 0.661 ns | 554.21 ns | 1.19x faster | 0.02x | 0.2174 | 456 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 653.44 ns | 4.970 ns | 4.406 ns | 652.06 ns | 1.01x faster | 0.02x | 0.2174 | 456 B | -| Hyperlinq_Enumerable_ArrayPool_Reference | Enumerable_Reference | 100 | 645.39 ns | 2.636 ns | 2.466 ns | 644.32 ns | 1.02x faster | 0.02x | 0.0343 | 72 B | -| | | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 49.07 ns | 1.069 ns | 1.632 ns | 48.85 ns | baseline | | 0.2027 | 424 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 561.90 ns | 11.090 ns | 12.771 ns | 555.53 ns | 11.32x slower | 0.33x | 0.2174 | 456 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 49.80 ns | 0.280 ns | 0.248 ns | 49.78 ns | 1.01x faster | 0.02x | 0.2027 | 424 B | -| Hyperlinq_Collection_ArrayPool_Reference | Collection_Reference | 100 | 61.29 ns | 0.466 ns | 0.413 ns | 61.16 ns | 1.21x slower | 0.03x | 0.0191 | 40 B | -| | | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 51.95 ns | 1.133 ns | 2.210 ns | 51.54 ns | baseline | | 0.2027 | 424 B | -| StructLinq_List_Reference | List_Reference | 100 | 557.68 ns | 2.742 ns | 2.290 ns | 556.38 ns | 10.48x slower | 0.31x | 0.2174 | 456 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 52.05 ns | 0.319 ns | 0.299 ns | 52.02 ns | 1.03x faster | 0.04x | 0.2027 | 424 B | -| Hyperlinq_List_ArrayPool_Reference | List_Reference | 100 | 62.97 ns | 0.317 ns | 0.297 ns | 62.77 ns | 1.18x slower | 0.04x | 0.0191 | 40 B | -| | | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,483.38 ns | 3.662 ns | 3.246 ns | 1,482.68 ns | baseline | | 0.7687 | 1,608 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,613.54 ns | 3.046 ns | 2.700 ns | 1,612.45 ns | 1.09x slower | 0.00x | 0.5798 | 1,216 B | -| Hyperlinq_AsyncEnumerable_ArrayPool_Reference | AsyncEnumerable_Reference | 100 | 1,639.47 ns | 4.508 ns | 3.996 ns | 1,639.51 ns | 1.11x slower | 0.00x | 0.3967 | 832 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Allocated | +|---------------------------------------------- |-------------------------- |------ |------------:|-----------:|-----------:|------------:|--------------:|--------:|-------:|----------:| +| Linq_Array | Array | 100 | 143.52 ns | 13.517 ns | 39.856 ns | 135.22 ns | baseline | | 0.2027 | 424 B | +| StructLinq_Array | Array | 100 | 337.94 ns | 43.264 ns | 127.565 ns | 315.72 ns | 2.49x slower | 1.07x | 0.2027 | 424 B | +| Hyperlinq_Array | Array | 100 | 100.89 ns | 6.689 ns | 19.722 ns | 94.25 ns | 1.47x faster | 0.49x | 0.2027 | 424 B | +| Hyperlinq_Array_ArrayPool | Array | 100 | 109.18 ns | 8.605 ns | 25.373 ns | 94.61 ns | 1.36x faster | 0.43x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 1,578.98 ns | 165.642 ns | 469.898 ns | 1,430.76 ns | baseline | | 0.5646 | 1,184 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,173.51 ns | 92.444 ns | 262.249 ns | 1,036.61 ns | 1.42x faster | 0.52x | 0.2174 | 456 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1,057.32 ns | 78.396 ns | 229.922 ns | 922.84 ns | 1.56x faster | 0.59x | 0.2022 | 424 B | +| Hyperlinq_Enumerable_ArrayPool_Value | Enumerable_Value | 100 | 863.26 ns | 62.616 ns | 184.625 ns | 754.90 ns | 1.92x faster | 0.70x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 112.45 ns | 11.254 ns | 32.109 ns | 105.85 ns | baseline | | 0.2027 | 424 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,352.42 ns | 123.192 ns | 345.444 ns | 1,211.76 ns | 12.70x slower | 4.34x | 0.2174 | 456 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 110.51 ns | 10.345 ns | 30.178 ns | 92.61 ns | 1.08x slower | 0.43x | 0.2027 | 424 B | +| Hyperlinq_Collection_ArrayPool_Value | Collection_Value | 100 | 108.14 ns | 7.474 ns | 22.038 ns | 96.64 ns | 1.04x slower | 0.36x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 94.24 ns | 8.776 ns | 25.876 ns | 79.15 ns | baseline | | 0.2027 | 424 B | +| StructLinq_List_Value | List_Value | 100 | 392.66 ns | 25.951 ns | 74.459 ns | 377.42 ns | 4.44x slower | 1.21x | 0.2022 | 424 B | +| Hyperlinq_List_Value | List_Value | 100 | 110.82 ns | 10.011 ns | 29.361 ns | 92.98 ns | 1.25x slower | 0.44x | 0.2027 | 424 B | +| Hyperlinq_List_ArrayPool_Value | List_Value | 100 | 81.42 ns | 1.743 ns | 1.630 ns | 80.92 ns | 1.20x faster | 0.21x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,714.55 ns | 292.913 ns | 835.697 ns | 2,397.87 ns | baseline | | 0.7668 | 1,608 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,563.81 ns | 159.957 ns | 469.125 ns | 2,376.18 ns | 1.01x slower | 0.25x | 0.5646 | 1,184 B | +| Hyperlinq_AsyncEnumerable_ArrayPool_Value | AsyncEnumerable_Value | 100 | 2,133.27 ns | 120.572 ns | 351.713 ns | 1,929.60 ns | 1.27x faster | 0.36x | 0.3815 | 800 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 1,663.20 ns | 164.639 ns | 467.054 ns | 1,632.07 ns | baseline | | 0.5646 | 1,184 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 915.42 ns | 17.757 ns | 28.674 ns | 906.22 ns | 1.69x faster | 0.47x | 0.2174 | 456 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,040.07 ns | 19.887 ns | 20.422 ns | 1,035.42 ns | 1.74x faster | 0.30x | 0.2174 | 456 B | +| Hyperlinq_Enumerable_ArrayPool_Reference | Enumerable_Reference | 100 | 1,073.81 ns | 80.581 ns | 237.595 ns | 1,011.11 ns | 1.64x faster | 0.58x | 0.0343 | 72 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 133.93 ns | 18.396 ns | 53.369 ns | 113.57 ns | baseline | | 0.2027 | 424 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,227.66 ns | 126.655 ns | 373.445 ns | 1,033.16 ns | 10.45x slower | 4.47x | 0.2174 | 456 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 75.55 ns | 1.647 ns | 1.286 ns | 75.54 ns | 1.55x faster | 0.65x | 0.2027 | 424 B | +| Hyperlinq_Collection_ArrayPool_Reference | Collection_Reference | 100 | 100.23 ns | 8.309 ns | 24.368 ns | 86.15 ns | 1.42x faster | 0.67x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 142.59 ns | 16.619 ns | 46.051 ns | 139.86 ns | baseline | | 0.2027 | 424 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,186.00 ns | 93.311 ns | 275.128 ns | 1,228.39 ns | 9.24x slower | 4.30x | 0.2174 | 456 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 99.29 ns | 8.310 ns | 23.843 ns | 88.13 ns | 1.47x faster | 0.52x | 0.2027 | 424 B | +| Hyperlinq_List_ArrayPool_Reference | List_Reference | 100 | 103.74 ns | 8.845 ns | 26.079 ns | 96.07 ns | 1.43x faster | 0.52x | 0.0191 | 40 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,852.49 ns | 227.110 ns | 636.839 ns | 2,728.24 ns | baseline | | 0.7668 | 1,608 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,577.52 ns | 161.290 ns | 473.037 ns | 2,409.79 ns | 1.13x faster | 0.32x | 0.5798 | 1,216 B | +| Hyperlinq_AsyncEnumerable_ArrayPool_Reference | AsyncEnumerable_Reference | 100 | 2,069.28 ns | 40.575 ns | 35.969 ns | 2,055.59 ns | 1.52x faster | 0.35x | 0.3967 | 832 B | diff --git a/Benchmarks/ToListBenchmarks.md b/Benchmarks/ToListBenchmarks.md index 82e6074e4..d2b4cc10b 100644 --- a/Benchmarks/ToListBenchmarks.md +++ b/Benchmarks/ToListBenchmarks.md @@ -23,38 +23,38 @@ Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cor Job=.NET 6 PGO EnvironmentVariables=COMPlus_ReadyToRun=0,COMPlus_TC_QuickJitForLoops=1,COMPlus_TieredPGO=1 Runtime=.NET 6.0 ``` -| Method | Categories | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Allocated | -|------------------------------------ |-------------------------- |------ |------------:|---------:|---------:|--------------:|--------:|-------:|----------:| -| Linq_Array | Array | 100 | 78.12 ns | 0.344 ns | 0.305 ns | baseline | | 0.2180 | 456 B | -| StructLinq_Array | Array | 100 | 105.98 ns | 0.367 ns | 0.307 ns | 1.36x slower | 0.01x | 0.2180 | 456 B | -| Hyperlinq_Array | Array | 100 | 54.08 ns | 0.374 ns | 0.350 ns | 1.44x faster | 0.01x | 0.2180 | 456 B | -| | | | | | | | | | | -| Linq_Enumerable_Value | Enumerable_Value | 100 | 472.95 ns | 2.738 ns | 2.561 ns | baseline | | 0.5808 | 1,216 B | -| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 565.69 ns | 2.407 ns | 2.251 ns | 1.20x slower | 0.01x | 0.2327 | 488 B | -| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 550.85 ns | 1.197 ns | 0.999 ns | 1.16x slower | 0.01x | 0.2365 | 496 B | -| | | | | | | | | | | -| Linq_Collection_Value | Collection_Value | 100 | 56.91 ns | 0.274 ns | 0.243 ns | baseline | | 0.2180 | 456 B | -| StructLinq_Collection_Value | Collection_Value | 100 | 586.92 ns | 2.851 ns | 2.527 ns | 10.31x slower | 0.07x | 0.2327 | 488 B | -| Hyperlinq_Collection_Value | Collection_Value | 100 | 66.44 ns | 0.648 ns | 0.606 ns | 1.17x slower | 0.01x | 0.2180 | 456 B | -| | | | | | | | | | | -| Linq_List_Value | List_Value | 100 | 60.17 ns | 0.425 ns | 0.355 ns | baseline | | 0.2180 | 456 B | -| StructLinq_List_Value | List_Value | 100 | 140.00 ns | 1.232 ns | 1.152 ns | 2.33x slower | 0.02x | 0.2179 | 456 B | -| Hyperlinq_List_Value | List_Value | 100 | 65.30 ns | 0.520 ns | 0.487 ns | 1.09x slower | 0.01x | 0.2180 | 456 B | -| | | | | | | | | | | -| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,466.73 ns | 4.006 ns | 3.551 ns | baseline | | 0.5798 | 1,216 B | -| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 1,472.88 ns | 4.559 ns | 4.265 ns | 1.00x slower | 0.00x | 0.5798 | 1,216 B | -| | | | | | | | | | | -| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 473.62 ns | 2.557 ns | 2.392 ns | baseline | | 0.5808 | 1,216 B | -| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 570.95 ns | 1.489 ns | 1.243 ns | 1.21x slower | 0.01x | 0.2327 | 488 B | -| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 653.91 ns | 2.104 ns | 1.969 ns | 1.38x slower | 0.01x | 0.2327 | 488 B | -| | | | | | | | | | | -| Linq_Collection_Reference | Collection_Reference | 100 | 57.16 ns | 0.823 ns | 0.687 ns | baseline | | 0.2180 | 456 B | -| StructLinq_Collection_Reference | Collection_Reference | 100 | 569.44 ns | 2.948 ns | 2.757 ns | 9.96x slower | 0.13x | 0.2327 | 488 B | -| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 61.24 ns | 0.481 ns | 0.376 ns | 1.07x slower | 0.01x | 0.2180 | 456 B | -| | | | | | | | | | | -| Linq_List_Reference | List_Reference | 100 | 60.14 ns | 0.348 ns | 0.326 ns | baseline | | 0.2180 | 456 B | -| StructLinq_List_Reference | List_Reference | 100 | 578.80 ns | 8.282 ns | 6.915 ns | 9.63x slower | 0.13x | 0.2327 | 488 B | -| Hyperlinq_List_Reference | List_Reference | 100 | 64.81 ns | 0.398 ns | 0.353 ns | 1.08x slower | 0.01x | 0.2180 | 456 B | -| | | | | | | | | | | -| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,466.21 ns | 3.947 ns | 3.692 ns | baseline | | 0.5798 | 1,216 B | -| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 1,616.07 ns | 4.787 ns | 4.478 ns | 1.10x slower | 0.00x | 0.5951 | 1,248 B | +| Method | Categories | Count | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Allocated | +|------------------------------------ |-------------------------- |------ |-----------:|----------:|----------:|------------:|--------------:|--------:|-------:|----------:| +| Linq_Array | Array | 100 | 152.3 ns | 13.07 ns | 38.55 ns | 153.11 ns | baseline | | 0.2179 | 456 B | +| StructLinq_Array | Array | 100 | 208.8 ns | 15.48 ns | 45.65 ns | 183.48 ns | 1.42x slower | 0.30x | 0.2179 | 456 B | +| Hyperlinq_Array | Array | 100 | 108.0 ns | 9.94 ns | 29.29 ns | 89.70 ns | 1.49x faster | 0.48x | 0.2180 | 456 B | +| | | | | | | | | | | | +| Linq_Enumerable_Value | Enumerable_Value | 100 | 944.9 ns | 62.47 ns | 184.20 ns | 988.12 ns | baseline | | 0.5808 | 1,216 B | +| StructLinq_Enumerable_Value | Enumerable_Value | 100 | 1,145.8 ns | 103.68 ns | 304.08 ns | 966.78 ns | 1.26x slower | 0.41x | 0.2327 | 488 B | +| Hyperlinq_Enumerable_Value | Enumerable_Value | 100 | 1,059.8 ns | 77.40 ns | 228.23 ns | 933.82 ns | 1.17x slower | 0.35x | 0.2174 | 456 B | +| | | | | | | | | | | | +| Linq_Collection_Value | Collection_Value | 100 | 118.8 ns | 8.42 ns | 24.82 ns | 107.77 ns | baseline | | 0.2180 | 456 B | +| StructLinq_Collection_Value | Collection_Value | 100 | 1,177.6 ns | 97.68 ns | 288.02 ns | 1,022.94 ns | 10.33x slower | 3.33x | 0.2327 | 488 B | +| Hyperlinq_Collection_Value | Collection_Value | 100 | 128.4 ns | 14.08 ns | 40.84 ns | 106.17 ns | 1.11x slower | 0.38x | 0.2179 | 456 B | +| | | | | | | | | | | | +| Linq_List_Value | List_Value | 100 | 117.5 ns | 7.59 ns | 21.42 ns | 109.69 ns | baseline | | 0.2179 | 456 B | +| StructLinq_List_Value | List_Value | 100 | 287.2 ns | 24.90 ns | 73.42 ns | 250.69 ns | 2.52x slower | 0.74x | 0.2179 | 456 B | +| Hyperlinq_List_Value | List_Value | 100 | 127.9 ns | 12.46 ns | 36.53 ns | 107.50 ns | 1.13x slower | 0.37x | 0.2179 | 456 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,460.6 ns | 109.22 ns | 318.61 ns | 2,334.36 ns | baseline | | 0.5798 | 1,216 B | +| Hyperlinq_AsyncEnumerable_Value | AsyncEnumerable_Value | 100 | 2,772.4 ns | 175.42 ns | 517.23 ns | 2,701.79 ns | 1.15x slower | 0.27x | 0.5798 | 1,216 B | +| | | | | | | | | | | | +| Linq_Enumerable_Reference | Enumerable_Reference | 100 | 950.9 ns | 76.10 ns | 224.39 ns | 836.78 ns | baseline | | 0.5798 | 1,216 B | +| StructLinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,052.6 ns | 67.60 ns | 198.25 ns | 943.04 ns | 1.17x slower | 0.35x | 0.2327 | 488 B | +| Hyperlinq_Enumerable_Reference | Enumerable_Reference | 100 | 1,457.2 ns | 128.46 ns | 378.76 ns | 1,202.12 ns | 1.59x slower | 0.49x | 0.2327 | 488 B | +| | | | | | | | | | | | +| Linq_Collection_Reference | Collection_Reference | 100 | 114.2 ns | 11.38 ns | 33.02 ns | 94.32 ns | baseline | | 0.2180 | 456 B | +| StructLinq_Collection_Reference | Collection_Reference | 100 | 1,181.8 ns | 103.00 ns | 302.08 ns | 1,018.63 ns | 10.90x slower | 3.58x | 0.2327 | 488 B | +| Hyperlinq_Collection_Reference | Collection_Reference | 100 | 119.5 ns | 9.30 ns | 27.42 ns | 103.49 ns | 1.11x slower | 0.35x | 0.2179 | 456 B | +| | | | | | | | | | | | +| Linq_List_Reference | List_Reference | 100 | 144.3 ns | 14.33 ns | 41.36 ns | 137.96 ns | baseline | | 0.2180 | 456 B | +| StructLinq_List_Reference | List_Reference | 100 | 1,162.4 ns | 114.20 ns | 336.71 ns | 955.59 ns | 8.67x slower | 3.17x | 0.2327 | 488 B | +| Hyperlinq_List_Reference | List_Reference | 100 | 103.2 ns | 2.56 ns | 6.76 ns | 100.94 ns | 1.42x faster | 0.42x | 0.2179 | 456 B | +| | | | | | | | | | | | +| Linq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,565.5 ns | 129.56 ns | 382.00 ns | 2,416.41 ns | baseline | | 0.5798 | 1,216 B | +| Hyperlinq_AsyncEnumerable_Reference | AsyncEnumerable_Reference | 100 | 2,867.6 ns | 191.57 ns | 564.84 ns | 2,539.05 ns | 1.14x slower | 0.29x | 0.5951 | 1,248 B | diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs index 2712efc14..389af6bed 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs @@ -1,3 +1,4 @@ +using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -11,6 +12,7 @@ static int SumRange(int start, int count) [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SkipLocalsInit] static unsafe TResult SumRange(int start, int count, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs index b75026b7e..c13bc1e2b 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs @@ -1,4 +1,5 @@ -using System.Buffers; +using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -34,23 +35,51 @@ IEnumerator IEnumerable.GetEnumerator() #region Conversion + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerable AsValueEnumerable() => this; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable AsEnumerable() => source; - [MethodImpl(MethodImplOptions.AggressiveInlining)] public TSource[] ToArray() - => this.ToArray, ValueEnumerator, TSource>(); + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + { + if (collection.Count is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(collection.Count); + collection.CopyTo(result, 0); + return result; + } + + using var arrayBuilder = ValueEnumerableExtensions.ToArrayBuilder, ValueEnumerator, TSource>(this, ArrayPool.Shared, false); + return arrayBuilder.ToArray(); + } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => this.ToArray, ValueEnumerator, TSource>(pool, clearOnDispose); - + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + { + if (collection.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(collection.Count, clearOnDispose); + collection.CopyTo(result.Rented, 0); + return result; + } + + using var arrayBuilder = ValueEnumerableExtensions.ToArrayBuilder, ValueEnumerator, TSource>(this, pool, clearOnDispose); + return arrayBuilder.ToArray(pool, clearOnDispose); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => this.ToList, ValueEnumerator, TSource>(); + => ToArray().AsList(); #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index 2a5f15979..874633921 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -41,7 +41,6 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - [SkipLocalsInit] public void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) @@ -58,7 +57,7 @@ public void CopyTo(TSource[] array, int arrayIndex) else { using var enumerator = GetEnumerator(); - if (arrayIndex is 0 && array.Length == Count) + if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination { for (var index = 0; index < array.Length; index++) { @@ -93,13 +92,14 @@ bool ICollection.Remove(TSource item) #region Conversion + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerable AsValueEnumerable() => this; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IReadOnlyCollection AsEnumerable() => source; - [SkipLocalsInit] public TSource[] ToArray() { if (source.Count is 0) @@ -110,7 +110,6 @@ public TSource[] ToArray() return result; } - [SkipLocalsInit] public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) @@ -122,7 +121,6 @@ public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispos } [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public List ToList() => ToArray().AsList(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs index 51198e4df..831cc1dc5 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs @@ -62,7 +62,6 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - [SkipLocalsInit] public void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) @@ -79,7 +78,7 @@ public void CopyTo(TSource[] array, int arrayIndex) else { using var enumerator = GetEnumerator(); - if (arrayIndex is 0 && array.Length == Count) + if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination { for (var index = 0; index < array.Length; index++) { @@ -164,7 +163,6 @@ public IReadOnlyCollection AsEnumerable() // ReSharper disable once HeapView.PossibleBoxingAllocation => source; - [SkipLocalsInit] public TSource[] ToArray() { if (source.Count is 0) @@ -175,7 +173,6 @@ public TSource[] ToArray() return result; } - [SkipLocalsInit] public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) @@ -187,7 +184,6 @@ public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispos } [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public List ToList() => ToArray().AsList(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs index cf3406b8b..f831c3133 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs @@ -1,4 +1,6 @@ -using System.Collections; +using System; +using System.Buffers; +using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -38,12 +40,52 @@ IEnumerator IEnumerable.GetEnumerator() #region Conversion + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerable AsValueEnumerable() => this; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable AsEnumerable() => source; + public TSource[] ToArray() + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + { + if (collection.Count is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(collection.Count); + collection.CopyTo(result, 0); + return result; + } + + using var arrayBuilder = ToArrayBuilder, TEnumerator, TSource>(source, ArrayPool.Shared, false); + return arrayBuilder.ToArray(); + } + + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + { + if (collection.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(collection.Count, clearOnDispose); + collection.CopyTo(result.Rented, 0); + return result; + } + + using var arrayBuilder = ToArrayBuilder, TEnumerator, TSource>(source, pool, clearOnDispose); + return arrayBuilder.ToArray(pool, clearOnDispose); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => ToArray().AsList(); + #endregion #region Quantifier diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index f77525e38..ca5e33d74 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -46,7 +46,6 @@ IEnumerator IEnumerable.GetEnumerator() bool ICollection.IsReadOnly => true; - [SkipLocalsInit] public void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) @@ -63,7 +62,7 @@ public void CopyTo(TSource[] array, int arrayIndex) else { using var enumerator = GetEnumerator(); - if (arrayIndex is 0 && array.Length == Count) + if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination { for (var index = 0; index < array.Length; index++) { @@ -98,13 +97,14 @@ bool ICollection.Remove(TSource item) #region Conversion + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerable AsValueEnumerable() => this; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IReadOnlyCollection AsEnumerable() => source; - [SkipLocalsInit] public TSource[] ToArray() { if (source.Count is 0) @@ -115,7 +115,6 @@ public TSource[] ToArray() return result; } - [SkipLocalsInit] public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) @@ -127,7 +126,6 @@ public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispos } [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public List ToList() => ToArray().AsList(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs index f6a7dd9ff..e97ffcf52 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -62,36 +62,62 @@ internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetE [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() + public readonly TEnumerator2 GetEnumerator() => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() + readonly TEnumerator IValueEnumerable.GetEnumerator() => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable AsValueEnumerable() + public readonly ValueEnumerable AsValueEnumerable() => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerable AsEnumerable() + public readonly TEnumerable AsEnumerable() => source; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TSource[] ToArray() - => this.ToArray, TEnumerator, TSource>(); + public readonly TSource[] ToArray() + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + { + if (collection.Count is 0) + return Array.Empty(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => this.ToArray, TEnumerator, TSource>(pool, clearOnDispose); + var result = Utils.AllocateUninitializedArray(collection.Count); + collection.CopyTo(result, 0); + return result; + } + + using var arrayBuilder = ValueEnumerableExtensions.ToArrayBuilder, TEnumerator, TSource>(this, ArrayPool.Shared, false); + return arrayBuilder.ToArray(); + } + + public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + { + if (collection.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(collection.Count, clearOnDispose); + collection.CopyTo(result.Rented, 0); + return result; + } + + using var arrayBuilder = ValueEnumerableExtensions.ToArrayBuilder, TEnumerator, TSource>(this, pool, clearOnDispose); + return arrayBuilder.ToArray(pool, clearOnDispose); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => this.ToList, TEnumerator, TSource>(); + public readonly List ToList() + => ToArray().AsList(); #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index a06085e2f..503890723 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -68,20 +68,19 @@ public readonly int Count => source.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() + public readonly TEnumerator2 GetEnumerator() => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() + readonly TEnumerator IValueEnumerable.GetEnumerator() => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); bool ICollection.IsReadOnly => true; - [SkipLocalsInit] - public void CopyTo(TSource[] array, int arrayIndex) + public readonly void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) return; @@ -97,7 +96,7 @@ public void CopyTo(TSource[] array, int arrayIndex) else { using var enumerator = getEnumerator.Invoke(source); - if (arrayIndex is 0 && array.Length == Count) + if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination { for (var index = 0; index < array.Length; index++) { @@ -117,32 +116,30 @@ public void CopyTo(TSource[] array, int arrayIndex) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] - bool ICollection.Contains(TSource item) + readonly bool ICollection.Contains(TSource item) => Contains(item, default); [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) + readonly void ICollection.Add(TSource item) => Throw.NotSupportedException(); [ExcludeFromCodeCoverage] - void ICollection.Clear() + readonly void ICollection.Clear() => Throw.NotSupportedException(); [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) + readonly bool ICollection.Remove(TSource item) => Throw.NotSupportedException(); #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable AsValueEnumerable() + public readonly ValueEnumerable AsValueEnumerable() => this; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerable AsEnumerable() + public readonly TEnumerable AsEnumerable() => source; - [SkipLocalsInit] - public TSource[] ToArray() + public readonly TSource[] ToArray() { if (source.Count is 0) return Array.Empty(); @@ -152,8 +149,7 @@ public TSource[] ToArray() return result; } - [SkipLocalsInit] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) return EmptyMemoryOwner.Instance; @@ -164,14 +160,13 @@ public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispos } [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] - public List ToList() + public readonly List ToList() => ToArray().AsList(); #endregion #region Quantifier - public bool Contains(TSource value, IEqualityComparer? comparer = default) + public readonly bool Contains(TSource value, IEqualityComparer? comparer = default) => Count is not 0 && source.Contains(value, comparer); #endregion diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs index 639bef0d8..403cbd298 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -61,30 +62,70 @@ internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetE [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() + public readonly TEnumerator2 GetEnumerator() => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() + readonly TEnumerator IValueEnumerable.GetEnumerator() => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.PossibleBoxingAllocation => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.PossibleBoxingAllocation => source.GetEnumerator(); #region Conversion - public ValueEnumerable AsValueEnumerable() + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerable AsValueEnumerable() => this; - public TEnumerable AsEnumerable() + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly TEnumerable AsEnumerable() => source; + public TSource[] ToArray() + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + { + if (collection.Count is 0) + return Array.Empty(); + + var result = Utils.AllocateUninitializedArray(collection.Count); + collection.CopyTo(result, 0); + return result; + } + + using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false); + return arrayBuilder.ToArray(); + } + + public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + { + // ReSharper disable once HeapView.PossibleBoxingAllocation + if (source is ICollection collection) + { + if (collection.Count is 0) + return EmptyMemoryOwner.Instance; + + var result = pool.RentDisposable(collection.Count, clearOnDispose); + collection.CopyTo(result.Rented, 0); + return result; + } + + using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose); + return arrayBuilder.ToArray(pool, clearOnDispose); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public List ToList() + => ToArray().AsList(); + #endregion #region Quantifier - public bool Contains(TSource value, IEqualityComparer? comparer = default) + public readonly bool Contains(TSource value, IEqualityComparer? comparer = default) { // ReSharper disable once HeapView.PossibleBoxingAllocation if (comparer.UseDefaultComparer() && source is ICollection collection) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index 28aabf70a..86577bfed 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -69,22 +69,21 @@ public readonly int Count => source.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() + public readonly TEnumerator2 GetEnumerator() => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() + readonly TEnumerator IValueEnumerable.GetEnumerator() => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => source.GetEnumerator(); - bool ICollection.IsReadOnly + readonly bool ICollection.IsReadOnly => true; - [SkipLocalsInit] - public void CopyTo(TSource[] array, int arrayIndex) + public readonly void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) return; @@ -102,7 +101,7 @@ public void CopyTo(TSource[] array, int arrayIndex) using var enumerator = getEnumerator.Invoke(source); if (arrayIndex is 0 && array.Length == Count) { - for (var index = 0; index < array.Length; index++) + for (var index = 0; index < array.Length; index++) // to enable range check elimination { _ = enumerator.MoveNext(); array[index] = enumerator.Current; @@ -120,29 +119,30 @@ public void CopyTo(TSource[] array, int arrayIndex) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - bool ICollection.Contains(TSource item) + readonly bool ICollection.Contains(TSource item) => Contains(item, default); [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) + readonly void ICollection.Add(TSource item) => Throw.NotSupportedException(); [ExcludeFromCodeCoverage] - void ICollection.Clear() + readonly void ICollection.Clear() => Throw.NotSupportedException(); [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) + readonly bool ICollection.Remove(TSource item) => Throw.NotSupportedException(); #region Conversion - public ValueEnumerable AsValueEnumerable() + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly ValueEnumerable AsValueEnumerable() => this; - public TEnumerable AsEnumerable() + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly TEnumerable AsEnumerable() => source; - [SkipLocalsInit] - public TSource[] ToArray() + public readonly TSource[] ToArray() { if (source.Count is 0) return Array.Empty(); @@ -152,8 +152,7 @@ public TSource[] ToArray() return result; } - [SkipLocalsInit] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) return EmptyMemoryOwner.Instance; @@ -164,15 +163,14 @@ public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispos } [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] - public List ToList() + public readonly List ToList() => ToArray().AsList(); #endregion #region Quantifier - public bool Contains(TSource value, IEqualityComparer? comparer = default) + public readonly bool Contains(TSource value, IEqualityComparer? comparer = default) { if (Count is 0) return false; diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs index 957fa250f..265b3822a 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs @@ -80,23 +80,21 @@ public readonly int Count => source.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() + public readonly TEnumerator2 GetEnumerator() => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() + readonly TEnumerator IValueEnumerable.GetEnumerator() => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() + readonly IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => source.GetEnumerator(); - bool ICollection.IsReadOnly + readonly bool ICollection.IsReadOnly => true; - - [SkipLocalsInit] - public void CopyTo(TSource[] array, int arrayIndex) + public readonly void CopyTo(TSource[] array, int arrayIndex) { if (Count is 0) return; @@ -112,7 +110,7 @@ public void CopyTo(TSource[] array, int arrayIndex) else { using var enumerator = getEnumerator.Invoke(source); - if (arrayIndex is 0 && array.Length == Count) + if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination { for (var index = 0; index < array.Length; index++) { @@ -132,7 +130,7 @@ public void CopyTo(TSource[] array, int arrayIndex) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - bool ICollection.Contains(TSource item) + readonly bool ICollection.Contains(TSource item) => Contains(item, default); public readonly int IndexOf(TSource item) @@ -181,14 +179,15 @@ public readonly ReadOnlyListExtensions.SkipTakeEnumerable AsValueEnumerable() => this; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly TEnumerable AsEnumerable() => source; - [SkipLocalsInit] - public TSource[] ToArray() + public readonly TSource[] ToArray() { if (source.Count is 0) return Array.Empty(); @@ -198,8 +197,7 @@ public TSource[] ToArray() return result; } - [SkipLocalsInit] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) return EmptyMemoryOwner.Instance; @@ -210,8 +208,7 @@ public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispos } [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] - public List ToList() + public readonly List ToList() => ToArray().AsList(); #endregion @@ -240,7 +237,7 @@ public readonly SelectAtEnumerable? comparer = default) + public readonly bool Contains(TSource value, IEqualityComparer? comparer = default) { if (Count is 0) return false; diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index a75b58fe4..66b2d7577 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -74,7 +74,7 @@ bool ICollection.IsReadOnly [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) - => System.Array.Copy(source.Array!, source.Offset, array, arrayIndex, source.Count); + => source.AsSpan().CopyTo(array.AsSpan(arrayIndex)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Contains(TSource item) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs index 77e919eac..3531bba2d 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs @@ -42,9 +42,6 @@ static List WrapArray(TSource[] source) } // ReSharper disable once ClassNeverInstantiated.Local -#if NET5_0_OR_GREATER - [SkipLocalsInit] -#endif class ListLayout { public TSource[]? items; diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs index d58fc28ff..ca2802efa 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs @@ -8,7 +8,6 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public static IMemoryOwner ToArray(this Memory source, ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlyMemory)source).Span.ToArray(pool, clearOnDispose); } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs index ee17c3a1a..267ff3a32 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs @@ -8,7 +8,6 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public static IMemoryOwner ToArray(this ReadOnlyMemory source, ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArray(pool, clearOnDispose); } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index c92d275d3..b91c28ede 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -8,11 +8,9 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] static TSource[] ToArray(this ReadOnlySpan source) => source.ToArray(); - [SkipLocalsInit] public static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose = default) { if (source.Length is 0) @@ -26,7 +24,6 @@ public static IMemoryOwner ToArray(this ReadOnlySpan ////////////////////////////////////////////////////////////////////////////////////////////////// [GeneratorIgnore] - [SkipLocalsInit] static TSource[] ToArray(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -38,7 +35,6 @@ static TSource[] ToArray(this ReadOnlySpan source, } [GeneratorIgnore] - [SkipLocalsInit] static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { @@ -53,7 +49,6 @@ static IMemoryOwner ToArray(this ReadOnlySpan(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -65,7 +60,6 @@ static TSource[] ToArrayAt(this ReadOnlySpan sourc } [GeneratorIgnore] - [SkipLocalsInit] static IMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { @@ -80,7 +74,6 @@ static IMemoryOwner ToArrayAt(this ReadOnlySpan(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction { @@ -93,7 +86,6 @@ static TResult[] ToArray(this ReadOnlySpan } [GeneratorIgnore] - [SkipLocalsInit] static TResult[] ToArrayVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction @@ -109,7 +101,6 @@ static TResult[] ToArrayVector(thi } [GeneratorIgnore] - [SkipLocalsInit] static IMemoryOwner ToArrayVector(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction @@ -125,7 +116,6 @@ static IMemoryOwner ToArrayVector ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { @@ -140,7 +130,6 @@ static IMemoryOwner ToArray(this ReadOnlyS ////////////////////////////////////////////////////////////////////////////////////////////////// [GeneratorIgnore] - [SkipLocalsInit] static TResult[] ToArrayAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction { @@ -153,7 +142,6 @@ static TResult[] ToArrayAt(this ReadOnlySpan ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { @@ -169,7 +157,6 @@ static IMemoryOwner ToArrayAt(this ReadOnl [GeneratorIgnore] - [SkipLocalsInit] static TResult[] ToArray(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction @@ -182,7 +169,6 @@ static TResult[] ToArray(this ReadOnlyS } [GeneratorIgnore] - [SkipLocalsInit] static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs index ba6f4bd92..1bf2f55f9 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs @@ -8,7 +8,6 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public static IMemoryOwner ToArray(this Span source, ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source).ToArray(pool, clearOnDispose); } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index 3daa011b2..8c4ff0c9c 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -8,7 +8,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [SkipLocalsInit] public static TSource[] ToArray(this TEnumerable source) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -28,7 +27,6 @@ public static TSource[] ToArray(this TEnumera return arrayBuilder.ToArray(); } - [SkipLocalsInit] public static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -52,7 +50,6 @@ public static IMemoryOwner ToArray(t [GeneratorIgnore] - [SkipLocalsInit] internal static TSource[] ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -63,7 +60,6 @@ internal static TSource[] ToArray } [GeneratorIgnore] - [SkipLocalsInit] internal static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -77,7 +73,6 @@ internal static IMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -88,7 +83,6 @@ internal static TSource[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -102,7 +96,6 @@ internal static IMemoryOwner ToArrayAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -113,7 +106,6 @@ static TResult[] ToArray( } [GeneratorIgnore] - [SkipLocalsInit] static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -126,7 +118,6 @@ static IMemoryOwner ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -137,7 +128,6 @@ static TResult[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -151,7 +141,6 @@ static IMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -163,7 +152,6 @@ internal static TResult[] ToArray ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index 20f06db2d..ec1763e77 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -8,7 +8,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [SkipLocalsInit] public static TSource[] ToArray(this TEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -25,7 +24,6 @@ public static TSource[] ToArray(this TEnumera return result; } - [SkipLocalsInit] public static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -45,7 +43,6 @@ public static IMemoryOwner ToArray(t ////////////////////////////////////////////////////////////////////////////////////////////////// [GeneratorIgnore] - [SkipLocalsInit] static TSource[] ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -56,7 +53,6 @@ static TSource[] ToArray(this TEn : ValueEnumerableExtensions.ToArray(source, predicate); [GeneratorIgnore] - [SkipLocalsInit] static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -68,7 +64,6 @@ static IMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -79,7 +74,6 @@ static TSource[] ToArrayAt(this T [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] static IMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -91,7 +85,6 @@ static IMemoryOwner ToArrayAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -106,7 +99,6 @@ internal static TResult[] ToArray ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -124,7 +116,6 @@ internal static IMemoryOwner ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -139,7 +130,6 @@ internal static TResult[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -156,7 +146,6 @@ internal static IMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -167,7 +156,6 @@ static TResult[] ToArray(source, predicate, selector); [GeneratorIgnore] - [SkipLocalsInit] static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs index 80a755b37..82344d8dc 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs @@ -10,14 +10,12 @@ public static partial class AsyncValueEnumerableExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public static async ValueTask ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -27,7 +25,6 @@ public static async ValueTask> ToArrayAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -36,7 +33,6 @@ static async ValueTask ToArrayAsync> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -47,7 +43,6 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -56,7 +51,6 @@ static async ValueTask ToArrayAtAsync> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -67,7 +61,6 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -76,7 +69,6 @@ static async ValueTask ToArrayAsync> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -87,7 +79,6 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -96,7 +87,6 @@ static async ValueTask ToArrayAtAsync> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -107,7 +97,6 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -117,7 +106,6 @@ static async ValueTask ToArrayAsync> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index df69e9e1a..79243e1ef 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -201,6 +201,9 @@ public readonly void CopyTo(Span span) { if (Count is 0) return; + + if (span.Length < Count) + Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); var source = slots!.AsSpan(0, Count); for (var index = 0; index < source.Length; index++) diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs index 3af33d334..36e8ecdcf 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs @@ -53,7 +53,6 @@ public ArrayBuilder(ArrayPool pool) public int Count => index; [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public readonly ReadOnlySpan AsSpan() => buffer.AsSpan(0, index); @@ -62,7 +61,6 @@ public readonly ReadOnlySpan AsSpan() /// /// The item to add. [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public void Add(T item) { var buffer = this.buffer; @@ -82,14 +80,12 @@ public void Add(T item) // Non-inline to improve code quality as uncommon path [MethodImpl(MethodImplOptions.NoInlining)] - [SkipLocalsInit] void AddWithBufferAllocation(T item) { EnsureCapacity(index + 1); buffer[index++] = item; } - [SkipLocalsInit] void EnsureCapacity(int minimum) { Debug.Assert(minimum > index); @@ -107,14 +103,13 @@ void EnsureCapacity(int minimum) var next = pool.Rent(nextCapacity); if (index is not 0) { - Array.Copy(buffer, next, index); + buffer.AsSpan().CopyTo(next.AsSpan(index)); pool.Return(buffer); } buffer = next; } - [SkipLocalsInit] public readonly void Dispose() { if (index is not 0) diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs index 0d009e050..bb119f262 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs @@ -74,7 +74,6 @@ public LargeArrayBuilder(int maxCapacity, ArrayPool pool, ArrayPool arra /// The item to add. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public void Add(T item) { Debug.Assert(maxCapacity > count); @@ -98,7 +97,6 @@ public void Add(T item) // Non-inline to improve code quality as uncommon path [MethodImpl(MethodImplOptions.NoInlining)] - [SkipLocalsInit] void AddWithBufferAllocation(T item) { AllocateBuffer(); @@ -110,24 +108,22 @@ void AddWithBufferAllocation(T item) /// /// The destination array. /// The index in to start copying to. - [SkipLocalsInit] public readonly void CopyTo(T[] array, int arrayIndex) { + var span = array.AsSpan(); foreach (var buffer in buffers.AsSpan()) { - var length = buffer.Length; - Array.Copy(buffer, 0, array, arrayIndex, length); - arrayIndex += length; + buffer.AsSpan().CopyTo(span); + span = span.Slice(buffer.Length); } - if (arrayIndex < count) - Array.Copy(current, 0, array, arrayIndex, count - arrayIndex); + if (span.Length is not 0) + current.AsSpan(0, span.Length).CopyTo(span); } /// /// Creates an array from the contents of this builder. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public readonly T[] ToArray() { if (count is 0) @@ -140,7 +136,6 @@ public readonly T[] ToArray() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) { if (count is 0) @@ -152,7 +147,6 @@ public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) } [MethodImpl(MethodImplOptions.NoInlining)] - [SkipLocalsInit] void AllocateBuffer() { Debug.Assert((uint)maxCapacity > (uint)count); @@ -176,7 +170,6 @@ void AllocateBuffer() index = 0; } - [SkipLocalsInit] public readonly void Dispose() { pool.Return(current, clearOnDispose); diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs index 4cc32ece3..4729f52c6 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs @@ -7,7 +7,7 @@ public static partial class ValueEnumerableExtensions { [GeneratorIgnore] - static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose) + internal static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { diff --git a/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs b/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs index bd17c1873..bf86446f1 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs @@ -7,12 +7,10 @@ namespace NetFabric.Hyperlinq static class ArrayPoolExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public static MemoryOwner RentDisposable(this ArrayPool pool, int length, bool clearOnDispose) => new(pool, length, clearOnDispose); } - [SkipLocalsInit] class MemoryOwner : IMemoryOwner { @@ -62,7 +60,6 @@ public void Dispose() } } - [SkipLocalsInit] class EmptyMemoryOwner : IMemoryOwner { diff --git a/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs b/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs index 3c81508c6..56611920d 100644 --- a/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs +++ b/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs @@ -7,7 +7,6 @@ static partial class Utils { [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] public static T[] AllocateUninitializedArray(int count) #if NET5_0_OR_GREATER => GC.AllocateUninitializedArray(count, pinned: false); From d12a5254a801d10ded83bb3262cd4295e3d2c454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Thu, 9 Sep 2021 22:58:32 +0100 Subject: [PATCH 48/61] Add Lease<> type (#380) * Add Lease<> type * Check for disposed object in GetEnumerator() * Fix Length * Fix Reset() * Add AsEnumerable() and AsValueEnumerable() * Fix unit tests --- .../ToArray/LargeArrayBuilder.Tests.cs | 6 +- .../ToArray/ToArray.ReadOnlyList.Tests.cs | 31 ++- .../ToArray/ToArray.ReadOnlySpan.Tests.cs | 18 +- .../ToArray/ToArray.ValueEnumerable.Tests.cs | 30 ++- .../ToArray.ValueReadOnlyCollection.Tests.cs | 15 +- ...ToArrayAsync.AsyncValueEnumerable.Tests.cs | 30 ++- .../Distinct/Distinct.ReadOnlySpan.Tests.cs | 3 +- .../Distinct.ValueEnumerable.Tests.cs | 5 +- ...sAsyncValueEnumerable'1.AsyncEnumerable.cs | 2 +- ...sAsyncValueEnumerable'6.AsyncEnumerable.cs | 2 +- .../AsValueEnumerable'1.Enumerable.cs | 6 +- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 6 +- .../AsValueEnumerable'1.ReadOnlyList.cs | 6 +- .../AsValueEnumerable'1.ValueEnumerable.cs | 6 +- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 6 +- .../AsValueEnumerable'6.Enumerable.cs | 6 +- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 6 +- .../AsValueEnumerable'6.ValueEnumerable.cs | 6 +- ...lueEnumerable'6.ValueReadOnlyCollection.cs | 6 +- .../AsValueEnumerable'6.ValueReadOnlyList.cs | 6 +- .../AsValueEnumerable.ArraySegment.cs | 30 ++- .../Conversion/ToArray/ToArray.Memory.cs | 2 +- .../ToArray/ToArray.ReadOnlyMemory.cs | 2 +- .../ToArray/ToArray.ReadOnlySpan.cs | 36 +-- .../Conversion/ToArray/ToArray.Span.cs | 2 +- .../ToArray/ToArray.ValueEnumerable.cs | 16 +- .../ToArray.ValueReadOnlyCollection.cs | 30 +-- .../ToArrayAsync.AsyncValueEnumerable.cs | 12 +- .../Where/Where/Where.ArraySegment.cs | 2 +- .../Where/Where/Where.AsyncValueEnumerable.cs | 2 +- .../Where/Where/Where.ReadOnlyMemory.cs | 2 +- .../Where/Where/Where.ReadOnlySpan.cs | 2 +- .../Where/Where/Where.ValueEnumerable.cs | 2 +- .../Where/Where.ValueReadOnlyCollection.cs | 2 +- .../Where/WhereAt/WhereAt.ArraySegment.cs | 2 +- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 2 +- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 2 +- .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 2 +- .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 2 +- .../WhereAt.ValueReadOnlyCollection.cs | 2 +- .../WhereSelect/WhereSelect.ArraySegment.cs | 2 +- .../WhereSelect.AsyncValueEnumerable.cs | 2 +- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 2 +- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 2 +- .../WhereSelect.ValueEnumerable.cs | 2 +- .../WhereSelect.ValueReadOnlyCollection.cs | 2 +- .../Generation/AsyncValueEnumerable/Range.cs | 6 +- .../Generation/AsyncValueEnumerable/Repeat.cs | 6 +- .../Generation/ValueEnumerable/Range.cs | 4 +- .../Generation/ValueEnumerable/Repeat.cs | 8 +- NetFabric.Hyperlinq/Lease.cs | 214 ++++++++++++++++++ .../Select/Select/Select.ArraySegment.cs | 2 +- .../Select/Select.AsyncValueEnumerable.cs | 2 +- .../Select/Select/Select.ReadOnlyMemory.cs | 2 +- .../Select/Select/Select.ReadOnlySpan.cs | 2 +- .../Select/Select/Select.ValueEnumerable.cs | 2 +- .../Select/Select.ValueReadOnlyCollection.cs | 2 +- .../Select/Select/Select.ValueReadOnlyList.cs | 2 +- .../Select/SelectAt/SelectAt.ArraySegment.cs | 2 +- .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 2 +- .../SelectAt/SelectAt.ReadOnlyMemory.cs | 2 +- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 2 +- .../SelectAt/SelectAt.ValueEnumerable.cs | 2 +- .../SelectAt.ValueReadOnlyCollection.cs | 2 +- .../SelectAt/SelectAt.ValueReadOnlyList.cs | 2 +- .../Select/SelectVector/SelectVector.Range.cs | 4 +- .../SelectVector/SelectVector.ReadOnlySpan.cs | 2 +- .../Set/Distinct/Distinct.ArraySegment.cs | 2 +- .../Distinct/Distinct.AsyncValueEnumerable.cs | 2 +- .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 2 +- .../Set/Distinct/Distinct.ReadOnlySpan.cs | 2 +- .../Set/Distinct/Distinct.ValueEnumerable.cs | 2 +- NetFabric.Hyperlinq/Set/Distinct/Set.cs | 4 +- .../Utils/ArrayBuilder/LargeArrayBuilder.cs | 6 +- .../Utils/ArrayPoolExtensions.cs | 63 +----- README.md | 8 +- 76 files changed, 463 insertions(+), 268 deletions(-) create mode 100644 NetFabric.Hyperlinq/Lease.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs index 2b4739215..2fec2ac88 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs @@ -43,7 +43,8 @@ public void ToArray_MemoryPool_Must_Succeed(int count) var expected = Enumerable .Range(0, count) .ToArray(); - using var builder = new LargeArrayBuilder(ArrayPool.Shared, false); + // ReSharper disable once ConvertToUsingDeclaration + using var builder = new LargeArrayBuilder(pool, false); for (var index = 0; index < count; index++) builder.Add(expected[index]); @@ -51,7 +52,8 @@ public void ToArray_MemoryPool_Must_Succeed(int count) using var result = builder.ToArray(pool, false); // Assert - _ = result.Memory.Must() + _ = result.Must() + .BeEnumerableOf() .BeEqualTo(expected); } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs index d0c43ab4c..7b7e23ae0 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs @@ -51,14 +51,16 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source, int skip, int take) .ToArray(); // Act + // ReSharper disable once ConvertToUsingDeclaration using var result = wrapped.AsValueEnumerable() .Skip(skip) .Take(take) .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -116,8 +118,9 @@ public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, int skip, in .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -175,8 +178,9 @@ public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, int skip, .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -233,8 +237,9 @@ public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, int skip, int .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -291,8 +296,9 @@ public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, int skip, i .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -353,8 +359,9 @@ public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, int .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs index 6c6fbabc1..875c29bcd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs @@ -26,7 +26,8 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source) .ToArray(pool); // Assert - _ = result.Memory.Must() + _ = result.Must() + .BeEnumerableOf() .BeEqualTo(expected); } @@ -77,7 +78,8 @@ public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func() .BeEqualTo(expected); } @@ -128,7 +130,8 @@ public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func() .BeEqualTo(expected); } @@ -178,7 +181,8 @@ public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, Func() .BeEqualTo(expected); } @@ -228,7 +232,8 @@ public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func() .BeEqualTo(expected); } @@ -282,7 +287,8 @@ public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Fun .ToArray(pool); // Assert - _ = result.Memory.Must() + _ = result.Must() + .BeEnumerableOf() .BeEqualTo(expected); } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs index ccb6f82cb..d0d3786d0 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs @@ -70,8 +70,9 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source) .ToArray, Wrap.Enumerator, int>(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -120,8 +121,9 @@ public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -170,8 +172,9 @@ public void ToArray_PredicateAt_MemoryPool_With_ValidData_Must_Succeed(int[] sou .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -220,8 +223,9 @@ public void ToArray_Selector_MemoryPool_With_ValidData_Must_Succeed(int[] source .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -270,8 +274,9 @@ public void ToArray_SelectorAt_MemoryPool_With_ValidData_Must_Succeed(int[] sour .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -324,8 +329,9 @@ public void ToArray_Predicate_Selector_MemoryPool_With_ValidData_Must_Succeed(in .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs index 83e80e7a8..c0975ed1b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs @@ -70,8 +70,9 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source) .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -120,8 +121,9 @@ public void ToArray_Predicate_MemoryPool_With_ValidData_Must_Succeed(int[] sourc .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -170,8 +172,9 @@ public void ToArray_SelectorAt_MemoryPool_With_ValidData_Must_Succeed(int[] sour .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } } diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs index dde125896..093e54754 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs @@ -51,8 +51,9 @@ public async ValueTask ToArrayAsync_MemoryPool_Must_Succeed(int[] source) .ConfigureAwait(false); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -103,8 +104,9 @@ public async ValueTask ToArrayAsync_Predicate_MemoryPool_Must_Succeed(int[] sour .ConfigureAwait(false); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -155,8 +157,9 @@ public async ValueTask ToArrayAsync_PredicateAt_MemoryPool_Must_Succeed(int[] so .ConfigureAwait(false); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -207,8 +210,9 @@ public async ValueTask ToArrayAsync_Selector_MemoryPool_Must_Succeed(int[] sourc .ConfigureAwait(false); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -259,8 +263,9 @@ public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] sou .ConfigureAwait(false); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -316,8 +321,9 @@ public async ValueTask ToArrayAsync_Predicate_Selector_MemoryPool_Must_Succeed(i .ConfigureAwait(false); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs index e4c6457ad..4dfb50115 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs @@ -68,7 +68,8 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source .ToArray(ArrayPool.Shared); // Assert - _ = result.Memory.Must() + _ = result.Must() + .BeEnumerableOf() .BeEqualTo(expected); } diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs index 78ebb3e45..1f224ea32 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs @@ -70,8 +70,9 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source .ToArray(pool); // Assert - _ = result.Memory - .SequenceEqual(expected); + _ = result.Must() + .BeEnumerableOf() + .BeEqualTo(expected); } [Theory] diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs index cdacc0d01..67530fdac 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs @@ -68,7 +68,7 @@ public ValueTask ToArrayAsync() => this.ToArrayAsync, AsyncEnumerator, TSource>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => this.ToArrayAsync, AsyncEnumerator, TSource>(pool, cancellationToken, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs index eb69ce185..ea9b2f9c8 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs @@ -83,7 +83,7 @@ public ValueTask ToArrayAsync() => this.ToArrayAsync, TEnumerator, TSource>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => this.ToArrayAsync, TEnumerator, TSource>(pool, cancellationToken, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs index c13bc1e2b..b9af7e02e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs @@ -60,15 +60,15 @@ public TSource[] ToArray() return arrayBuilder.ToArray(); } - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { // ReSharper disable once HeapView.PossibleBoxingAllocation if (source is ICollection collection) { if (collection.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(collection.Count, clearOnDispose); + var result = pool.Lease(collection.Count, clearOnDispose); collection.CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs index 874633921..a8be25625 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs @@ -110,12 +110,12 @@ public TSource[] ToArray() return result; } - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Count, clearOnDispose); + var result = pool.Lease(source.Count, clearOnDispose); CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs index 831cc1dc5..c6646af20 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs @@ -173,12 +173,12 @@ public TSource[] ToArray() return result; } - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Count, clearOnDispose); + var result = pool.Lease(source.Count, clearOnDispose); CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs index f831c3133..ac02b2263 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs @@ -65,15 +65,15 @@ public TSource[] ToArray() return arrayBuilder.ToArray(); } - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { // ReSharper disable once HeapView.PossibleBoxingAllocation if (source is ICollection collection) { if (collection.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(collection.Count, clearOnDispose); + var result = pool.Lease(collection.Count, clearOnDispose); collection.CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs index ca5e33d74..e3eb7ce64 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs @@ -115,12 +115,12 @@ public TSource[] ToArray() return result; } - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Count, clearOnDispose); + var result = pool.Lease(source.Count, clearOnDispose); CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs index e97ffcf52..f735067c5 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs @@ -98,15 +98,15 @@ public readonly TSource[] ToArray() return arrayBuilder.ToArray(); } - public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { // ReSharper disable once HeapView.PossibleBoxingAllocation if (source is ICollection collection) { if (collection.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(collection.Count, clearOnDispose); + var result = pool.Lease(collection.Count, clearOnDispose); collection.CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs index 503890723..d3ca7a55c 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs @@ -149,12 +149,12 @@ public readonly TSource[] ToArray() return result; } - public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Count, clearOnDispose); + var result = pool.Lease(source.Count, clearOnDispose); CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs index 403cbd298..a3d066e5e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs @@ -100,15 +100,15 @@ public TSource[] ToArray() return arrayBuilder.ToArray(); } - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { // ReSharper disable once HeapView.PossibleBoxingAllocation if (source is ICollection collection) { if (collection.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(collection.Count, clearOnDispose); + var result = pool.Lease(collection.Count, clearOnDispose); collection.CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs index 86577bfed..b5c96d2b9 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs @@ -152,12 +152,12 @@ public readonly TSource[] ToArray() return result; } - public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Count, clearOnDispose); + var result = pool.Lease(source.Count, clearOnDispose); CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs index 265b3822a..50a3711f8 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs @@ -197,12 +197,12 @@ public readonly TSource[] ToArray() return result; } - public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { if (source.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Count, clearOnDispose); + var result = pool.Lease(source.Count, clearOnDispose); CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index 66b2d7577..c804277e0 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -83,10 +83,10 @@ public bool Contains(TSource item) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int IndexOf(TSource item) { - var index = System.Array.IndexOf(source.Array!, item, source.Offset, source.Count); - return index >= 0 - ? index - source.Offset - : -1; + var index = Array.IndexOf(source.Array!, item, source.Offset, source.Count); + return index < 0 + ? -1 + : index - source.Offset; } [ExcludeFromCodeCoverage] @@ -161,7 +161,7 @@ public TSource[] ToArray() => source.AsSpan().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.AsSpan().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -196,14 +196,24 @@ public Dictionary ToDictionary ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAt(index); + => index < 0 || index >= source.Count + ? Option.None + : Option.Some(source.Array![source.Offset + index]); public Option First() - => ((ReadOnlySpan)source.AsSpan()).First(); - + => source switch + { + { Count: 0 } => Option.None, + _ => Option.Some(source.Array![source.Offset]) + }; + public Option Single() - => ((ReadOnlySpan)source.AsSpan()).Single(); - + => source switch + { + { Count: 1 } => Option.Some(source.Array![source.Offset]), + _ => Option.None, + }; + #endregion #region Filtering diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs index ca2802efa..0fbef647e 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs @@ -8,7 +8,7 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IMemoryOwner ToArray(this Memory source, ArrayPool pool, bool clearOnDispose = default) + public static Lease ToArray(this Memory source, ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlyMemory)source).Span.ToArray(pool, clearOnDispose); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs index 267ff3a32..5b33812c9 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs @@ -8,7 +8,7 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IMemoryOwner ToArray(this ReadOnlyMemory source, ArrayPool pool, bool clearOnDispose = default) + public static Lease ToArray(this ReadOnlyMemory source, ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArray(pool, clearOnDispose); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index b91c28ede..c7343d194 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -11,12 +11,12 @@ static partial class ArrayExtensions static TSource[] ToArray(this ReadOnlySpan source) => source.ToArray(); - public static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose = default) + public static Lease ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose = default) { if (source.Length is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Length, clearOnDispose); + var result = pool.Lease(source.Length, clearOnDispose); Copy(source, result.Memory.Span); return result; } @@ -35,11 +35,11 @@ static TSource[] ToArray(this ReadOnlySpan source, } [GeneratorIgnore] - static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + static Lease ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { if (source.Length is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate); return arrayBuilder.ToArray(pool, clearOnDispose); @@ -60,11 +60,11 @@ static TSource[] ToArrayAt(this ReadOnlySpan sourc } [GeneratorIgnore] - static IMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + static Lease ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { if (source.Length is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); using var arrayBuilder = ToArrayBuilderAt(source, pool, clearOnDispose, predicate); return arrayBuilder.ToArray(pool, clearOnDispose); @@ -101,28 +101,28 @@ static TResult[] ToArrayVector(thi } [GeneratorIgnore] - static IMemoryOwner ToArrayVector(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TVectorSelector vectorSelector, TSelector selector) + static Lease ToArrayVector(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction where TSource : struct where TResult : struct { if (source.Length is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Length, clearOnDispose); + var result = pool.Lease(source.Length, clearOnDispose); CopyVector(source, result.Memory.Span, vectorSelector, selector); return result; } [GeneratorIgnore] - static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) + static Lease ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { if (source.Length is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Length, clearOnDispose); + var result = pool.Lease(source.Length, clearOnDispose); Copy(source, result.Memory.Span, selector); return result; } @@ -142,13 +142,13 @@ static TResult[] ToArrayAt(this ReadOnlySpan ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) + static Lease ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { if (source.Length is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Length, clearOnDispose); + var result = pool.Lease(source.Length, clearOnDispose); CopyAt(source, result.Memory.Span, selector); return result; } @@ -169,12 +169,12 @@ static TResult[] ToArray(this ReadOnlyS } [GeneratorIgnore] - static IMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) + static Lease ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction { if (source.Length is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose, predicate, selector); return arrayBuilder.ToArray(pool, clearOnDispose); diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs index 1bf2f55f9..204ed3e92 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs @@ -8,7 +8,7 @@ namespace NetFabric.Hyperlinq static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IMemoryOwner ToArray(this Span source, ArrayPool pool, bool clearOnDispose = default) + public static Lease ToArray(this Span source, ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source).ToArray(pool, clearOnDispose); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index 8c4ff0c9c..36108fba9 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -27,7 +27,7 @@ public static TSource[] ToArray(this TEnumera return arrayBuilder.ToArray(); } - public static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) + public static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator { @@ -35,9 +35,9 @@ public static IMemoryOwner ToArray(t if (source is ICollection collection) { if (collection.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(collection.Count, clearOnDispose); + var result = pool.Lease(collection.Count, clearOnDispose); collection.CopyTo(result.Rented, 0); return result; } @@ -60,7 +60,7 @@ internal static TSource[] ToArray } [GeneratorIgnore] - internal static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + internal static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction @@ -83,7 +83,7 @@ internal static TSource[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + internal static Lease ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction @@ -106,7 +106,7 @@ static TResult[] ToArray( } [GeneratorIgnore] - static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -128,7 +128,7 @@ static TResult[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + static Lease ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction @@ -152,7 +152,7 @@ internal static TResult[] ToArray ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) + internal static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index ec1763e77..1a46283c4 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -24,14 +24,14 @@ public static TSource[] ToArray(this TEnumera return result; } - public static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) + public static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator { if (source.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Count, clearOnDispose); + var result = pool.Lease(source.Count, clearOnDispose); // ReSharper disable once HeapView.PossibleBoxingAllocation if (source is ICollection collection) collection.CopyTo(result.Rented, 0); @@ -53,12 +53,12 @@ static TSource[] ToArray(this TEn : ValueEnumerableExtensions.ToArray(source, predicate); [GeneratorIgnore] - static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction => source.Count is 0 - ? EmptyMemoryOwner.Instance + ? Lease.Empty() : ValueEnumerableExtensions.ToArray(source, pool, clearOnDispose, predicate); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -74,12 +74,12 @@ static TSource[] ToArrayAt(this T [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - static IMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) + static Lease ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction => source.Count is 0 - ? EmptyMemoryOwner.Instance + ? Lease.Empty() : ValueEnumerableExtensions.ToArrayAt(source, pool, clearOnDispose, predicate); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -99,15 +99,15 @@ internal static TResult[] ToArray ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + internal static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { if (source.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Count, clearOnDispose); + var result = pool.Lease(source.Count, clearOnDispose); Copy(source, result.Rented, selector); return result; } @@ -130,15 +130,15 @@ internal static TResult[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) + internal static Lease ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSelector : struct, IFunction { if (source.Count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(source.Count, clearOnDispose); + var result = pool.Lease(source.Count, clearOnDispose); CopyAt(source, result.Rented, selector); return result; } @@ -156,13 +156,13 @@ static TResult[] ToArray(source, predicate, selector); [GeneratorIgnore] - static IMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) + static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction where TSelector : struct, IFunction => source.Count is 0 - ? EmptyMemoryOwner.Instance + ? Lease.Empty() : ValueEnumerableExtensions.ToArray(source, pool, clearOnDispose, predicate, selector); } } diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs index 82344d8dc..a062b1ec7 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs @@ -16,7 +16,7 @@ public static async ValueTask ToArrayAsync (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator => (await source.ToArrayBuilderAsync(pool, clearOnDispose, cancellationToken).ConfigureAwait(false)).ToArray(pool, clearOnDispose); @@ -33,7 +33,7 @@ static async ValueTask ToArrayAsync> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) + static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -51,7 +51,7 @@ static async ValueTask ToArrayAtAsync> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) + static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction @@ -69,7 +69,7 @@ static async ValueTask ToArrayAsync> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) + static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -87,7 +87,7 @@ static async ValueTask ToArrayAtAsync> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) + static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TSelector : struct, IAsyncFunction @@ -106,7 +106,7 @@ static async ValueTask ToArrayAsync> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) + static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator where TPredicate : struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index 885346363..a459331c8 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -222,7 +222,7 @@ public TSource[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index 09cae35df..622f4eeca 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -329,7 +329,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAsync(pool, clearOnDispose, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index 2fc450e35..af9464323 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -216,7 +216,7 @@ public Option Single() public TSource[] ToArray() => source.Span.ToArray(predicate); - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArray(pool, clearOnDispose, predicate); public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index 2b19d8283..b587ab670 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -157,7 +157,7 @@ public Option Single() public TSource[] ToArray() => source.ToArray(predicate); - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, predicate); public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index f9ad5835b..42f503c9e 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -135,7 +135,7 @@ public TSource[] ToArray() => source.ToArray(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index e647281d6..a0ec54406 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -225,7 +225,7 @@ public TSource[] ToArray() => ValueReadOnlyCollectionExtensions.ToArray(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index c7aa1cc5d..0c9991022 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -220,7 +220,7 @@ public TSource[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index 6e2dd58ed..cfacfac20 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -322,7 +322,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAtAsync(cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAtAsync(pool, clearOnDispose, cancellationToken, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index 95ce60b76..b5f9d02d4 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -204,7 +204,7 @@ public Option Single() public TSource[] ToArray() => source.Span.ToArrayAt(predicate); - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArrayAt(pool, clearOnDispose, predicate); public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index acc79b256..69b2d3edd 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -147,7 +147,7 @@ public Option Single() public TSource[] ToArray() => source.ToArrayAt(predicate); - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayAt(pool, clearOnDispose, predicate); public List ToList() diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index 72f079f87..9bc9a5b54 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -222,7 +222,7 @@ public TSource[] ToArray() => source.ToArrayAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayAt(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index 7338684f4..52701135b 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -221,7 +221,7 @@ public TSource[] ToArray() => ToArrayAt(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ToArrayAt(source, pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index b79d4bfc1..9b86a712f 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -238,7 +238,7 @@ public TResult[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index 2e9445f69..02d24b5d6 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -357,7 +357,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAsync(cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAsync(pool, clearOnDispose, cancellationToken, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index d451ea01a..883bdc1c2 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -239,7 +239,7 @@ public TResult[] ToArray() => source.Span.ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index 484eb1093..07cfb1f15 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -112,7 +112,7 @@ public TResult[] ToArray() => source.ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index 5853663e9..8a816f47e 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -242,7 +242,7 @@ public TResult[] ToArray() => source.ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index 753e32603..f0f53d467 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -242,7 +242,7 @@ public TResult[] ToArray() => ValueReadOnlyCollectionExtensions.ToArray(source, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs index 4f3b71058..474d2d5a8 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs @@ -187,9 +187,9 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = defau return new ValueTask(array); } - public ValueTask> ToArrayAsync(MemoryPool pool, CancellationToken cancellationToken = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) { - var result = pool.Rent(count); + var result = pool.Lease(count, clearOnDispose); var span = result.Memory.Span; if (start is 0) { @@ -207,7 +207,7 @@ public ValueTask> ToArrayAsync(MemoryPool pool, Cancellat span[index] = index + start; } } - return new ValueTask>(result); + return new ValueTask>(result); } public async ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs index 8f0219275..23713e5fa 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs @@ -180,9 +180,9 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d return new ValueTask(result: array); } - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) { - var result = pool.RentDisposable(count, clearOnDispose); + var result = pool.Lease(count, clearOnDispose); var array = result.Memory.Span; var end = count - 1; for (var index = 0; index <= end; index++) @@ -190,7 +190,7 @@ public ValueTask> ToArrayAsync(ArrayPool pool, Ca cancellationToken.ThrowIfCancellationRequested(); array[index] = value; } - return new ValueTask>(result: result); + return new ValueTask>(result: result); } public async ValueTask> ToListAsync(CancellationToken cancellationToken = default) diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs index 1965d75a9..dbe032359 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs @@ -258,9 +258,9 @@ public int[] ToArray() return array; } - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentDisposable(Count, clearOnDispose); + var result = pool.Lease(Count, clearOnDispose); ArrayExtensions.CopyRange(start, Count, result.Memory.Span); return result; } diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs index ef600c73e..a7ec67e50 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs @@ -183,9 +183,9 @@ public TSource[] ToArray() return array; } - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentDisposable(Count, clearOnDispose); + var result = pool.Lease(Count, clearOnDispose); CopyTo(result.Memory.Span); return result; } @@ -236,10 +236,10 @@ public static TSource[] ToArrayVector(this RepeatEnumerable so return array; } - public static IMemoryOwner ToArrayVector(this RepeatEnumerable source, ArrayPool pool, bool clearOnDispose = default) + public static Lease ToArrayVector(this RepeatEnumerable source, ArrayPool pool, bool clearOnDispose = default) where TSource : struct { - var result = pool.RentDisposable(source.count, clearOnDispose); + var result = pool.Lease(source.count, clearOnDispose); source.CopyToVector(result.Memory.Span); return result; } diff --git a/NetFabric.Hyperlinq/Lease.cs b/NetFabric.Hyperlinq/Lease.cs new file mode 100644 index 000000000..e82e62e89 --- /dev/null +++ b/NetFabric.Hyperlinq/Lease.cs @@ -0,0 +1,214 @@ +using System; +using System.Buffers; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static class Lease + { + static class EmptyLease + { + // ReSharper disable once InconsistentNaming + internal static readonly Lease Value = new(ArrayPool.Shared, 0, default); + } + + public static Lease Empty() + => EmptyLease.Value; + } + + public sealed class Lease + : IMemoryOwner + , IValueEnumerable.DisposableEnumerator> + { + readonly ArrayPool pool; + readonly bool clearOnDispose; + T[]? rented; + int length; + + internal Lease(ArrayPool pool, int length, bool clearOnDispose) + { + Debug.Assert(length >= 0); + + this.pool = pool; + this.length = length; + this.clearOnDispose = clearOnDispose; + rented = length is 0 + ? Array.Empty() + : this.pool.Rent(length); + } + + /// + /// Gets or sets the length of memory to be used. + /// + public int Length + { + get => length; + set + { + var array = rented; + if (array is null) + Throw.ObjectDisposedException(nameof(Lease)); + if (value < 0 || value > array.Length) + Throw.ArgumentOutOfRangeException(nameof(value)); + + length = value; + } + } + + /// + /// Gets all the memory rented. + /// + public T[] Rented + { + get + { + var array = rented; + if (array is null) + Throw.ObjectDisposedException(nameof(Lease)); + return array; + } + } + + /// + /// Gets the slice of memory to be used. + /// + public Memory Memory + { + get + { + var array = rented; + if (array is null) + Throw.ObjectDisposedException(nameof(Lease)); + return array.AsMemory(0, length); + } + } + + /// + /// Gets the slice of memory that is rented but not used. + /// + public Memory Remaining + { + get + { + var array = rented; + if (array is null) + Throw.ObjectDisposedException(nameof(Lease)); + return array.AsMemory(length); + } + } + + public void Dispose() + { + if (length is 0) + return; // do not dispose empty + + var array = rented; + if (array is null) + return; // it's already disposed + + rented = null; + pool.Return(array, clearOnDispose); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() + { + var array = rented; + if (array is null) + Throw.ObjectDisposedException(nameof(Lease)); + return new Enumerator(array, length); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + DisposableEnumerator IValueEnumerable.GetEnumerator() + => GetDisposableEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => GetDisposableEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => GetDisposableEnumerator(); + + DisposableEnumerator GetDisposableEnumerator() + { + var array = rented; + if (array is null) + Throw.ObjectDisposedException(nameof(Lease)); + return new DisposableEnumerator(array, length); + } + + public struct Enumerator + { + readonly T[] source; + readonly int length; + int index; + + internal Enumerator(T[] source, int length) + { + this.source = source; + this.length = length; + index = -1; + } + + public readonly T Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index < length; + } + + public struct DisposableEnumerator + : IEnumerator + { + readonly T[] source; + readonly int length; + int index; + + internal DisposableEnumerator(T[] source, int length) + { + this.source = source; + this.length = length; + index = -1; + } + + public readonly T Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source[index]; + } + + readonly object? IEnumerator.Current + // ReSharper disable once HeapView.PossibleBoxingAllocation + => source[index]; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index < length; + + public void Reset() + => index = -1; + + public readonly void Dispose() + { } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ArrayExtensions.ArraySegmentValueEnumerable AsValueEnumerable() + => rented is null + ? Throw.ObjectDisposedException>(nameof(Lease)) + : new ArraySegment(rented, 0, length).AsValueEnumerable(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IEnumerable AsEnumerable() + => this; + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index d48e1ce3e..d5cc8a071 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -213,7 +213,7 @@ public TResult[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs index ff31c1eeb..49d3d76a7 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -258,7 +258,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAsync(pool, cancellationToken, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index a06ab0715..b62a3715c 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -206,7 +206,7 @@ public TResult[] ToArray() => source.Span.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArray(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index 09432715e..7c3bae6fa 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -101,7 +101,7 @@ public TResult[] ToArray() => source.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index 62c3351d9..868a3013e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -160,7 +160,7 @@ public TResult[] ToArray() => source.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index cd9459c52..03ae3ac84 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -195,7 +195,7 @@ public TResult[] ToArray() => ValueReadOnlyCollectionExtensions.ToArray(source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs index 8fe332388..67ee2408c 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -221,7 +221,7 @@ public readonly TResult[] ToArray() => source.ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArray(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 5ae7e692d..a2532139a 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -204,7 +204,7 @@ public TResult[] ToArray() => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index 67f51cc94..f299225a0 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -260,7 +260,7 @@ public ValueTask ToArrayAsync(CancellationToken cancellationToken = d => source.ToArrayAtAsync(cancellationToken, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) + public ValueTask> ToArrayAsync(ArrayPool pool, CancellationToken cancellationToken = default, bool clearOnDispose = default) => source.ToArrayAtAsync(pool, cancellationToken, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 42867bc67..74f31826f 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -198,7 +198,7 @@ public TResult[] ToArray() => source.Span.ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.Span.ToArrayAt(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index c075f7256..dc30405c3 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -101,7 +101,7 @@ public TResult[] ToArray() => source.ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayAt(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index b26243b60..524d6dc67 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -170,7 +170,7 @@ public TResult[] ToArray() => source.ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayAt(pool, clearOnDispose, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index 04ba9313e..cfd0e6ca8 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -204,7 +204,7 @@ public TResult[] ToArray() => ToArrayAt(source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ToArrayAt(source, pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs index c610c62cf..6c8435ce8 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -237,7 +237,7 @@ public readonly TResult[] ToArray() => ValueReadOnlyCollectionExtensions.ToArrayAt(source, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => ValueReadOnlyCollectionExtensions.ToArrayAt(source, pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs index c14c0b4e6..db1b3deda 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs @@ -86,9 +86,9 @@ public TResult[] ToArray() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) { - var result = pool.RentDisposable(count, clearOnDispose); + var result = pool.Lease(count, clearOnDispose); ArrayExtensions.CopyRange(start, count, result.Memory.Span, vectorSelector, selector); return result; } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs index 9fb0254ef..a3a7aee03 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs @@ -88,7 +88,7 @@ public TResult[] ToArray() => source.ToArrayVector(vectorSelector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => source.ToArrayVector(pool, clearOnDispose, vectorSelector, selector); public List ToList() diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs index 60756419b..b3fa0878a 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs @@ -130,7 +130,7 @@ public TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs index 1aa0ab518..0c07e13c3 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs @@ -222,7 +222,7 @@ public async ValueTask ToArrayAsync(CancellationToken cancellationTok => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public async ValueTask> ToArrayAsync(ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken = default) + public async ValueTask> ToArrayAsync(ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken = default) => (await FillSetAsync(cancellationToken).ConfigureAwait(false)).ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs index 752b15a79..d028c5864 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -132,7 +132,7 @@ public TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs index 8f376df77..26611f41d 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs @@ -96,7 +96,7 @@ public TSource[] ToArray() }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs index 269e97125..ca155917e 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs @@ -116,7 +116,7 @@ public TSource[] ToArray() => GetSet().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) + public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) => GetSet().ToArray(pool, clearOnDispose); [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq/Set/Distinct/Set.cs index 79243e1ef..7a1b2805b 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Set.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Set.cs @@ -170,9 +170,9 @@ public readonly TElement[] ToArray() return array; } - public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) + public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose) { - var result = pool.RentDisposable(Count, clearOnDispose); + var result = pool.Lease(Count, clearOnDispose); CopyTo(result.Memory.Span); return result; } diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs index bb119f262..ebe162eba 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs @@ -136,12 +136,12 @@ public readonly T[] ToArray() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly IMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose) + public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose) { if (count is 0) - return EmptyMemoryOwner.Instance; + return Lease.Empty(); - var result = pool.RentDisposable(count, clearOnDispose); + var result = pool.Lease(count, clearOnDispose); CopyTo(result.Rented, 0); return result; } diff --git a/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs b/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs index bf86446f1..357419a8c 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs @@ -7,68 +7,7 @@ namespace NetFabric.Hyperlinq static class ArrayPoolExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static MemoryOwner RentDisposable(this ArrayPool pool, int length, bool clearOnDispose) + public static Lease Lease(this ArrayPool pool, int length, bool clearOnDispose) => new(pool, length, clearOnDispose); } - - class MemoryOwner - : IMemoryOwner - { - readonly ArrayPool pool; - readonly int length; - readonly bool clearOnDispose; - T[]? rented; - - internal MemoryOwner(ArrayPool pool, int length, bool clearOnDispose) - { - this.pool = pool; - this.length = length; - this.clearOnDispose = clearOnDispose; - rented = this.pool.Rent(length); - } - - public T[] Rented - { - get - { - var array = rented; - if (array is null) - Throw.ObjectDisposedException(nameof(MemoryOwner)); - return array; - } - } - - public Memory Memory - { - get - { - var array = rented; - if (array is null) - Throw.ObjectDisposedException(nameof(MemoryOwner)); - return new Memory(array, 0, length); - } - } - - public void Dispose() - { - var array = rented; - if (array is not null) - { - rented = null; - pool.Return(array, clearOnDispose); - } - } - } - - class EmptyMemoryOwner - : IMemoryOwner - { - public static EmptyMemoryOwner Instance => new(); - - private EmptyMemoryOwner() { } - - public Memory Memory => Memory.Empty; - - public void Dispose() { } - } } diff --git a/README.md b/README.md index 6888bf44f..0709d4fb2 100644 --- a/README.md +++ b/README.md @@ -290,23 +290,23 @@ source.AsValueEnumerable() ### Buffer pools -[Buffer pools](https://adamsitnik.com/Array-Pool/) allow the use of heap memory without adding pressure to the garbage collector. It preallocates a chunk of memory and "rents" it as required. The garbage collector will add this memory to the Large Object Heap (LOH). +[Buffer pools](https://adamsitnik.com/Array-Pool/) allow the use of heap memory without adding pressure to the garbage collector. It pre-allocates a chunk of memory and "rents" it as required. The garbage collector will add this memory to the Large Object Heap (LOH). `ToArray()` is frequently used to cache values for a brief period and the use of buffer pools may be useful. -`Netfabric.Hyperlinq` adds an overload that takes a `MemoryPool<>` as a parameter: +`Netfabric.Hyperlinq` adds an overload that takes a `ArrayPool<>` as a parameter: ``` csharp void Method() { using var buffer = source.AsValueEnumerable() - .ToArray(MemoryPool.Shared); + .ToArray(ArrayPool.Shared); var memory = buffer.Memory; // use memory here } ``` -It returns an [`IMemoryOwner<>`](https://docs.microsoft.com/en-us/dotnet/api/system.buffers.imemoryowner-1). The `using` statement guarantees that it is disposed and the buffer automatically returned to the pool. +It returns an instance of a [`IMemoryOwner<>`](https://docs.microsoft.com/en-us/dotnet/api/system.buffers.imemoryowner-1). The `using` statement guarantees that it is disposed and the buffer automatically returned to the pool. ### SIMD From 5eee3179d8d8fa3ec2f651b0254cfc0fe9d6d374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Sat, 11 Sep 2021 23:44:10 +0100 Subject: [PATCH 49/61] Fix SingleAsync() (#381) * Fix SingleAsync() * Fix Repeat() test --- .../CountAsync.AsyncValueEnumerable.Tests.cs | 6 +-- .../SumAsync.AsyncValueEnumerable.Tests.cs | 8 ++-- ...ValueEnumerable'1.AsyncEnumerable.Tests.cs | 2 +- ...Enumerable'1.AsyncValueEnumerable.Tests.cs | 2 +- ...ValueEnumerable'6.AsyncEnumerable.Tests.cs | 2 +- ...Enumerable'6.AsyncValueEnumerable.Tests.cs | 2 +- ...ToArrayAsync.AsyncValueEnumerable.Tests.cs | 24 +++++----- .../ToListAsync.AsyncValueEnumerable.Tests.cs | 12 ++--- ...ementAtAsync.AsyncValueEnumerable.Tests.cs | 12 ++--- .../FirstAsync.AsyncValueEnumerable.Tests.cs | 12 ++--- .../SingleAsync.AsyncValueEnumerable.Tests.cs | 48 +++++++++---------- .../Where/Where.AsyncValueEnumerable.Tests.cs | 2 +- .../WhereAt.AsyncValueEnumerable.Tests.cs | 2 +- .../WhereSelect.AsyncValueEnumerable.Tests.cs | 2 +- .../AsyncValueEnumerable/Range.Tests.cs | 8 ++-- .../AsyncValueEnumerable/Repeat.Tests.cs | 12 ++--- .../Generation/Repeat.TestData.cs | 7 ++- .../Select.AsyncValueEnumerable.Tests.cs | 2 +- .../SelectAt.AsyncValueEnumerable.Tests.cs | 2 +- .../All/All.AsyncValueEnumerable.Tests.cs | 4 +- .../Any/Any.AsyncValueEnumerable.Tests.cs | 6 +-- .../Contains.AsyncValueEnumerable.Tests.cs | 16 +++---- .../Distinct.AsyncValueEnumerable.Tests.cs | 8 ++-- .../SingleAsync.AsyncValueEnumerable.cs | 15 +++--- .../Generation/AsyncValueEnumerable/Repeat.cs | 19 ++++---- .../Generation/ValueEnumerable/Repeat.cs | 5 +- 26 files changed, 118 insertions(+), 122 deletions(-) diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs index 28ae22077..b0df41458 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs @@ -12,7 +12,7 @@ public class AsyncValueEnumerableTests [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask CountAsync_With_ValidData_Must_Succeed(int[] source) + public async Task CountAsync_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap @@ -34,7 +34,7 @@ public async ValueTask CountAsync_With_ValidData_Must_Succeed(int[] source) [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public async ValueTask CountAsync_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task CountAsync_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -57,7 +57,7 @@ public async ValueTask CountAsync_Predicate_With_ValidData_Must_Succeed(int[] so [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public async ValueTask CountAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task CountAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs index 51065d9cb..b6ca37841 100644 --- a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs @@ -10,7 +10,7 @@ public class AsyncValueEnumerableTests { [Theory] [MemberData(nameof(TestData.SumDouble), MemberType = typeof(TestData))] - public async ValueTask SumAsync_With_Double_Must_Succeed(double[] source) + public async Task SumAsync_With_Double_Must_Succeed(double[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -29,7 +29,7 @@ public async ValueTask SumAsync_With_Double_Must_Succeed(double[] source) [Theory] [MemberData(nameof(TestData.SumNullableDouble), MemberType = typeof(TestData))] - public async ValueTask SumAsync_With_NullableDouble_Must_Succeed(double?[] source) + public async Task SumAsync_With_NullableDouble_Must_Succeed(double?[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -48,7 +48,7 @@ public async ValueTask SumAsync_With_NullableDouble_Must_Succeed(double?[] sourc [Theory] [MemberData(nameof(TestData.SumDecimal), MemberType = typeof(TestData))] - public async ValueTask SumAsync_With_Decimal_Must_Succeed(decimal[] source) + public async Task SumAsync_With_Decimal_Must_Succeed(decimal[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -67,7 +67,7 @@ public async ValueTask SumAsync_With_Decimal_Must_Succeed(decimal[] source) [Theory] [MemberData(nameof(TestData.SumNullableDecimal), MemberType = typeof(TestData))] - public async ValueTask SumAsync_With_NullableDecimal_Must_Succeed(decimal?[] source) + public async Task SumAsync_With_NullableDecimal_Must_Succeed(decimal?[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs index 1842f64dc..fa4d93c24 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs @@ -34,7 +34,7 @@ public void AsAsyncValueEnumerable1_With_ValidData_Must_Succeed(int[] source) [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source) + public async Task AsAsyncValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs index 12a3a8b9d..13562a3fc 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs @@ -34,7 +34,7 @@ public void AsAsyncValueEnumerable1_With_ValidData_Must_Succeed(int[] source) [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source) + public async Task AsAsyncValueEnumerable1_Sum_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs index 5311a6b0f..69a6bdbef 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs @@ -58,7 +58,7 @@ public void AsAsyncValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[ [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) + public async Task AsAsyncValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs index 5363407bc..7d1f42958 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs @@ -59,7 +59,7 @@ public void AsAsyncValueEnumerable6_Enumerator2_With_ValidData_Must_Succeed(int[ [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AsAsyncValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) + public async Task AsAsyncValueEnumerable6_Sum_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs index 093e54754..e7cf9ee18 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs @@ -13,7 +13,7 @@ public class AsyncValueEnumerableTests [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_With_ValidData_Must_Succeed(int[] source) + public async Task ToArrayAsync_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap @@ -36,7 +36,7 @@ public async ValueTask ToArrayAsync_With_ValidData_Must_Succeed(int[] source) [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_MemoryPool_Must_Succeed(int[] source) + public async Task ToArrayAsync_MemoryPool_Must_Succeed(int[] source) { // Arrange var pool = ArrayPool.Shared; @@ -62,7 +62,7 @@ public async ValueTask ToArrayAsync_MemoryPool_Must_Succeed(int[] source) [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task ToArrayAsync_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -87,7 +87,7 @@ public async ValueTask ToArrayAsync_Predicate_With_ValidData_Must_Succeed(int[] [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_Predicate_MemoryPool_Must_Succeed(int[] source, Func predicate) + public async Task ToArrayAsync_Predicate_MemoryPool_Must_Succeed(int[] source, Func predicate) { // Arrange var pool = ArrayPool.Shared; @@ -115,7 +115,7 @@ public async ValueTask ToArrayAsync_Predicate_MemoryPool_Must_Succeed(int[] sour [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task ToArrayAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -140,7 +140,7 @@ public async ValueTask ToArrayAsync_PredicateAt_With_ValidData_Must_Succeed(int[ [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func predicate) + public async Task ToArrayAsync_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func predicate) { // Arrange var pool = ArrayPool.Shared; @@ -168,7 +168,7 @@ public async ValueTask ToArrayAsync_PredicateAt_MemoryPool_Must_Succeed(int[] so [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] source, Func selector) + public async Task ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange var wrapped = Wrap @@ -193,7 +193,7 @@ public async ValueTask ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] s [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_Selector_MemoryPool_Must_Succeed(int[] source, Func selector) + public async Task ToArrayAsync_Selector_MemoryPool_Must_Succeed(int[] source, Func selector) { // Arrange var pool = ArrayPool.Shared; @@ -221,7 +221,7 @@ public async ValueTask ToArrayAsync_Selector_MemoryPool_Must_Succeed(int[] sourc [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func selector) + public async Task ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange var wrapped = Wrap @@ -246,7 +246,7 @@ public async ValueTask ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[] [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func selector) + public async Task ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func selector) { // Arrange var pool = ArrayPool.Shared; @@ -275,7 +275,7 @@ public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] sou [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) + public async Task ToArrayAsync_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange var wrapped = Wrap @@ -302,7 +302,7 @@ public async ValueTask ToArrayAsync_Predicate_Selector_With_ValidData_Must_Succe [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask ToArrayAsync_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Func predicate, Func selector) + public async Task ToArrayAsync_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange var pool = ArrayPool.Shared; diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs index 9a73611ed..921eaca63 100644 --- a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs @@ -13,7 +13,7 @@ public class AsyncValueEnumerableTests [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ToListAsync_With_ValidData_Must_Succeed(int[] source) + public async Task ToListAsync_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap @@ -37,7 +37,7 @@ public async ValueTask ToListAsync_With_ValidData_Must_Succeed(int[] source) [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public async ValueTask ToListAsync_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task ToListAsync_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -63,7 +63,7 @@ public async ValueTask ToListAsync_Predicate_With_ValidData_Must_Succeed(int[] s [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public async ValueTask ToListAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task ToListAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -89,7 +89,7 @@ public async ValueTask ToListAsync_PredicateAt_With_ValidData_Must_Succeed(int[] [MemberData(nameof(TestData.SelectorEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask ToListAsync_Selector_With_ValidData_Must_Succeed(int[] source, Func selector) + public async Task ToListAsync_Selector_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange var wrapped = Wrap @@ -115,7 +115,7 @@ public async ValueTask ToListAsync_Selector_With_ValidData_Must_Succeed(int[] so [MemberData(nameof(TestData.SelectorAtEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public async ValueTask ToListAsync_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func selector) + public async Task ToListAsync_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func selector) { // Arrange var wrapped = Wrap @@ -142,7 +142,7 @@ public async ValueTask ToListAsync_SelectorAt_With_ValidData_Must_Succeed(int[] [MemberData(nameof(TestData.PredicateSelectorEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask ToListAsync_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) + public async Task ToListAsync_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Func predicate, Func selector) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs index 4b32ac9b8..11dd52718 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs @@ -38,7 +38,7 @@ public async void ElementAtAsync_With_OutOfRange_Must_Return_None(int[] source) [Theory] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ElementAtAsync_With_ValidData_Must_Return_Some(int[] source) + public async Task ElementAtAsync_With_ValidData_Must_Return_Some(int[] source) { var wrapped = Wrap .AsAsyncValueEnumerable(source); @@ -92,7 +92,7 @@ public async void ElementAtAsync_Predicate_With_OutOfRange_Must_Return_None(int[ [Theory] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public async ValueTask ElementAtAsync_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) + public async Task ElementAtAsync_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -148,7 +148,7 @@ public async void ElementAtAsync_PredicateAt_With_OutOfRange_Must_Return_None(in [Theory] [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public async ValueTask ElementAtAsync_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) + public async Task ElementAtAsync_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -203,7 +203,7 @@ public async void ElementAtAsync_Selector_With_OutOfRange_Must_Return_None(int[] [Theory] [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask ElementAtAsync_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) + public async Task ElementAtAsync_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -258,7 +258,7 @@ public async void ElementAtAsync_SelectorAt_With_OutOfRange_Must_Return_None(int [Theory] [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public async ValueTask ElementAtAsync_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) + public async Task ElementAtAsync_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) { // Arrange var wrapped = Wrap @@ -316,7 +316,7 @@ public async void ElementAtAsync_Predicate_Selector_With_OutOfRange_Must_Return_ [Theory] [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask ElementAtAsync_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) + public async Task ElementAtAsync_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs index e2fa58c69..dfd6668a8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs @@ -30,7 +30,7 @@ public async void FirstAsync_With_Empty_Must_Return_None(int[] source) [Theory] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask FirstAsync_With_ValidData_Must_Return_Some(int[] source) + public async Task FirstAsync_With_ValidData_Must_Return_Some(int[] source) { // Arrange var wrapped = Wrap @@ -72,7 +72,7 @@ public async void FirstAsync_Predicate_With_Empty_Must_Return_None(int[] source, [Theory] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public async ValueTask FirstAsync_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) + public async Task FirstAsync_Predicate_With_ValidData_Must_Return_Some(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -115,7 +115,7 @@ public async void FirstAsync_PredicateAt_With_Empty_Must_Return_None(int[] sourc [Theory] [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public async ValueTask FirstAsync_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) + public async Task FirstAsync_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -159,7 +159,7 @@ public async void FirstAsync_Selector_With_Empty_Must_Return_None(int[] source, [Theory] [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask FirstAsync_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) + public async Task FirstAsync_Selector_With_ValidData_Must_Return_Some(int[] source, Func selector) { // Arrange var wrapped = Wrap @@ -203,7 +203,7 @@ public async void FirstAsync_SelectorAt_With_Empty_Must_Return_None(int[] source [Theory] [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.SelectorAtMultiple), MemberType = typeof(TestData))] - public async ValueTask FirstAsync_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) + public async Task FirstAsync_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func selector) { // Arrange var wrapped = Wrap @@ -248,7 +248,7 @@ public async void FirstAsync_Predicate_Selector_With_Empty_Must_Return_None(int[ [Theory] [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSelectorMultiple), MemberType = typeof(TestData))] - public async ValueTask FirstAsync_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) + public async Task FirstAsync_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func predicate, Func selector) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs index 62ecc075b..060688d0c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs @@ -29,7 +29,7 @@ public async void SingleAsync_With_Empty_Must_Return_None(int[] source) [Theory] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] - public async ValueTask SingleAsync_With_SingleAsync_Must_Return_Some(int[] source) + public async Task SingleAsync_With_Single_Must_Return_Some(int[] source) { // Arrange var wrapped = Wrap @@ -43,9 +43,9 @@ public async ValueTask SingleAsync_With_SingleAsync_Must_Return_Some(int[] sourc .ConfigureAwait(false); // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsSome && option.Value == expected); } [Theory] @@ -89,7 +89,7 @@ public async void SingleAsync_Predicate_With_Empty_Must_Return_None(int[] source [Theory] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] - public async ValueTask SingleAsync_Predicate_With_SingleAsync_Must_Return_Some(int[] source, Func predicate) + public async Task SingleAsync_Predicate_With_SingleAsync_Must_Return_Some(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -104,9 +104,9 @@ public async ValueTask SingleAsync_Predicate_With_SingleAsync_Must_Return_Some(i .ConfigureAwait(false); // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsSome && option.Value == expected); } [Theory] @@ -151,7 +151,7 @@ public async void SingleAsync_PredicateAt_With_Empty_Must_Return_None(int[] sour [Theory] [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] - public async ValueTask SingleAsync_PredicateAt_With_SingleAsync_Must_Return_Some(int[] source, Func predicate) + public async Task SingleAsync_PredicateAt_With_SingleAsync_Must_Return_Some(int[] source, Func predicate) { // Arrange var wrapped = Wrap @@ -167,9 +167,9 @@ public async ValueTask SingleAsync_PredicateAt_With_SingleAsync_Must_Return_Some .ConfigureAwait(false); // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsSome && option.Value == expected); } [Theory] @@ -214,7 +214,7 @@ public async void SingleAsync_Selector_With_Empty_Must_Return_None(int[] source, [Theory] [MemberData(nameof(TestData.SelectorSingle), MemberType = typeof(TestData))] - public async ValueTask SingleAsync_Selector_With_SingleAsync_Must_Return_Some(int[] source, Func selector) + public async Task SingleAsync_Selector_With_SingleAsync_Must_Return_Some(int[] source, Func selector) { // Arrange var wrapped = Wrap @@ -230,9 +230,9 @@ public async ValueTask SingleAsync_Selector_With_SingleAsync_Must_Return_Some(in .ConfigureAwait(false); // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsSome && option.Value == expected); } [Theory] @@ -277,7 +277,7 @@ public async void SingleAsync_SelectorAt_With_Empty_Must_Return_None(int[] sourc [Theory] [MemberData(nameof(TestData.SelectorAtSingle), MemberType = typeof(TestData))] - public async ValueTask SingleAsync_SelectorAt_With_SingleAsync_Must_Return_Some(int[] source, Func selector) + public async Task SingleAsync_SelectorAt_With_SingleAsync_Must_Return_Some(int[] source, Func selector) { // Arrange var wrapped = Wrap @@ -293,9 +293,9 @@ public async ValueTask SingleAsync_SelectorAt_With_SingleAsync_Must_Return_Some( .ConfigureAwait(false); // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsSome && option.Value == expected); } [Theory] @@ -341,7 +341,7 @@ public async void SingleAsync_Predicate_Selector_With_Empty_Must_Return_None(int [Theory] [MemberData(nameof(TestData.PredicateSelectorSingle), MemberType = typeof(TestData))] - public async ValueTask SingleAsync_Predicate_Selector_With_SingleAsync_Must_Return_Some(int[] source, Func predicate, Func selector) + public async Task SingleAsync_Predicate_Selector_With_SingleAsync_Must_Return_Some(int[] source, Func predicate, Func selector) { // Arrange var wrapped = Wrap @@ -359,9 +359,9 @@ public async ValueTask SingleAsync_Predicate_Selector_With_SingleAsync_Must_Retu .ConfigureAwait(false); // Assert - _ = result.Match( - value => value.Must().BeEqualTo(expected), - () => throw new Exception()); + _ = result.Must() + .BeOfType>() + .EvaluateTrue(option => option.IsSome && option.Value == expected); } [Theory] diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs index 49ea28526..b6c21f4e4 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs @@ -34,7 +34,7 @@ public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task Where_Sum_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs index 294eeeacf..3ac5990bf 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs @@ -34,7 +34,7 @@ public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task Where_Sum_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs index 6c86e1f31..859a55079 100644 --- a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs @@ -35,7 +35,7 @@ public void WhereSelect_Predicate_With_ValidData_Must_Succeed(int[] source, Func [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public async ValueTask WhereSelect_Sum_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task WhereSelect_Sum_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs index 3f6622a06..2b4dde9bc 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs @@ -74,7 +74,7 @@ public void Range_Take_With_ValidData_Must_Succeed(int start, int count, int tak [Theory] [MemberData(nameof(TestData.Range), MemberType = typeof(TestData))] - public async ValueTask Range_AnyAsync_With_ValidData_Must_Succeed(int start, int count) + public async Task Range_AnyAsync_With_ValidData_Must_Succeed(int start, int count) { // Arrange var expected = Enumerable.Any(Enumerable.Range(start, count)); @@ -91,7 +91,7 @@ public async ValueTask Range_AnyAsync_With_ValidData_Must_Succeed(int start, int [Theory] [MemberData(nameof(TestData.Range_Contains), MemberType = typeof(TestData))] - public async ValueTask Range_ContainsAsync_With_ValidData_Must_Succeed(int start, int count, int value) + public async Task Range_ContainsAsync_With_ValidData_Must_Succeed(int start, int count, int value) { // Arrange var expected = Enumerable.Contains(Enumerable.Range(start, count), value); @@ -109,7 +109,7 @@ public async ValueTask Range_ContainsAsync_With_ValidData_Must_Succeed(int start [Theory] [MemberData(nameof(TestData.Range), MemberType = typeof(TestData))] - public async ValueTask Range_ToArray_With_ValidData_Must_Succeed(int start, int count) + public async Task Range_ToArray_With_ValidData_Must_Succeed(int start, int count) { // Arrange var expected = Enumerable.ToArray(Enumerable.Range(start, count)); @@ -128,7 +128,7 @@ public async ValueTask Range_ToArray_With_ValidData_Must_Succeed(int start, int [Theory] [MemberData(nameof(TestData.Range), MemberType = typeof(TestData))] - public async ValueTask Range_With_ToList_Must_Succeed(int start, int count) + public async Task Range_With_ToList_Must_Succeed(int start, int count) { // Arrange var expected = Enumerable.ToList(Enumerable.Range(start, count)); diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs index e5e2c35b5..8353dacbf 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs @@ -75,7 +75,7 @@ public void Repeat_Take_With_ValidData_Must_Succeed(int value, int count, int ta [Theory] [MemberData(nameof(TestData.Repeat), MemberType = typeof(TestData))] - public async ValueTask Repeat_All_With_ValidData_Must_Succeed(int value, int count) + public async Task Repeat_All_With_ValidData_Must_Succeed(int value, int count) { // Arrange var expected = Enumerable.Repeat(value, count).All(item => false); @@ -93,7 +93,7 @@ public async ValueTask Repeat_All_With_ValidData_Must_Succeed(int value, int cou [Theory] [MemberData(nameof(TestData.Repeat), MemberType = typeof(TestData))] - public async ValueTask Repeat_Any_With_ValidData_Must_Succeed(int value, int count) + public async Task Repeat_Any_With_ValidData_Must_Succeed(int value, int count) { // Arrange var expected = Enumerable.Repeat(value, count).Any(); @@ -111,7 +111,7 @@ public async ValueTask Repeat_Any_With_ValidData_Must_Succeed(int value, int cou [Theory] [MemberData(nameof(TestData.Repeat), MemberType = typeof(TestData))] - public async ValueTask Repeat_ToArray_With_ValidData_Must_Succeed(int value, int count) + public async Task Repeat_ToArray_With_ValidData_Must_Succeed(int value, int count) { // Arrange var expected = Enumerable.Repeat(value, count).ToArray(); @@ -130,7 +130,7 @@ public async ValueTask Repeat_ToArray_With_ValidData_Must_Succeed(int value, int [Theory] [MemberData(nameof(TestData.Repeat), MemberType = typeof(TestData))] - public async ValueTask Repeat_ToList_With_ValidData_Must_Succeed(int value, int count) + public async Task Repeat_ToList_With_ValidData_Must_Succeed(int value, int count) { // Arrange var expected = Enumerable.Repeat(value, count).ToList(); @@ -143,9 +143,7 @@ public async ValueTask Repeat_ToList_With_ValidData_Must_Succeed(int value, int // Assert _ = result.Must() - .BeOfType>() - .BeAsyncEnumerableOf() - .BeEqualTo(expected); + .EvaluateTrue(list => list.SequenceEqual(expected)); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs b/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs index a625b1626..2208d8cf8 100644 --- a/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs +++ b/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs @@ -8,10 +8,9 @@ public static partial class TestData public static TheoryData Repeat => new() { - { 0, 0 }, - { 0, 1 }, - { 0, 5 }, - { 5, 5 } + { 1, 0 }, + { 1, 1 }, + { 1, 5 }, }; public static TheoryData Repeat_SkipTake => diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs index acd451929..402ef5f75 100644 --- a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs @@ -33,7 +33,7 @@ public void Select_Selector_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task AllAsync_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -33,7 +33,7 @@ public async ValueTask AllAsync_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task AllAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs index 99ce22f97..8e3e150d3 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs @@ -12,7 +12,7 @@ public class AsyncValueEnumerableTests [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask AnyAsync_With_ValidData_Must_Succeed(int[] source) + public async Task AnyAsync_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -33,7 +33,7 @@ public async ValueTask AnyAsync_With_ValidData_Must_Succeed(int[] source) [MemberData(nameof(TestData.PredicateEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateMultiple), MemberType = typeof(TestData))] - public async ValueTask AnyAsync_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task AnyAsync_Predicate_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -54,7 +54,7 @@ public async ValueTask AnyAsync_Predicate_With_ValidData_Must_Succeed(int[] sour [MemberData(nameof(TestData.PredicateAtEmpty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtSingle), MemberType = typeof(TestData))] [MemberData(nameof(TestData.PredicateAtMultiple), MemberType = typeof(TestData))] - public async ValueTask AnyAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) + public async Task AnyAsync_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func predicate) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs index a376e4705..441ac2da5 100644 --- a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs @@ -12,7 +12,7 @@ public class AsyncValueEnumerableTests [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ContainsAsync_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) + public async Task ContainsAsync_ValueType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange const int value = int.MaxValue; @@ -32,7 +32,7 @@ public async ValueTask ContainsAsync_ValueType_With_Null_And_NotContains_Must_Re [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ContainsAsync_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) + public async Task ContainsAsync_ReferenceType_With_Null_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange const string? value = default; @@ -51,7 +51,7 @@ public async ValueTask ContainsAsync_ReferenceType_With_Null_And_NotContains_Mus [Theory] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ContainsAsync_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) + public async Task ContainsAsync_ValueType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange var value = source @@ -71,7 +71,7 @@ public async ValueTask ContainsAsync_ValueType_With_Null_And_Contains_Must_Retur [Theory] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ContainsAsync_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) + public async Task ContainsAsync_ReferenceType_With_Null_And_Contains_Must_ReturnTrue(int[] source) { // Arrange var value = source @@ -93,7 +93,7 @@ public async ValueTask ContainsAsync_ReferenceType_With_Null_And_Contains_Must_R [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ContainsAsync_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) + public async Task ContainsAsync_With_DefaultComparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange const int value = int.MaxValue; @@ -112,7 +112,7 @@ public async ValueTask ContainsAsync_With_DefaultComparer_And_NotContains_Must_R [Theory] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ContainsAsync_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) + public async Task ContainsAsync_With_DefaultComparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange var value = source @@ -134,7 +134,7 @@ public async ValueTask ContainsAsync_With_DefaultComparer_And_Contains_Must_Retu [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ContainsAsync_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) + public async Task ContainsAsync_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source) { // Arrange const int value = int.MaxValue; @@ -156,7 +156,7 @@ public async ValueTask ContainsAsync_With_Comparer_And_NotContains_Must_ReturnFa [Theory] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask ContainsAsync_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) + public async Task ContainsAsync_With_Comparer_And_Contains_Must_ReturnTrue(int[] source) { // Arrange var value = source diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs index 25a111f94..5617efc0b 100644 --- a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs +++ b/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs @@ -33,7 +33,7 @@ public void Distinct_With_ValidData_Must_Succeed(int[] source) [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask Distinct_ToArrayAsync_With_ValidData_Must_Succeed(int[] source) + public async Task Distinct_ToArrayAsync_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -57,7 +57,7 @@ public async ValueTask Distinct_ToArrayAsync_With_ValidData_Must_Succeed(int[] s [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask Distinct_ToArrayAsync_MemoryPool_With_ValidData_Must_Succeed(int[] source) + public async Task Distinct_ToArrayAsync_MemoryPool_With_ValidData_Must_Succeed(int[] source) { // Arrange var pool = ArrayPool.Shared; @@ -81,7 +81,7 @@ public async ValueTask Distinct_ToArrayAsync_MemoryPool_With_ValidData_Must_Succ [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask Distinct_ToListAsync_With_ValidData_Must_Succeed(int[] source) + public async Task Distinct_ToListAsync_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); @@ -105,7 +105,7 @@ public async ValueTask Distinct_ToListAsync_With_ValidData_Must_Succeed(int[] so [MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] [MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] - public async ValueTask Distinct_SumAsync_With_ValidData_Must_Succeed(int[] source) + public async Task Distinct_SumAsync_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); diff --git a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs index e50bfbc0c..436690e85 100644 --- a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs @@ -93,11 +93,15 @@ static async ValueTask> GetSingleAsync> GetSingleAsync> GetSingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs index 23713e5fa..e175a1a28 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs @@ -166,16 +166,14 @@ public RepeatEnumerable Select(TSelector selector = public ValueTask ToArrayAsync(CancellationToken cancellationToken = default) { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var array = new TSource[count]; - if (value is object) + if (value is null) + return new ValueTask(result: new TSource[count]); + + var array = Utils.AllocateUninitializedArray(count); + for (var index = 0; index < array.Length; index++) { - var end = count - 1; - for (var index = 0; index <= end; index++) - { - cancellationToken.ThrowIfCancellationRequested(); - array[index] = value; - } + cancellationToken.ThrowIfCancellationRequested(); + array[index] = value; } return new ValueTask(result: array); } @@ -184,8 +182,7 @@ public ValueTask> ToArrayAsync(ArrayPool pool, Cancellat { var result = pool.Lease(count, clearOnDispose); var array = result.Memory.Span; - var end = count - 1; - for (var index = 0; index <= end; index++) + for (var index = 0; index < array.Length; index++) { cancellationToken.ThrowIfCancellationRequested(); array[index] = value; diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs index a7ec67e50..2f3a0ac0b 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs @@ -177,8 +177,7 @@ public RepeatEnumerable Select(TSelector selector = public TSource[] ToArray() { - // ReSharper disable once HeapView.ObjectAllocation.Evident - var array = new TSource[Count]; + var array = Utils.AllocateUninitializedArray(Count); CopyTo(array.AsSpan()); return array; } @@ -231,7 +230,7 @@ public static TSource[] ToArrayVector(this RepeatEnumerable so where TSource : struct { // ReSharper disable once HeapView.ObjectAllocation.Evident - var array = new TSource[source.count]; + var array = Utils.AllocateUninitializedArray(source.count); source.CopyToVector(array.AsSpan()); return array; } From efaaa5d22f587ebde4842ac4106e4dccba899d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Tue, 14 Sep 2021 09:37:21 +0100 Subject: [PATCH 50/61] Bump version to 3.0.0-beta46 (#382) --- NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 4873c2627..41942f5c8 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -5,7 +5,7 @@ NetFabric.Hyperlinq NetFabric.Hyperlinq High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, Memory, and Span. - 3.0.0-beta45 + 3.0.0-beta46 Icon.png LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance From 187830828faa9e8720acad9e228522408054473b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Thu, 23 Sep 2021 09:30:38 +0100 Subject: [PATCH 51/61] Make Lease<> constructor public (#383) --- NetFabric.Hyperlinq/Lease.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NetFabric.Hyperlinq/Lease.cs b/NetFabric.Hyperlinq/Lease.cs index e82e62e89..717b6909d 100644 --- a/NetFabric.Hyperlinq/Lease.cs +++ b/NetFabric.Hyperlinq/Lease.cs @@ -28,7 +28,7 @@ public sealed class Lease T[]? rented; int length; - internal Lease(ArrayPool pool, int length, bool clearOnDispose) + public Lease(ArrayPool pool, int length, bool clearOnDispose = false) { Debug.Assert(length >= 0); @@ -208,7 +208,7 @@ public ArrayExtensions.ArraySegmentValueEnumerable AsValueEnumerable() : new ArraySegment(rented, 0, length).AsValueEnumerable(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IEnumerable AsEnumerable() + public Lease AsEnumerable() => this; } } \ No newline at end of file From d62f946b254158b9e6bb0578f96146d326c85d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anta=CC=83o=20Almada?= Date: Thu, 23 Sep 2021 21:34:23 +0100 Subject: [PATCH 52/61] 3.0.0-beta47 --- NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 41942f5c8..8e3b3a72d 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -5,7 +5,7 @@ NetFabric.Hyperlinq NetFabric.Hyperlinq High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, Memory, and Span. - 3.0.0-beta46 + 3.0.0-beta47 Icon.png LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance From 40a2e763effd2de518f6ace49d3ff74fbd0447bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Thu, 23 Sep 2021 23:14:16 +0100 Subject: [PATCH 53/61] Make ArrayPoolExtensions public (#384) --- .../AsValueEnumerable.ArraySegment.cs | 9 ++++++++- .../Where/Where/Where.ArraySegment.cs | 4 ++++ .../Where/Where/Where.ReadOnlyMemory.cs | 4 ++++ .../Where/WhereAt/WhereAt.ArraySegment.cs | 4 ++++ .../WhereSelect/WhereSelect.ArraySegment.cs | 4 ++++ NetFabric.Hyperlinq/Lease.cs | 18 ++++++++++++++---- NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj | 2 +- .../Select/Select/Select.ArraySegment.cs | 9 ++++++++- .../Select/SelectAt/SelectAt.ArraySegment.cs | 11 +++++++++-- .../Set/Distinct/Distinct.ArraySegment.cs | 4 ++++ .../Utils/ArrayPoolExtensions.cs | 9 ++++++--- 11 files changed, 66 insertions(+), 12 deletions(-) diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index c804277e0..fadda85ae 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -131,7 +131,14 @@ readonly object? IEnumerator.Current [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++index < source.Count; + { + if (index < source.Count) + { + index++; + return index < source.Count; + } + return false; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] [ExcludeFromCodeCoverage] diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index a459331c8..e1443b60a 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -78,10 +78,14 @@ readonly object? IEnumerator.Current [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() { + var index = this.index; while (++index <= end) { if (predicate.Invoke(source![index])) + { + this.index = index; return true; + } } return false; } diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index af9464323..b6242cfcf 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -77,11 +77,15 @@ readonly object? IEnumerator.Current public bool MoveNext() { var span = source.Span; + var index = this.index; while (++index < span.Length) { var item = span[index]; if (predicate.Invoke(item)) + { + this.index = index; return true; + } } return false; } diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index 0c9991022..63db8ad6c 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -84,10 +84,14 @@ readonly object? IEnumerator.Current [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() { + var index = this.index; while (++index <= end) { if (predicate.Invoke(source![index + offset], index)) + { + this.index = index; return true; + } } return false; } diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index 9b86a712f..0af6eba60 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -82,10 +82,14 @@ readonly object? IEnumerator.Current [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() { + var index = this.index; while (++index <= end) { if (predicate.Invoke(source![index])) + { + this.index = index; return true; + } } return false; } diff --git a/NetFabric.Hyperlinq/Lease.cs b/NetFabric.Hyperlinq/Lease.cs index 717b6909d..b9eb58550 100644 --- a/NetFabric.Hyperlinq/Lease.cs +++ b/NetFabric.Hyperlinq/Lease.cs @@ -28,7 +28,7 @@ public sealed class Lease T[]? rented; int length; - public Lease(ArrayPool pool, int length, bool clearOnDispose = false) + internal Lease(ArrayPool pool, int length, bool clearOnDispose) { Debug.Assert(length >= 0); @@ -37,7 +37,7 @@ public Lease(ArrayPool pool, int length, bool clearOnDispose = false) this.clearOnDispose = clearOnDispose; rented = length is 0 ? Array.Empty() - : this.pool.Rent(length); + : pool.Rent(length); } /// @@ -163,7 +163,12 @@ public readonly T Current [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++index < length; + { + if (index >= length) + return false; + index++; + return index < length; + } } public struct DisposableEnumerator @@ -192,7 +197,12 @@ readonly object? IEnumerator.Current [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++index < length; + { + if (index >= length) + return false; + index++; + return index < length; + } public void Reset() => index = -1; diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 8e3b3a72d..1b7b2c4eb 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -5,7 +5,7 @@ NetFabric.Hyperlinq NetFabric.Hyperlinq High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, Memory, and Span. - 3.0.0-beta47 + 3.0.0-beta48 Icon.png LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index d5cc8a071..f72ec8ee4 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -133,7 +133,14 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++index <= end; + { + if (index <= end) + { + index++; + return index <= end; + } + return false; + } [ExcludeFromCodeCoverage] [DoesNotReturn] diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index a2532139a..8c531f0d7 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -125,8 +125,15 @@ public TResult Current [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++index <= end; - + { + if (index <= end) + { + index++; + return index <= end; + } + return false; + } + [ExcludeFromCodeCoverage] [DoesNotReturn] public readonly void Reset() diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs index b3fa0878a..8a2511cfc 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs @@ -67,10 +67,14 @@ readonly object? IEnumerator.Current [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() { + var index = this.index; while (++index <= end) { if (set.Add(source![index])) + { + this.index = index; return true; + } } return false; } diff --git a/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs b/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs index 357419a8c..3d9d7ae9e 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs @@ -4,10 +4,13 @@ namespace NetFabric.Hyperlinq { - static class ArrayPoolExtensions + public static class ArrayPoolExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Lease Lease(this ArrayPool pool, int length, bool clearOnDispose) - => new(pool, length, clearOnDispose); + public static Lease Lease(this ArrayPool pool, int length, bool clearOnDispose = default) + => length < 0 + ? Throw.ArgumentOutOfRangeException>(nameof(length)) + // ReSharper disable once HeapView.ObjectAllocation.Evident + : new Lease(pool, length, clearOnDispose); } } From 9abf381ca277d0934bd810bc946e443d203106e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=A3o=20Almada?= Date: Mon, 27 Sep 2021 19:46:40 +0100 Subject: [PATCH 54/61] Remove NoInliningAttribute for Throw methods (#385) --- NetFabric.Hyperlinq/Utils/Throw.cs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/NetFabric.Hyperlinq/Utils/Throw.cs b/NetFabric.Hyperlinq/Utils/Throw.cs index 7fda0a647..8b8ad3075 100644 --- a/NetFabric.Hyperlinq/Utils/Throw.cs +++ b/NetFabric.Hyperlinq/Utils/Throw.cs @@ -8,102 +8,82 @@ namespace NetFabric.Hyperlinq static class Throw { [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static void ArgumentArraySegmentNullException(string paramName) => throw new ArgumentException(paramName: paramName, message: Resource.ArraySegmentNull); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static void ArgumentException(string paramName, string? message = default) => throw new ArgumentException(paramName: paramName, message: message); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static void ArgumentNullException(string paramName, string? message = default) => throw new ArgumentNullException(paramName: paramName, message: message); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static T ArgumentNullException(string paramName, string? message = default) => throw new ArgumentNullException(paramName: paramName, message: message); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static ref readonly T ArgumentNullExceptionRef(string paramName, string? message = default) => throw new ArgumentNullException(paramName: paramName, message: message); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static void ArgumentOutOfRangeException(string paramName, string? message = default) => throw new ArgumentOutOfRangeException(paramName: paramName, message: message); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static T ArgumentOutOfRangeException(string paramName, string? message = default) => throw new ArgumentOutOfRangeException(paramName: paramName, message: message); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static ref readonly T ArgumentOutOfRangeExceptionRef(string paramName, string? message = default) => throw new ArgumentOutOfRangeException(paramName: paramName, message: message); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static void EmptySequence() => throw new InvalidOperationException(Resource.EmptySequence); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static T EmptySequence() => throw new InvalidOperationException(Resource.EmptySequence); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static ref readonly T EmptySequenceRef() => throw new InvalidOperationException(Resource.EmptySequence); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static void NotSingleSequence() => throw new InvalidOperationException(Resource.NotSingleSequence); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static T NotSingleSequence() => throw new InvalidOperationException(Resource.NotSingleSequence); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static ref readonly T NotSingleSequenceRef() => throw new InvalidOperationException(Resource.NotSingleSequence); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static void InvalidOperationException(string? message = default) => throw new InvalidOperationException(message); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static T InvalidOperationException() => throw new InvalidOperationException(); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static void NotSupportedException() => throw new NotSupportedException(); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static T NotSupportedException() => throw new NotSupportedException(); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static void ObjectDisposedException(string objectName) => throw new ObjectDisposedException(objectName); [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] public static T ObjectDisposedException(string objectName) => throw new ObjectDisposedException(objectName); } From d6ed2e4becab90b8d153161448d547fa81391879 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Wed, 7 Jul 2021 22:25:27 +0100 Subject: [PATCH 55/61] Refactor the source generator to be public --- .editorconfig | 21 +- .github/workflows/dotnetcore.yml | 5 +- .../NetFabric.Hyperlinq.Benchmarks.csproj | 3 +- .../Count/Count.ReadOnlySpan.Tests.cs | 0 .../Count/Count.ValueEnumerable.Tests.cs | 0 .../Count.ValueReadOnlyCollection.Tests.cs | 0 .../CountAsync.AsyncValueEnumerable.Tests.cs | 0 .../Aggregation/Sum.TestData.cs | 0 .../Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs | 0 .../Sum/Sum.ValueEnumerable.Tests.cs | 0 .../Sum/Sum.ValueReadOnlyCollection.Tests.cs | 0 .../SumAsync.AsyncValueEnumerable.Tests.cs | 0 ...ncEnumerable.AsyncValueEnumerable.Tests.cs | 0 ...ValueEnumerable'1.AsyncEnumerable.Tests.cs | 0 ...Enumerable'1.AsyncValueEnumerable.Tests.cs | 0 ...ValueEnumerable'6.AsyncEnumerable.Tests.cs | 0 ...Enumerable'6.AsyncValueEnumerable.Tests.cs | 0 .../AsEnumerable.ValueEnumerable.Tests.cs | 0 .../AsValueEnumerable'1.Enumerable.Tests.cs | 0 ...ueEnumerable'1.ReadOnlyCollection.Tests.cs | 0 ...ValueEnumerable'1.ValueEnumerable.Tests.cs | 0 ...merable'1.ValueReadOnlyCollection.Tests.cs | 0 ...lueEnumerable'1.ValueReadOnlyList.Tests.cs | 0 .../AsValueEnumerable'6.Enumerable.Tests.cs | 0 ...ueEnumerable'6.ReadOnlyCollection.Tests.cs | 0 ...ValueEnumerable'6.ValueEnumerable.Tests.cs | 0 ...merable'6.ValueReadOnlyCollection.Tests.cs | 0 ...lueEnumerable'6.ValueReadOnlyList.Tests.cs | 0 .../AsValueEnumerable.ArraySegment.Tests.cs | 0 .../AsValueEnumerable.ReadOnlyMemory.Tests.cs | 0 .../AsValueEnumerable.ReadOnlySpan.Tests.cs | 0 .../Collections/Generic/Dictionary.Tests.cs | 0 .../Collections/Generic/HashSet.Tests.cs | 0 .../Collections/Generic/LinkedList.Tests.cs | 0 .../System/Collections/Generic/List.Tests.cs | 0 .../Generic/PriorityQueue.Tests.cs | 0 .../System/Collections/Generic/Queue.Tests.cs | 0 .../Generic/SortedDictionary.Tests.cs | 0 .../Collections/Generic/SortedSet.Tests.cs | 0 .../System/Collections/Generic/Stack.Tests.cs | 0 .../Immutable/ImmutableArray.Tests.cs | 0 .../Immutable/ImmutableDictionary.Tests.cs | 0 .../Immutable/ImmutableHashSet.Tests.cs | 0 .../Immutable/ImmutableList.Tests.cs | 0 .../Immutable/ImmutableQueue.Tests.cs | 0 .../ImmutableSortedDictionary.Tests.cs | 0 .../Immutable/ImmutableStack.Tests.cs | 0 .../Conversion/ToArray/ArrayBuilder.Tests.cs | 0 .../ToArray/LargeArrayBuilder.Tests.cs | 0 .../ToArray/ToArray.ReadOnlyList.Tests.cs | 0 .../ToArray/ToArray.ReadOnlySpan.Tests.cs | 0 .../ToArray/ToArray.ValueEnumerable.Tests.cs | 0 .../ToArray.ValueReadOnlyCollection.Tests.cs | 0 ...ToArrayAsync.AsyncValueEnumerable.Tests.cs | 0 .../ToList/ToList.ReadOnlyList.Tests.cs | 0 .../ToList/ToList.ReadOnlySpan.Tests.cs | 0 .../ToList/ToList.ValueEnumerable.Tests.cs | 0 .../ToList.ValueReadOnlyCollection.Tests.cs | 0 .../ToListAsync.AsyncValueEnumerable.Tests.cs | 0 .../Element/ElementAt.TestData.cs | 0 .../ElementAt/ElementAt.ReadOnlyList.Tests.cs | 0 .../ElementAt/ElementAt.ReadOnlySpan.Tests.cs | 0 .../ElementAt.ValueEnumerable.Tests.cs | 0 ...ElementAt.ValueReadOnlyCollection.Tests.cs | 0 ...ementAtAsync.AsyncValueEnumerable.Tests.cs | 0 .../Element/First/First.ReadOnlyList.Tests.cs | 0 .../Element/First/First.ReadOnlySpan.Tests.cs | 0 .../First/First.ValueEnumerable.Tests.cs | 0 .../First.ValueReadOnlyCollection.Tests.cs | 0 .../FirstAsync.AsyncValueEnumerable.Tests.cs | 0 .../Single/Single.ReadOnlyList.Tests.cs | 0 .../Single/Single.ReadOnlySpan.Tests.cs | 0 .../Single/Single.ValueEnumerable.Tests.cs | 0 .../Single.ValueReadOnlyCollection.Tests.cs | 0 .../SingleAsync.AsyncValueEnumerable.Tests.cs | 0 .../Where/Where.ArraySegment.Tests.cs | 0 .../Where/Where.AsyncValueEnumerable.Tests.cs | 0 .../Where/Where.ReadOnlyMemory.Tests.cs | 0 .../Where/Where.ReadOnlySpan.Tests.cs | 0 .../Where/Where.ValueEnumerable.Tests.cs | 0 .../Where.ValueReadOnlyCollection.Tests.cs | 0 .../WhereAt/WhereAt.ArraySegment.Tests.cs | 0 .../WhereAt.AsyncValueEnumerable.Tests.cs | 0 .../WhereAt/WhereAt.ReadOnlyMemory.Tests.cs | 0 .../WhereAt/WhereAt.ReadOnlySpan.Tests.cs | 0 .../WhereAt/WhereAt.ValueEnumerable.Tests.cs | 0 .../WhereAt.ValueReadOnlyCollection.Tests.cs | 0 .../WhereSelect.ArraySegment.Tests.cs | 0 .../WhereSelect.AsyncValueEnumerable.Tests.cs | 0 .../WhereSelect.ReadOnlyMemory.Tests.cs | 0 .../WhereSelect.ReadOnlySpan.Tests.cs | 0 .../WhereSelect.ValueEnumerable.Tests.cs | 0 ...ereSelect.ValueReadOnlyCollection.Tests.cs | 0 .../AsyncValueEnumerable/Empty.Tests.cs | 0 .../AsyncValueEnumerable/Range.Tests.cs | 0 .../AsyncValueEnumerable/Repeat.Tests.cs | 0 .../AsyncValueEnumerable/Return.Tests.cs | 0 .../Generation/Range.TestData.cs | 0 .../Generation/Repeat.TestData.cs | 0 .../Generation/Return.TestData.cs | 0 .../Generation/ValueEnumerable/Empty.Tests.cs | 0 .../Generation/ValueEnumerable/Range.Tests.cs | 0 .../ValueEnumerable/Repeat.Tests.cs | 0 .../ValueEnumerable/Return.Tests.cs | 0 .../GlobalSuppressions.cs | 0 .../NetFabric.Hyperlinq.Core.UnitTests.csproj | 28 +- .../Option/Option.Tests.cs | 0 .../Option/TestData.Option.cs | 0 .../Partitioning/Skip.TestData.cs | 0 .../Skip/Skip.AsyncValueEnumerable.Tests.cs | 0 .../Skip/Skip.ValueEnumerable.Tests.cs | 0 .../Skip.ValueReadOnlyCollection.Tests.cs | 0 .../Skip/Skip.ValueReadOnlyList.Tests.cs | 0 .../Partitioning/SkipTake.TestData.cs | 0 .../Partitioning/Take.TestData.cs | 0 .../Take/Take.AsyncValueEnumerable.Tests.cs | 0 .../Take/Take.ValueEnumerable.Tests.cs | 0 .../Take.ValueReadOnlyCollection.Tests.cs | 0 .../Take/Take.ValueReadOnlyList.Tests.cs | 0 .../Select/Select.ArraySegment.Tests.cs | 0 .../Select.AsyncValueEnumerable.Tests.cs | 0 .../Select/Select.ReadOnlyMemory.Tests.cs | 0 .../Select/Select.ReadOnlySpan.Tests.cs | 0 .../Select/Select.ValueEnumerable.Tests.cs | 0 .../Select.ValueReadOnlyCollection.Tests.cs | 0 .../Select/Select.ValueReadOnlyList.Tests.cs | 0 .../SelectAt/SelectAt.ArraySegment.Tests.cs | 0 .../SelectAt.AsyncValueEnumerable.Tests.cs | 0 .../SelectAt/SelectAt.ReadOnlyMemory.Tests.cs | 0 .../SelectAt/SelectAt.ReadOnlySpan.Tests.cs | 0 .../SelectAt.ValueEnumerable.Tests.cs | 0 .../SelectAt.ValueReadOnlyCollection.Tests.cs | 0 .../SelectAt.ValueReadOnlyList.Tests.cs | 0 .../Projection/SelectVector.TestData.cs | 0 .../SelectVector.ReadOnlySpan.Tests.cs | 0 .../All/All.AsyncValueEnumerable.Tests.cs | 0 .../Quantifier/All/All.ReadOnlySpan.Tests.cs | 0 .../All/All.ValueEnumerable.Tests.cs | 0 .../All/All.ValueReadOnlyCollection.Tests.cs | 0 .../Any/Any.AsyncValueEnumerable.Tests.cs | 0 .../Quantifier/Any/Any.ReadOnlySpan.Tests.cs | 0 .../Any/Any.ValueEnumerable.Tests.cs | 0 .../Any/Any.ValueReadOnlyCollection.Tests.cs | 0 .../Contains.AsyncValueEnumerable.Tests.cs | 0 .../Contains/Contains.ReadOnlySpan.Tests.cs | 0 .../Contains.ValueEnumerable.Tests.cs | 0 .../Contains.ValueReadOnlyCollection.Tests.cs | 0 .../ContainsVector.ReadOnlySpan.Tests.cs | 0 .../Distinct/Distinct.ArraySegment.Tests.cs | 0 .../Distinct.AsyncValueEnumerable.Tests.cs | 0 .../Distinct/Distinct.ReadOnlyMemory.Tests.cs | 0 .../Distinct/Distinct.ReadOnlySpan.Tests.cs | 0 .../Distinct.ValueEnumerable.Tests.cs | 0 .../TestData/TestData.Empty.cs | 0 .../TestData/TestData.Multiple.cs | 0 .../TestData/TestData.Single.cs | 0 .../Utils/DelegateExtensions.cs | 0 .../Utils/SpanExtensions.cs | 0 .../Utils/TestComparer.cs | 0 .../Utils/Wrappers/Wrap.AsAsyncEnumerable.cs | 6 +- .../Wrappers/Wrap.AsAsyncValueEnumerable.cs | 4 - .../Utils/Wrappers/Wrap.AsCollection.cs | 0 .../Utils/Wrappers/Wrap.AsEnumerable.cs | 4 - .../Utils/Wrappers/Wrap.AsFunctionIn.cs | 0 .../Utils/Wrappers/Wrap.AsList.cs | 0 .../Wrappers/Wrap.AsReadOnlyCollection.cs | 10 - .../Utils/Wrappers/Wrap.AsReadOnlyList.cs | 3 - .../Utils/Wrappers/Wrap.AsValueCollection.cs | 12 - .../Utils/Wrappers/Wrap.AsValueEnumerable.cs | 4 - .../Utils/Wrappers/Wrap.AsValueList.cs | 12 - .../Wrap.AsValueReadOnlyCollection.cs | 12 - .../Wrappers/Wrap.AsValueReadOnlyList.cs | 12 - .../Utils/Wrappers/Wrap.AsyncEnumerator.cs | 0 .../Utils/Wrappers/Wrap.Enumerator.cs | 0 .../Aggregation/Count/Count.ReadOnlySpan.cs | 10 +- .../Count/Count.ValueEnumerable.cs | 12 - .../Count/Count.ValueReadOnlyCollection.cs | 13 +- .../Count/Count.ValueReadOnlyList.cs | 31 ++ .../Count/CountAsync.AsyncValueEnumerable.cs | 12 - .../Aggregation/Sum/Sum.Range.cs | 2 - .../Aggregation/Sum/Sum.ReadOnlySpan.cs | 16 +- .../Aggregation/Sum/Sum.ValueEnumerable.cs | 14 +- .../Sum/Sum.ValueReadOnlyCollection.cs | 14 +- .../Aggregation/Sum/Sum.ValueReadOnlyList.cs | 17 + .../Sum/SumAsync.AsyncValueEnumerable.cs | 12 +- .../AsAsyncEnumerable.AsyncValueEnumerable.cs | 0 ...sAsyncValueEnumerable'1.AsyncEnumerable.cs | 0 ...cValueEnumerable'1.AsyncValueEnumerable.cs | 1 - ...sAsyncValueEnumerable'6.AsyncEnumerable.cs | 10 +- ...cValueEnumerable'6.AsyncValueEnumerable.cs | 9 +- .../AsyncValueEnumerator.cs | 0 .../AsEnumerable.ValueEnumerable.cs | 0 .../AsValueEnumerable.Array.cs | 1 - .../AsValueEnumerable.ArraySegment.cs | 240 +++++++++ .../AsValueEnumerable.ImmutableArray.cs | 0 .../AsValueEnumerable.List.cs | 0 .../AsValueEnumerable.Memory.cs | 3 +- .../AsValueEnumerable.ReadOnlyMemory.cs | 25 +- .../AsValueEnumerable.ReadOnlySpan.cs | 119 +---- .../AsValueEnumerable.Span.cs | 4 +- .../AsValueEnumerable/SpanEnumerator.cs | 0 .../AsValueEnumerable/ValueEnumerator.cs | 0 .../ToArray/ToArray.ReadOnlySpan.cs | 12 - .../ToArray/ToArray.ValueEnumerable.cs | 13 +- .../ToArray.ValueReadOnlyCollection.cs | 11 +- .../ToArray/ToArray.ValueReadOnlyList.cs | 24 + .../ToArrayAsync.AsyncValueEnumerable.cs | 20 +- .../ToDictionary/ToDictionary.ReadOnlySpan.cs | 12 +- .../ToDictionary.ValueEnumerable.cs | 26 +- .../ToDictionary.ValueReadOnlyCollection.cs | 26 +- .../ToDictionary.ValueReadOnlyList.cs | 30 ++ .../ToDictionaryAsync.AsyncValueEnumerable.cs | 34 +- .../Conversion/ToList/ToList.ReadOnlySpan.cs | 12 +- .../ToList/ToList.ValueEnumerable.cs | 10 +- .../ToList/ToList.ValueReadOnlyCollection.cs | 10 +- .../ToList/ToList.ValueReadOnlyList.cs | 15 + .../ToListAsync.AsyncValueEnumerable.cs | 10 +- .../ElementAt/ElementAt.ReadOnlyList.cs | 6 +- .../ElementAt/ElementAt.ReadOnlySpan.cs | 10 +- .../ElementAt/ElementAt.ValueEnumerable.cs | 10 +- .../ElementAt.ValueReadOnlyCollection.cs | 10 +- .../ElementAt/ElementAt.ValueReadOnlyList.cs | 21 + .../ElementAtAsync.AsyncValueEnumerable.cs | 10 +- .../Element/First/First.ReadOnlyList.cs | 6 +- .../Element/First/First.ReadOnlySpan.cs | 10 +- .../Element/First/First.ValueEnumerable.cs | 10 +- .../First/First.ValueReadOnlyCollection.cs | 16 +- .../Element/First/First.ValueReadOnlyList.cs | 15 + .../First/FirstAsync.AsyncValueEnumerable.cs | 10 +- .../Element/Single/Single.ReadOnlyList.cs | 6 +- .../Element/Single/Single.ReadOnlySpan.cs | 6 +- .../Element/Single/Single.ValueEnumerable.cs | 16 +- .../Single/Single.ValueReadOnlyCollection.cs | 10 +- .../Single/Single.ValueReadOnlyList.cs | 15 + .../SingleAsync.AsyncValueEnumerable.cs | 15 +- .../SequenceEqual.ReadOnlySpan.cs | 2 +- .../Where/Where/Where.ArraySegment.cs | 62 +-- .../Where/Where/Where.AsyncValueEnumerable.cs | 53 -- .../Where/Where/Where.ReadOnlyMemory.cs | 2 +- .../Where/Where/Where.ReadOnlySpan.cs | 1 - .../Where/Where/Where.ValueEnumerable.cs | 53 -- .../Where/Where.ValueReadOnlyCollection.cs | 53 -- .../Where/Where/Where.ValueReadOnlyList.cs | 18 + .../Filtering/Where/Where/WhereEnumerator.cs | 0 .../Where/WhereAt/WhereAt.ArraySegment.cs | 61 ++- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 49 -- .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 1 - .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 1 - .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 49 -- .../WhereAt.ValueReadOnlyCollection.cs | 49 -- .../WhereAt/WhereAt.ValueReadOnlyList.cs | 18 + .../Where/WhereAt/WhereAtEnumerator.cs | 0 .../WhereSelect/WhereSelect.ArraySegment.cs | 69 +-- .../WhereSelect.AsyncValueEnumerable.cs | 49 +- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 21 +- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 3 +- .../WhereSelect.ValueEnumerable.cs | 55 +-- .../WhereSelect.ValueReadOnlyCollection.cs | 55 +-- .../WhereSelect/WhereSelectEnumerator.cs | 0 .../Generation/AsyncValueEnumerable/Empty.cs | 0 .../Generation/AsyncValueEnumerable/Range.cs | 1 - .../Generation/AsyncValueEnumerable/Repeat.cs | 4 - .../Generation/AsyncValueEnumerable/Return.cs | 28 +- .../ValueEnumerable/CreateValueEnumerable.cs | 0 .../Generation/ValueEnumerable/Empty.cs | 0 .../Generation/ValueEnumerable/Range.cs | 29 +- .../Generation/ValueEnumerable/Repeat.cs | 4 - .../Generation/ValueEnumerable/Return.cs | 14 - .../GlobalSuppressions.cs | 0 .../Lease.cs | 0 .../NetFabric.Hyperlinq.Core.csproj | 84 ++++ .../Option/NoneOption.cs | 0 .../Option/Option.cs | 1 - .../Skip/Skip.AsyncValueEnumerable.cs | 0 .../Partitioning/Skip/Skip.ReadOnlyList.cs | 2 +- .../Partitioning/Skip/Skip.ValueEnumerable.cs | 0 .../Skip/Skip.ValueReadOnlyCollection.cs | 0 .../Skip/Skip.ValueReadOnlyList.cs | 15 + .../SkipTake/SkipTake.AsyncValueEnumerable.cs | 0 .../SkipTake/SkipTake.ReadOnlyList.cs | 27 -- .../SkipTake/SkipTake.ValueEnumerable.cs | 0 .../SkipTake.ValueReadOnlyCollection.cs | 32 -- .../Take/Take.AsyncValueEnumerable.cs | 0 .../Partitioning/Take/Take.ReadOnlyList.cs | 2 +- .../Partitioning/Take/Take.ValueEnumerable.cs | 0 .../Take/Take.ValueReadOnlyCollection.cs | 0 .../Take/Take.ValueReadOnlyList.cs | 15 + .../Select/Select/Select.ArraySegment.cs | 70 +-- .../Select/Select.AsyncValueEnumerable.cs | 16 - .../Select/Select/Select.ReadOnlyMemory.cs | 30 -- .../Select/Select/Select.ReadOnlySpan.cs | 7 - .../Select/Select/Select.ValueEnumerable.cs | 22 - .../Select/Select.ValueReadOnlyCollection.cs | 50 -- .../Select/Select/Select.ValueReadOnlyList.cs | 44 -- .../Select/Select/SelectEnumerator.cs | 0 .../Select/SelectAt/SelectAt.ArraySegment.cs | 43 +- .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 16 - .../SelectAt/SelectAt.ReadOnlyMemory.cs | 30 -- .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 7 - .../SelectAt/SelectAt.ValueEnumerable.cs | 22 - .../SelectAt.ValueReadOnlyCollection.cs | 50 -- .../SelectAt/SelectAt.ValueReadOnlyList.cs | 44 -- .../Select/SelectAt/SelectAtEnumerator.cs | 0 .../Select/SelectVector/SelectVector.Range.cs | 2 +- .../SelectVector/SelectVector.ReadOnlySpan.cs | 2 - .../SelectMany/SelectMany.ArraySegment.cs | 27 +- .../SelectMany/SelectMany.ReadOnlyMemory.cs | 27 +- .../SelectMany/SelectMany.ReadOnlySpan.cs | 3 +- .../SelectMany/SelectMany.ValueEnumerable.cs | 35 +- .../SelectMany.ValueReadOnlyCollection.cs | 20 + .../SelectMany.ValueReadOnlyList.cs | 20 + .../Properties/AssemblyInfo.cs | 3 + .../Quantifier/All/All.ReadOnlySpan.cs | 0 .../Quantifier/All/All.ValueEnumerable.cs | 13 - .../All/All.ValueReadOnlyCollection.cs | 12 - .../Quantifier/All/All.ValueReadOnlyList.cs | 25 + .../All/AllAsync.AsyncValueEnumerable.cs | 0 .../Quantifier/Any/Any.ReadOnlySpan.cs | 0 .../Quantifier/Any/Any.ValueEnumerable.cs | 12 - .../Any}/Any.ValueReadOnlyCollection.cs | 11 +- .../Quantifier/Any/Any.ValueReadOnlyList.cs | 31 ++ .../Any/AnyAsync.AsyncValueEnumerable.cs | 0 .../Contains/Contains.Enumerable.cs | 4 +- .../Contains/Contains.ReadOnlySpan.cs | 4 +- .../Contains/Contains.ValueEnumerable.cs | 4 +- .../Contains.ValueReadOnlyCollection.cs | 4 +- .../Contains/Contains.ValueReadOnlyList.cs | 14 + .../ContainsAsync.AsyncValueEnumerable.cs | 0 .../ContainsVector.ReadOnlySpan.cs | 2 +- .../ContainsVector/ContainsVector.Span.cs | 2 +- .../Resource.Designer.cs | 0 .../Resource.resx | 0 .../Set/Distinct/Distinct.ArraySegment.cs | 56 --- .../Distinct/Distinct.AsyncValueEnumerable.cs | 0 .../Set/Distinct/Distinct.ReadOnlyMemory.cs | 56 --- .../Set/Distinct/Distinct.ReadOnlySpan.cs | 0 .../Set/Distinct/Distinct.ValueEnumerable.cs | 0 .../Distinct.ValueReadOnlyCollection.cs | 18 + .../Distinct/Distinct.ValueReadOnlyList.cs | 18 + .../Set/Distinct/Set.cs | 0 .../Utils/ArrayBuilder/ArrayBuilder.cs | 0 .../Utils/ArrayBuilder/LargeArrayBuilder.cs | 0 .../ToArrayBuilder.ReadOnlyList.cs | 70 +++ .../ToArrayBuilder.ReadOnlySpan.cs | 6 +- .../ToArrayBuilder.ValueEnumerable.cs | 11 +- ...oArrayBuilderAsync.AsyncValueEnumerable.cs | 12 +- .../Utils/ArrayExtensions.cs | 16 + .../Utils/ArrayPoolExtensions.cs | 0 .../Utils/ArraySegmentExtensions.cs | 5 +- .../Utils/BooleanExtensions.cs | 0 .../Utils/Copy/Copy.Range.cs | 0 .../Utils/Copy/Copy.ReadOnlySpan.cs | 0 .../Copy/Copy.ValueReadOnlyCollection.cs | 0 .../Utils/Default.cs | 0 .../Utils/EnumeratorState.cs | 0 .../AsyncPredicateCombination.cs | 0 .../AsyncSelectorCombination.cs | 0 .../PredicateCombination.cs | 0 .../PredicateInCombination.cs | 0 .../SelectorCombination.cs | 0 .../Utils/IndexOf/IndexOf.ReadOnlySpan.cs | 0 .../IndexOf.ValueReadOnlyCollection.cs | 0 .../Utils/IntExtensions.cs | 0 .../Utils/MemoryExtensions.cs | 12 + .../Utils/Scalar.cs | 0 .../Utils/SpanExtensions.cs | 12 + .../Utils/Throw.cs | 0 .../Utils/ThrowIfArgument.cs | 0 .../Utils/Utils.AllocateUninitializedArray.cs | 0 .../Utils/Utils.EqualityComparer.cs | 0 .../Utils/Utils.SkipTake.cs | 0 .../Utils/VectorExtensions.cs | 0 .../NetFabric.Hyperlinq.Immutable.csproj | 55 --- .../CollectExtensionMethodsTests.cs | 49 -- .../GenerateSourceTests.cs | 241 --------- .../TestData/Results/Dictionary.Select.cs | 30 -- .../TestData/Results/Dictionary.Where.cs | 30 -- .../Results/Distinct.ValueEnumerable.Where.cs | 36 -- .../TestData/Results/Range.Count.cs | 20 - .../TestData/Results/Range.Select.cs | 30 -- .../TestData/Results/Range.Where.cs | 30 -- .../TestData/Results/Repeat.Count.cs | 20 - .../Results/Select.ArraySegment.Any.cs | 30 -- .../Results/Select.ValueEnumerable.Any.cs | 36 -- .../Results/Select.ValueEnumerable.First.cs | 23 - .../Results/Select.ValueEnumerable.Where.cs | 30 -- .../Results/Where.ArraySegment.Count.cs | 23 - .../Results/Where.ValueEnumerable.Count.cs | 23 - .../Results/Where.ValueEnumerable.Distinct.cs | 23 - .../Results/Where.ValueEnumerable.First.cs | 23 - .../Results/Where.ValueEnumerable.Select.cs | 30 -- .../TestData/Source/Any.ArraySegment.cs | 20 - .../TestData/Source/Any.ValueEnumerable.cs | 26 - .../TestData/Source/Any.ValueReadOnlyList.cs | 28 -- .../TestData/Source/Common/IFunction.cs | 7 - .../Source/Common/IFunctionWrapper.cs | 16 - .../Source/Common/IValueEnumerable.cs | 31 -- .../TestData/Source/Common/Option.cs | 8 - .../Source/Common/PredicateCombination.cs | 17 - .../Source/Common/SelectorCombination.cs | 17 - .../Source/Contains.ValueEnumerable.cs | 18 - .../TestData/Source/Count.ValueEnumerable.cs | 12 - .../TestData/Source/Dictionary.Bindings.cs | 57 --- .../TestData/Source/Distinct.ArraySegment.cs | 56 --- .../Source/Distinct.ValueEnumerable.cs | 60 --- .../TestData/Source/ExtensionMethods.cs | 21 - .../TestData/Source/First.ValueEnumerable.cs | 15 - .../TestData/Source/NoExtensionMethods.cs | 41 -- .../TestData/Source/Range.cs | 88 ---- .../TestData/Source/Repeat.cs | 139 ------ .../TestData/Source/Select.ArraySegment.cs | 115 ----- .../TestData/Source/Select.ValueEnumerable.cs | 79 --- .../Source/ToDictionary.ArraySegment.cs | 46 -- .../TestData/Source/Where.ArraySegment.cs | 80 --- .../TestData/Source/Where.ValueEnumerable.cs | 86 ---- .../Verifier.cs | 42 -- ...NetFabric.Hyperlinq.SourceGenerator.csproj | 21 - .../OverloadsGenerator.cs | 409 ---------------- .../Properties/AssemblyInfo.cs | 3 - .../Utils/CodeBuilder.cs | 71 --- .../GenerateSourceTests.cs | 143 ++++++ .../NetFabric.Hyperlinq.UnitTests.csproj | 39 +- ...e.TestEnumerableWithValueTypeEnumerator.cs | 50 ++ .../AsValueEnumerable.IReadOnlyList.cs | 112 +++++ .../Results/AsValueEnumerable.Repeat.cs | 26 + .../AsValueEnumerable.TestCollection.cs | 77 +++ ...erableWithInterfacelessPublicEnumerator.cs | 66 +++ ...umerable.TestEnumerableWithNoInterfaces.cs | 64 +++ ...erfacesButEnumeratorWithResetAndDispose.cs | 65 +++ ...stEnumerableWithReferenceTypeEnumerator.cs | 46 ++ ...e.TestEnumerableWithValueTypeEnumerator.cs | 46 ++ .../Results/AsValueEnumerable.TestList.cs | 94 ++++ ...umerable.TestListWithExplicitInterfaces.cs | 94 ++++ ...sValueEnumerable.TestReadOnlyCollection.cs | 83 ++++ .../AsValueEnumerable.TestReadOnlyList.cs | 112 +++++ .../AsValueEnumerable.TestValueEnumerable.cs | 26 + .../TestData/Results/Count.Array.cs | 26 + .../TestData/Results/Count.Span.cs | 26 + .../TestData/Results/Empty.cs | 17 + .../TestData/Results/Select.Array.cs | 26 + ...t.TestEnumerableWithValueTypeEnumerator.cs | 56 +++ .../TestData/Results/Skip.Take.Array.cs | 35 ++ .../TestData/Results/Where.Array.cs | 26 + ...e.TestEnumerableWithValueTypeEnumerator.cs | 13 + .../Source/AsValueEnumerable.Empty.cs | 28 ++ .../Source/AsValueEnumerable.Empty2.cs | 27 ++ .../Source/AsValueEnumerable.Empty3.cs | 18 + .../Source/AsValueEnumerable.IReadOnlyList.cs | 17 + .../Source/AsValueEnumerable.Repeat.cs | 13 + .../AsValueEnumerable.TestCollection.cs | 15 + ...erableWithInterfacelessPublicEnumerator.cs | 20 + ...umerable.TestEnumerableWithNoInterfaces.cs | 17 + ...erfacesButEnumeratorWithResetAndDispose.cs | 20 + ...stEnumerableWithReferenceTypeEnumerator.cs | 19 + ...e.TestEnumerableWithValueTypeEnumerator.cs | 19 + .../Source/AsValueEnumerable.TestList.cs | 15 + ...umerable.TestListWithExplicitInterfaces.cs | 15 + ...sValueEnumerable.TestReadOnlyCollection.cs | 15 + .../AsValueEnumerable.TestReadOnlyList.cs | 15 + .../AsValueEnumerable.TestValueEnumerable.cs | 15 + .../TestData/Source/Common/Enumerables.cs | 327 +++++++++++++ .../TestData/Source/Common/ItemTypes.cs | 7 + .../Source/Common/ValueEnumerables.cs | 45 ++ .../TestData/Source/Count.Array.cs | 13 + .../TestData/Source/Count.Span.cs | 16 + .../TestData/Source/Select.Array.cs | 13 + ...t.TestEnumerableWithValueTypeEnumerator.cs | 13 + .../TestData/Source/Skip.Take.Array.cs | 14 + .../TestData/Source/Where.Array.cs | 13 + NetFabric.Hyperlinq.UnitTests/Verifier.cs | 49 ++ NetFabric.Hyperlinq.sln | 42 +- .../Attributes/GeneratorBindingsAttribute.cs | 0 .../Attributes/GeneratorIgnoreAttribute.cs | 0 .../Attributes/GeneratorMappingAttribute.cs | 0 .../CompilationContext.cs | 1 + .../AsValueEnumerable'1.Enumerable.cs | 155 ------ .../AsValueEnumerable'1.ReadOnlyCollection.cs | 214 -------- .../AsValueEnumerable'1.ReadOnlyList.cs | 320 ------------ .../AsValueEnumerable'1.ValueEnumerable.cs | 174 ------- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 246 ---------- .../AsValueEnumerable'6.Enumerable.cs | 264 ---------- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 348 ------------- .../AsValueEnumerable'6.ValueEnumerable.cs | 266 ---------- ...lueEnumerable'6.ValueReadOnlyCollection.cs | 361 -------------- .../AsValueEnumerable'6.ValueReadOnlyList.cs | 428 ---------------- .../AsValueEnumerable.ArraySegment.cs | 459 ------------------ .../Generic/DictionaryExtensions.cs | 47 -- .../Collections/Generic/HashSetExtensions.cs | 24 - .../Generic/LinkedListExtensions.cs | 24 - .../Generic/PriorityQueueExtensions.cs | 29 -- .../Collections/Generic/QueueExtensions.cs | 24 - .../Generic/SortedDictionaryExtensions.cs | 47 -- .../Generic/SortedSetExtensions.cs | 24 - .../Collections/Generic/StackExtensions.cs | 24 - .../ImmutableDictionaryExtensions.cs | 27 -- .../Immutable/ImmutableHashSetExtensions.cs | 24 - .../Immutable/ImmutableListExtensions.cs | 24 - .../Immutable/ImmutableQueueExtensions.cs | 36 -- .../ImmutableSortedDictionaryExtensions.cs | 27 -- .../Immutable/ImmutableStackExtensions.cs | 36 -- .../Conversion/ToArray/ToArray.Memory.cs | 15 - .../ToArray/ToArray.ReadOnlyMemory.cs | 15 - .../Conversion/ToArray/ToArray.Span.cs | 15 - .../Generator.AsValueEnumerable.cs | 405 ++++++++++++++++ NetFabric.Hyperlinq/Generator.cs | 348 +++++++++++++ NetFabric.Hyperlinq/ITypeSymbolExtensions.cs | 53 ++ NetFabric.Hyperlinq/MethodSignature.cs | 41 ++ .../NetFabric.Hyperlinq.csproj | 98 ++-- .../Properties/AssemblyInfo.cs | 4 +- .../Any/Any.ValueReadOnlyCollection.cs | 43 -- NetFabric.Hyperlinq/SyntaxReceiver.cs | 33 ++ NetFabric.Hyperlinq/TypeSymbolsCache.cs | 28 ++ .../Utils/AttributeExtensions.cs | 0 NetFabric.Hyperlinq/Utils/CodeBuilder.cs | 98 ++++ .../Utils/DictionarySet.cs | 0 .../Utils/MethodSymbolExtensions.cs | 2 +- .../Utils/NamespaceSymbolExtensions.cs | 0 .../Utils/StringExtensions.cs | 0 .../Utils/SymbolExtensions.cs | 0 .../Utils/TypeParameterSymbolExtensions.cs | 0 .../Utils/TypeSymbolConversionComparer.cs | 24 + .../Utils/TypeSymbolExtensions.cs | 0 NetFabric.Hyperlinq/ValueEnumerableType.cs | 6 + README.md | 2 + 524 files changed, 4457 insertions(+), 8215 deletions(-) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Aggregation/Count/Count.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Aggregation/Count/Count.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Aggregation/Sum.TestData.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Dictionary.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSet.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueue.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Queue.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionary.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSet.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Stack.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToArray/ArrayBuilder.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToArray/LargeArrayBuilder.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToList/ToList.ReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToList/ToList.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToList/ToList.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/ElementAt.TestData.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/ElementAt/ElementAt.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/ElementAt/ElementAt.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/First/First.ReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/First/First.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/First/First.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/First/First.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/Single/Single.ReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/Single/Single.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/Single/Single.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/Single/Single.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/Where/Where.ArraySegment.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/Where/Where.ReadOnlyMemory.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/Where/Where.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/Where/Where.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereAt/WhereAt.ArraySegment.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereAt/WhereAt.ReadOnlyMemory.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereAt/WhereAt.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereAt/WhereAt.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereSelect/WhereSelect.ArraySegment.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereSelect/WhereSelect.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/AsyncValueEnumerable/Empty.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/AsyncValueEnumerable/Range.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/AsyncValueEnumerable/Repeat.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/AsyncValueEnumerable/Return.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/Range.TestData.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/Repeat.TestData.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/Return.TestData.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/ValueEnumerable/Empty.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/ValueEnumerable/Range.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/ValueEnumerable/Repeat.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Generation/ValueEnumerable/Return.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/GlobalSuppressions.cs (100%) rename NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj => NetFabric.Hyperlinq.Core.UnitTests/NetFabric.Hyperlinq.Core.UnitTests.csproj (53%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Option/Option.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Option/TestData.Option.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Skip.TestData.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Skip/Skip.ValueReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/SkipTake.TestData.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Take.TestData.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Take/Take.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Partitioning/Take/Take.ValueReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/Select/Select.ArraySegment.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/Select/Select.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/Select/Select.ReadOnlyMemory.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/Select/Select.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/Select/Select.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/Select/Select.ValueReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/SelectAt/SelectAt.ArraySegment.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/SelectAt/SelectAt.ReadOnlyMemory.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/SelectAt/SelectAt.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/SelectAt/SelectAt.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/SelectAt/SelectAt.ValueReadOnlyList.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/SelectVector.TestData.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Projection/SelectVector/SelectVector.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/All/All.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/All/All.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/All/All.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/Any/Any.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/Any/Any.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Set/Distinct/Distinct.ArraySegment.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Set/Distinct/Distinct.ValueEnumerable.Tests.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/TestData/TestData.Empty.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/TestData/TestData.Multiple.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/TestData/TestData.Single.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/DelegateExtensions.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/SpanExtensions.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/TestComparer.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs (77%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs (78%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsCollection.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsEnumerable.cs (81%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsFunctionIn.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsList.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs (55%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsReadOnlyList.cs (81%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsValueCollection.cs (69%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsValueEnumerable.cs (79%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsValueList.cs (75%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs (60%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs (62%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.AsyncEnumerator.cs (100%) rename {NetFabric.Hyperlinq.UnitTests => NetFabric.Hyperlinq.Core.UnitTests}/Utils/Wrappers/Wrap.Enumerator.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Aggregation/Count/Count.ReadOnlySpan.cs (68%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Aggregation/Count/Count.ValueEnumerable.cs (68%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Aggregation/Count/Count.ValueReadOnlyCollection.cs (64%) create mode 100644 NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs (73%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Aggregation/Sum/Sum.Range.cs (97%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Aggregation/Sum/Sum.ReadOnlySpan.cs (97%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Aggregation/Sum/Sum.ValueEnumerable.cs (94%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs (93%) create mode 100644 NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs (97%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsAsyncValueEnumerable/AsyncValueEnumerator.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs (93%) create mode 100644 NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArrayExtensions.cs => NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ImmutableArray.cs (100%) rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs => NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.List.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs (76%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs (91%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs (54%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs (77%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsValueEnumerable/SpanEnumerator.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/AsValueEnumerable/ValueEnumerator.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToArray/ToArray.ReadOnlySpan.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToArray/ToArray.ValueEnumerable.cs (97%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs (97%) create mode 100644 NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs (97%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs (85%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs (83%) create mode 100644 NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs (88%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToList/ToList.ReadOnlySpan.cs (94%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToList/ToList.ValueEnumerable.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToList/ToList.ValueReadOnlyCollection.cs (96%) create mode 100644 NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/ElementAt/ElementAt.ReadOnlyList.cs (95%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/ElementAt/ElementAt.ReadOnlySpan.cs (95%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/ElementAt/ElementAt.ValueEnumerable.cs (97%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs (97%) create mode 100644 NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/First/First.ReadOnlyList.cs (94%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/First/First.ReadOnlySpan.cs (95%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/First/First.ValueEnumerable.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/First/First.ValueReadOnlyCollection.cs (94%) create mode 100644 NetFabric.Hyperlinq.Core/Element/First/First.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/First/FirstAsync.AsyncValueEnumerable.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/Single/Single.ReadOnlyList.cs (94%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/Single/Single.ReadOnlySpan.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/Single/Single.ValueEnumerable.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/Single/Single.ValueReadOnlyCollection.cs (97%) create mode 100644 NetFabric.Hyperlinq.Core/Element/Single/Single.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Element/Single/SingleAsync.AsyncValueEnumerable.cs (97%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/Where/Where.ArraySegment.cs (81%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/Where/Where.AsyncValueEnumerable.cs (84%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/Where/Where.ReadOnlyMemory.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/Where/Where.ReadOnlySpan.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/Where/Where.ValueEnumerable.cs (83%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs (83%) create mode 100644 NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/Where/WhereEnumerator.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs (80%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs (85%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs (84%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs (84%) create mode 100644 NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/Where/WhereAt/WhereAtEnumerator.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs (76%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs (86%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs (90%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs (83%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs (84%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Generation/AsyncValueEnumerable/Empty.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Generation/AsyncValueEnumerable/Range.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Generation/AsyncValueEnumerable/Repeat.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Generation/AsyncValueEnumerable/Return.cs (72%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Generation/ValueEnumerable/CreateValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Generation/ValueEnumerable/Empty.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Generation/ValueEnumerable/Range.cs (92%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Generation/ValueEnumerable/Repeat.cs (97%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Generation/ValueEnumerable/Return.cs (88%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/GlobalSuppressions.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Lease.cs (100%) create mode 100644 NetFabric.Hyperlinq.Core/NetFabric.Hyperlinq.Core.csproj rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Option/NoneOption.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Option/Option.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/Skip/Skip.AsyncValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/Skip/Skip.ReadOnlyList.cs (94%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/Skip/Skip.ValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/Skip/Skip.ValueReadOnlyCollection.cs (100%) create mode 100644 NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs (88%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs (82%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/Take/Take.AsyncValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/Take/Take.ReadOnlyList.cs (94%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/Take/Take.ValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Partitioning/Take/Take.ValueReadOnlyCollection.cs (100%) create mode 100644 NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/Select/Select.ArraySegment.cs (73%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/Select/Select.AsyncValueEnumerable.cs (92%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/Select/Select.ReadOnlyMemory.cs (84%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/Select/Select.ReadOnlySpan.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/Select/Select.ValueEnumerable.cs (86%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/Select/Select.ValueReadOnlyCollection.cs (77%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/Select/Select.ValueReadOnlyList.cs (81%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/Select/SelectEnumerator.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectAt/SelectAt.ArraySegment.cs (81%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs (92%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs (83%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs (86%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs (78%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs (81%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectAt/SelectAtEnumerator.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectVector/SelectVector.Range.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs (88%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs (88%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs (99%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs (86%) create mode 100644 NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyCollection.cs create mode 100644 NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.Core/Properties/AssemblyInfo.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/All/All.ReadOnlySpan.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/All/All.ValueEnumerable.cs (61%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/All/All.ValueReadOnlyCollection.cs (57%) create mode 100644 NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/All/AllAsync.AsyncValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/Any/Any.ReadOnlySpan.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/Any/Any.ValueEnumerable.cs (66%) rename {NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source => NetFabric.Hyperlinq.Core/Quantifier/Any}/Any.ValueReadOnlyCollection.cs (78%) create mode 100644 NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/Any/AnyAsync.AsyncValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/Contains/Contains.Enumerable.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/Contains/Contains.ReadOnlySpan.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/Contains/Contains.ValueEnumerable.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs (97%) create mode 100644 NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs (98%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Quantifier/ContainsVector/ContainsVector.Span.cs (82%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Resource.Designer.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Resource.resx (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Set/Distinct/Distinct.ArraySegment.cs (58%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Set/Distinct/Distinct.AsyncValueEnumerable.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Set/Distinct/Distinct.ReadOnlyMemory.cs (59%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Set/Distinct/Distinct.ReadOnlySpan.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Set/Distinct/Distinct.ValueEnumerable.cs (100%) create mode 100644 NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueReadOnlyCollection.cs create mode 100644 NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Set/Distinct/Set.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/ArrayBuilder/ArrayBuilder.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/ArrayBuilder/LargeArrayBuilder.cs (100%) create mode 100644 NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs (96%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs (97%) create mode 100644 NetFabric.Hyperlinq.Core/Utils/ArrayExtensions.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/ArrayPoolExtensions.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/ArraySegmentExtensions.cs (70%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/BooleanExtensions.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/Copy/Copy.Range.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/Copy/Copy.ReadOnlySpan.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/Copy/Copy.ValueReadOnlyCollection.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/Default.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/EnumeratorState.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/FunctionCombination/AsyncPredicateCombination.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/FunctionCombination/AsyncSelectorCombination.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/FunctionCombination/PredicateCombination.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/FunctionCombination/PredicateInCombination.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/FunctionCombination/SelectorCombination.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/IndexOf/IndexOf.ReadOnlySpan.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/IndexOf/IndexOf.ValueReadOnlyCollection.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/IntExtensions.cs (100%) create mode 100644 NetFabric.Hyperlinq.Core/Utils/MemoryExtensions.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/Scalar.cs (100%) create mode 100644 NetFabric.Hyperlinq.Core/Utils/SpanExtensions.cs rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/Throw.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/ThrowIfArgument.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/Utils.AllocateUninitializedArray.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/Utils.EqualityComparer.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/Utils.SkipTake.cs (100%) rename {NetFabric.Hyperlinq => NetFabric.Hyperlinq.Core}/Utils/VectorExtensions.cs (100%) delete mode 100644 NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunction.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunctionWrapper.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Option.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/PredicateCombination.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/SelectorCombination.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Contains.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/First.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ToDictionary.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj delete mode 100644 NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator/Properties/AssemblyInfo.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator/Utils/CodeBuilder.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/GenerateSourceTests.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/Empty.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty2.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty3.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.IReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Repeat.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestCollection.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestList.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/Enumerables.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/ItemTypes.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/ValueEnumerables.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/Count.Array.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/Count.Span.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/Select.Array.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/Select.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/Skip.Take.Array.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/TestData/Source/Where.Array.cs create mode 100644 NetFabric.Hyperlinq.UnitTests/Verifier.cs rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Attributes/GeneratorBindingsAttribute.cs (100%) rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Attributes/GeneratorIgnoreAttribute.cs (100%) rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Attributes/GeneratorMappingAttribute.cs (100%) rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/CompilationContext.cs (98%) delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs create mode 100644 NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq/Generator.cs create mode 100644 NetFabric.Hyperlinq/ITypeSymbolExtensions.cs create mode 100644 NetFabric.Hyperlinq/MethodSignature.cs delete mode 100644 NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyCollection.cs create mode 100644 NetFabric.Hyperlinq/SyntaxReceiver.cs create mode 100644 NetFabric.Hyperlinq/TypeSymbolsCache.cs rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Utils/AttributeExtensions.cs (100%) create mode 100644 NetFabric.Hyperlinq/Utils/CodeBuilder.cs rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Utils/DictionarySet.cs (100%) rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Utils/MethodSymbolExtensions.cs (98%) rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Utils/NamespaceSymbolExtensions.cs (100%) rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Utils/StringExtensions.cs (100%) rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Utils/SymbolExtensions.cs (100%) rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Utils/TypeParameterSymbolExtensions.cs (100%) create mode 100644 NetFabric.Hyperlinq/Utils/TypeSymbolConversionComparer.cs rename {NetFabric.Hyperlinq.SourceGenerator => NetFabric.Hyperlinq}/Utils/TypeSymbolExtensions.cs (100%) create mode 100644 NetFabric.Hyperlinq/ValueEnumerableType.cs diff --git a/.editorconfig b/.editorconfig index 4cead120d..b4a841bef 100755 --- a/.editorconfig +++ b/.editorconfig @@ -68,14 +68,14 @@ csharp_style_var_for_built_in_types = true:error csharp_style_var_when_type_is_apparent = true:error # Expression-bodied members -csharp_style_expression_bodied_accessors = true:error -csharp_style_expression_bodied_constructors = true:error -csharp_style_expression_bodied_indexers = true:error -csharp_style_expression_bodied_lambdas = true:error -csharp_style_expression_bodied_local_functions = true:error -csharp_style_expression_bodied_methods = true:error -csharp_style_expression_bodied_operators = true:error -csharp_style_expression_bodied_properties = true:error +csharp_style_expression_bodied_accessors =true:warning +csharp_style_expression_bodied_constructors =true:warning +csharp_style_expression_bodied_indexers =true:warning +csharp_style_expression_bodied_lambdas =true:warning +csharp_style_expression_bodied_local_functions =true:warning +csharp_style_expression_bodied_methods =true:warning +csharp_style_expression_bodied_operators =true:warning +csharp_style_expression_bodied_properties =true:warning # Pattern matching preferences csharp_style_pattern_matching_over_as_with_null_check = true:error @@ -101,7 +101,7 @@ csharp_style_pattern_local_over_anonymous_function = true:error csharp_style_prefer_index_operator = true:warning csharp_style_prefer_range_operator = true:warning csharp_style_throw_expression = true:error -csharp_style_unused_value_assignment_preference = discard_variable:error +csharp_style_unused_value_assignment_preference =discard_variable:warning csharp_style_unused_value_expression_statement_preference = discard_variable:error # 'using' directive preferences @@ -216,3 +216,6 @@ dotnet_naming_style.camel_case.required_prefix = dotnet_naming_style.camel_case.required_suffix = dotnet_naming_style.camel_case.word_separator = dotnet_naming_style.camel_case.capitalization = camel_case + +[*.{cs,vb}] +dotnet_code_quality_unused_parameters=all:warning \ No newline at end of file diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index a6013e986..f8ebf0884 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -10,9 +10,10 @@ jobs: - name: Check out repository uses: actions/checkout@v2 - name: Setup .NET Core - uses: actions/setup-dotnet@v1.7.2 + uses: actions/setup-dotnet@v1 with: - dotnet-version: '6.0.100-preview.2.21155.3' + dotnet-version: '6.0.x' + include-prerelease: true - name: Test source generator run: dotnet test ./NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj - name: Build solution diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index c34ffc150..cc4e2de24 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -4,6 +4,7 @@ net6.0 false true + true @@ -14,7 +15,7 @@ - + diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Count/Count.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Count/Count.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Count/Count.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Count/Count.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Count/CountAsync.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs b/NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum.TestData.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Aggregation/Sum.TestData.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum.TestData.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum/Sum.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum/Sum.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum/Sum.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Aggregation/Sum/SumAsync.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Dictionary.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Dictionary.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Dictionary.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Dictionary.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSet.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSet.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSet.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSet.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueue.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueue.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueue.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueue.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Queue.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Queue.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Queue.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Queue.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionary.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionary.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionary.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionary.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSet.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSet.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSet.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSet.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Stack.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Stack.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Stack.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/Stack.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ArrayBuilder.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ArrayBuilder.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ArrayBuilder.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ArrayBuilder.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/LargeArrayBuilder.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArray.ReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArray.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArray.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArray.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToList.ReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToList.ReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToList.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToList.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToList.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToList.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToList.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Conversion/ToList/ToListAsync.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt.TestData.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/ElementAt.TestData.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt.TestData.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAt.ReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAt.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAt.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAt.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAt.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAt.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/First/First.ReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/First/First.ReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/First/First.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/First/First.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/First/First.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/First/First.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/First/FirstAsync.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/Single/Single.ReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/Single/Single.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/Single/Single.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/Single/Single.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/Single/Single.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/Single/Single.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Element/Single/SingleAsync.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ArraySegment.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ReadOnlyMemory.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlyMemory.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ReadOnlyMemory.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/Where/Where.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ArraySegment.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ArraySegment.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ArraySegment.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyMemory.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyMemory.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlyMemory.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereAt/WhereAt.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ArraySegment.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ArraySegment.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ArraySegment.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlyMemory.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Filtering/WhereSelect/WhereSelect.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Empty.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/AsyncValueEnumerable/Empty.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Empty.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/AsyncValueEnumerable/Empty.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/AsyncValueEnumerable/Range.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/AsyncValueEnumerable/Repeat.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Return.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/AsyncValueEnumerable/Return.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/AsyncValueEnumerable/Return.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/AsyncValueEnumerable/Return.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/Range.TestData.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/Range.TestData.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/Range.TestData.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/Repeat.TestData.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/Repeat.TestData.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/Repeat.TestData.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/Return.TestData.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/Return.TestData.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/Return.TestData.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Empty.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/ValueEnumerable/Empty.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Empty.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/ValueEnumerable/Empty.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/ValueEnumerable/Range.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Range.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/ValueEnumerable/Range.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Repeat.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/ValueEnumerable/Repeat.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Repeat.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/ValueEnumerable/Repeat.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Return.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Generation/ValueEnumerable/Return.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Generation/ValueEnumerable/Return.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Generation/ValueEnumerable/Return.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/GlobalSuppressions.cs b/NetFabric.Hyperlinq.Core.UnitTests/GlobalSuppressions.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/GlobalSuppressions.cs rename to NetFabric.Hyperlinq.Core.UnitTests/GlobalSuppressions.cs diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj b/NetFabric.Hyperlinq.Core.UnitTests/NetFabric.Hyperlinq.Core.UnitTests.csproj similarity index 53% rename from NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj rename to NetFabric.Hyperlinq.Core.UnitTests/NetFabric.Hyperlinq.Core.UnitTests.csproj index 6e60efb64..d7c4ddcb2 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj +++ b/NetFabric.Hyperlinq.Core.UnitTests/NetFabric.Hyperlinq.Core.UnitTests.csproj @@ -1,34 +1,36 @@  - net6.0 - + net48;netcoreapp2.1;netcoreapp3.1;net6.0 false - + - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - - - runtime; build; native; contentfiles; analyzers; buildtransitive + all - - runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers - + - - Always - + diff --git a/NetFabric.Hyperlinq.UnitTests/Option/Option.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Option/Option.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Option/Option.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Option/Option.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs b/NetFabric.Hyperlinq.Core.UnitTests/Option/TestData.Option.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Option/TestData.Option.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Option/TestData.Option.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip.TestData.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Skip.TestData.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip.TestData.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip/Skip.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip/Skip.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Skip/Skip.ValueReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/SkipTake.TestData.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/SkipTake.TestData.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/SkipTake.TestData.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take.TestData.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Take.TestData.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take.TestData.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take/Take.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take/Take.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take/Take.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take/Take.ValueReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Partitioning/Take/Take.ValueReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Partitioning/Take/Take.ValueReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ArraySegment.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ReadOnlyMemory.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlyMemory.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ReadOnlyMemory.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ValueReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/Select/Select.ValueReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/Select/Select.ValueReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ArraySegment.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ArraySegment.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ArraySegment.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyMemory.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyMemory.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ReadOnlyMemory.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyList.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyList.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyList.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectAt/SelectAt.ValueReadOnlyList.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectVector.TestData.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/SelectVector.TestData.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectVector.TestData.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectVector/SelectVector.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Projection/SelectVector/SelectVector.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Projection/SelectVector/SelectVector.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/All/All.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/All/All.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/All/All.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/All/All.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/All/All.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/All/All.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Any/Any.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Any/Any.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Any/Any.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Any/Any.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Any/Any.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Any/Any.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Contains/Contains.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Contains/Contains.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Contains/Contains.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/Contains/Contains.ValueReadOnlyCollection.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.ArraySegment.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.AsyncValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.ReadOnlyMemory.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.ReadOnlySpan.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs b/NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Set/Distinct/Distinct.ValueEnumerable.Tests.cs diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs b/NetFabric.Hyperlinq.Core.UnitTests/TestData/TestData.Empty.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/TestData/TestData.Empty.cs rename to NetFabric.Hyperlinq.Core.UnitTests/TestData/TestData.Empty.cs diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs b/NetFabric.Hyperlinq.Core.UnitTests/TestData/TestData.Multiple.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/TestData/TestData.Multiple.cs rename to NetFabric.Hyperlinq.Core.UnitTests/TestData/TestData.Multiple.cs diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs b/NetFabric.Hyperlinq.Core.UnitTests/TestData/TestData.Single.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/TestData/TestData.Single.cs rename to NetFabric.Hyperlinq.Core.UnitTests/TestData/TestData.Single.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/DelegateExtensions.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/DelegateExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Utils/DelegateExtensions.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/DelegateExtensions.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/SpanExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Utils/SpanExtensions.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/SpanExtensions.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/TestComparer.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Utils/TestComparer.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/TestComparer.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs similarity index 77% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs index 8579095be..027b9b9ad 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs @@ -28,11 +28,7 @@ public AsyncEnumerator GetAsyncEnumerator() IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AsyncEnumerableExtensions.AsyncValueEnumerable, AsyncEnumerator, AsyncEnumerator, T, GetAsyncEnumeratorFunction, GetAsyncEnumeratorFunction> AsAsyncValueEnumerable() - => this.AsAsyncValueEnumerable, AsyncEnumerator, T, GetAsyncEnumeratorFunction>(); - + public readonly struct GetAsyncEnumeratorFunction : IFunction, CancellationToken, AsyncEnumerator> { diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs similarity index 78% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs index cd44977d7..08841b05f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs @@ -31,10 +31,6 @@ AsyncEnumerator IAsyncValueEnumerable>.GetAsyncEnumerat IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AsyncValueEnumerableExtensions.AsyncValueEnumerable, AsyncEnumerator, AsyncEnumerator, T, GetAsyncEnumeratorFunction, GetAsyncEnumeratorFunction> AsAsyncValueEnumerable() - => AsyncValueEnumerableExtensions.AsAsyncValueEnumerable, AsyncEnumerator, T, GetAsyncEnumeratorFunction>(this); public readonly struct GetAsyncEnumeratorFunction : IFunction, CancellationToken, AsyncEnumerator> diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsCollection.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs similarity index 81% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs index 088e62d28..bb738371e 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs @@ -31,10 +31,6 @@ IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public EnumerableExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() - => this.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(); public readonly struct GetEnumeratorFunction : IFunction, Enumerator> diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsFunctionIn.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsFunctionIn.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsFunctionIn.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsFunctionIn.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsList.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsList.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsList.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs similarity index 55% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs index 8d006b69c..bcb16a3ed 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyCollection.cs @@ -24,16 +24,6 @@ public ReadOnlyCollectionWrapper(T[] source) public int Count => source.Length; - - public new ReadOnlyCollectionExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() - => ReadOnlyCollectionExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); - - public new readonly struct GetEnumeratorFunction - : IFunction, Enumerator> - { - public Enumerator Invoke(ReadOnlyCollectionWrapper enumerable) - => enumerable.GetEnumerator(); - } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs similarity index 81% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs index c8218969f..1948c72dd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsReadOnlyList.cs @@ -24,9 +24,6 @@ internal ReadOnlyListWrapper(T[] source) public T this[int index] => source[index]; - - public new ReadOnlyListExtensions.ValueEnumerable, T> AsValueEnumerable() - => this.AsValueEnumerable, T>(); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs similarity index 69% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs index d09834452..05cdb1dcd 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueCollection.cs @@ -51,18 +51,6 @@ bool ICollection.Remove(T item) => throw new NotSupportedException(); void ICollection.Clear() => throw new NotSupportedException(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyCollectionExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() - => ValueReadOnlyCollectionExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); - - public readonly struct GetEnumeratorFunction - : IFunction, Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator Invoke(ValueCollectionWrapper enumerable) - => enumerable.GetEnumerator(); - } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs similarity index 79% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs index efa262bde..63dff6ba2 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs @@ -32,10 +32,6 @@ IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() - => ValueEnumerableExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); public readonly struct GetEnumeratorFunction : IFunction, Enumerator> diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs similarity index 75% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs index ef1f3889b..4033031c9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueList.cs @@ -68,18 +68,6 @@ void IList.Insert(int index, T item) => throw new NotSupportedException(); void IList.RemoveAt(int index) => throw new NotSupportedException(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() - => ValueReadOnlyListExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); - - public readonly struct GetEnumeratorFunction - : IFunction, Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator Invoke(ValueListWrapper enumerable) - => enumerable.GetEnumerator(); - } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs similarity index 60% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs index 26ff0ffbc..8128eead9 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyCollection.cs @@ -35,18 +35,6 @@ IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyCollectionExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() - => ReadOnlyCollectionExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); - - public readonly struct GetEnumeratorFunction - : IFunction, Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator Invoke(ValueReadOnlyCollectionWrapper enumerable) - => enumerable.GetEnumerator(); - } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs similarity index 62% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs index 8882b862e..f4b6c386c 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsValueReadOnlyList.cs @@ -38,18 +38,6 @@ IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() - => ValueReadOnlyListExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); - - public readonly struct GetEnumeratorFunction - : IFunction, Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator Invoke(ValueReadOnlyListWrapper enumerable) - => enumerable.GetEnumerator(); - } } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.AsyncEnumerator.cs diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.Enumerator.cs b/NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.Enumerator.cs similarity index 100% rename from NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.Enumerator.cs rename to NetFabric.Hyperlinq.Core.UnitTests/Utils/Wrappers/Wrap.Enumerator.cs diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ReadOnlySpan.cs similarity index 68% rename from NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ReadOnlySpan.cs index 72c8dc7a5..f2470d7bf 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ReadOnlySpan.cs @@ -6,14 +6,14 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - static int Count(this ReadOnlySpan source) + public static int Count(ReadOnlySpan source) => source.Length; [MethodImpl(MethodImplOptions.AggressiveInlining)] - static int Count(this ReadOnlySpan source, Func predicate) + public static int Count(ReadOnlySpan source, Func predicate) => source.Count(new FunctionWrapper(predicate)); - static int Count(this ReadOnlySpan source, TPredicate predicate = default) + public static int Count(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate: struct, IFunction { var counter = 0; @@ -25,10 +25,10 @@ static int Count(this ReadOnlySpan source, TPredic } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static int Count(this ReadOnlySpan source, Func predicate) + public static int Count(this ReadOnlySpan source, Func predicate) => source.CountAt(new FunctionWrapper(predicate)); - static int CountAt(this ReadOnlySpan source, TPredicate predicate = default) + public static int CountAt(this ReadOnlySpan source, TPredicate predicate = default) where TPredicate: struct, IFunction { var counter = 0; diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueEnumerable.cs similarity index 68% rename from NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueEnumerable.cs index f7eef5479..4e033636d 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueEnumerable.cs @@ -20,12 +20,6 @@ public static int Count(this TEnumerable sour return counter; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.Count>(new FunctionWrapper(predicate)); - public static int Count(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -40,12 +34,6 @@ public static int Count(this TEnu } return counter; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.CountAt>(new FunctionWrapper(predicate)); public static int CountAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueReadOnlyCollection.cs similarity index 64% rename from NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueReadOnlyCollection.cs index 0dd554836..6481d6078 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueReadOnlyCollection.cs @@ -6,17 +6,12 @@ namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyCollectionExtensions { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this TEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator => source.Count; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this TEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => Count>(source, new FunctionWrapper(predicate)); - public static int Count(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -26,12 +21,6 @@ public static int Count(this TEnu {Count: 0} => 0, _ => ValueEnumerableExtensions.Count(source, predicate) }; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this TEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => CountAt>(source, new FunctionWrapper(predicate)); public static int CountAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueReadOnlyList.cs new file mode 100644 index 000000000..11f843b7c --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Aggregation/Count/Count.ValueReadOnlyList.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this TEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.Count(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this TEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TPredicate: struct, IFunction + => ValueReadOnlyCollectionExtensions.Count(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountAt(this TEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TPredicate: struct, IFunction + => ValueReadOnlyCollectionExtensions.CountAt(source, predicate); + + } +} + diff --git a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs similarity index 73% rename from NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs index 152bad6f5..efa84676e 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Aggregation/Count/CountAsync.AsyncValueEnumerable.cs @@ -29,12 +29,6 @@ public static async ValueTask CountAsync return counter; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueTask CountAsync(this TEnumerable source, Func> predicate, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - => source.CountAsync>(new AsyncFunctionWrapper(predicate), cancellationToken); - public static async ValueTask CountAsync(this TEnumerable source, TPredicate predicate = default, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -60,12 +54,6 @@ public static async ValueTask CountAsync CountAsync(this TEnumerable source, Func> predicate, CancellationToken cancellationToken = default) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - => source.CountAtAsync>(new AsyncFunctionWrapper(predicate), cancellationToken); - public static async ValueTask CountAtAsync(this TEnumerable source, TPredicate predicate = default, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.Range.cs similarity index 97% rename from NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs rename to NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.Range.cs index 389af6bed..3ca8d9949 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs +++ b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.Range.cs @@ -10,9 +10,7 @@ public static partial class ValueEnumerable static int SumRange(int start, int count) => count * (start + start + count) / 2; - [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SkipLocalsInit] static unsafe TResult SumRange(int start, int count, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ReadOnlySpan.cs similarity index 97% rename from NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ReadOnlySpan.cs index 197420b85..d3e87fe90 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ReadOnlySpan.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore] + static TSum Sum(this ReadOnlySpan source) where TSum : struct { @@ -26,7 +26,7 @@ static TSum Sum(this ReadOnlySpan source) return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum SumVector(this ReadOnlySpan source) where TSource : struct where TSum : struct @@ -44,7 +44,7 @@ static TSum SumVector(this ReadOnlySpan source) return Scalar.Add(vectorSum.Sum(), Sum(source.Slice(source.Length - count, count))); } - [GeneratorIgnore] + static TSum Sum(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction where TSum : struct @@ -66,7 +66,7 @@ static TSum Sum(this ReadOnlySpan source, TP return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum SumAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction where TSum : struct @@ -89,7 +89,7 @@ static TSum SumAt(this ReadOnlySpan source, return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum Sum(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction where TSum : struct @@ -110,7 +110,7 @@ static TSum Sum(this ReadOnlySpan so return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum SumVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction @@ -131,7 +131,7 @@ static TSum SumVector(this R return Scalar.Add(vectorSum.Sum(), Sum(source.Slice(source.Length - count, count), selector)); } - [GeneratorIgnore] + static TSum SumAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction where TSum : struct @@ -153,7 +153,7 @@ static TSum SumAt(this ReadOnlySpan return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum Sum(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueEnumerable.cs similarity index 94% rename from NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueEnumerable.cs index 1cc64d0c4..29ab70c16 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueEnumerable.cs @@ -4,8 +4,8 @@ namespace NetFabric.Hyperlinq { public static partial class ValueEnumerableExtensions { - [GeneratorIgnore] - internal static TSum Sum(this TEnumerable source) + + public static TSum Sum(this TEnumerable source) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator where TSum : struct @@ -17,7 +17,7 @@ internal static TSum Sum(this TEnumerab return sum; } - [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -34,7 +34,7 @@ internal static TSum Sum(th return sum; } - [GeneratorIgnore] + internal static TSum SumAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -51,7 +51,7 @@ internal static TSum SumAt( return sum; } - [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -68,7 +68,7 @@ internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -85,7 +85,7 @@ internal static TSum SumAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs similarity index 93% rename from NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs index be0c80100..18b1702ee 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs @@ -4,8 +4,8 @@ namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorIgnore] - internal static TSum Sum(this TEnumerable source) + + public static TSum Sum(this TEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator where TSum : struct @@ -15,7 +15,7 @@ internal static TSum Sum(this TEnumerab _ => ValueEnumerableExtensions.Sum(source) }; - [GeneratorIgnore] + static TSum Sum(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -27,7 +27,7 @@ static TSum Sum(this TEnume _ => ValueEnumerableExtensions.Sum(source, predicate) }; - [GeneratorIgnore] + static TSum SumAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -39,7 +39,7 @@ static TSum SumAt(this TEnu _ => ValueEnumerableExtensions.SumAt(source, predicate) }; - [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -51,7 +51,7 @@ internal static TSum Sum ValueEnumerableExtensions.Sum(source, selector) }; - [GeneratorIgnore] + internal static TSum SumAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -63,7 +63,7 @@ internal static TSum SumAt ValueEnumerableExtensions.SumAt(source, selector) }; - [GeneratorIgnore] + static TSum Sum(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueReadOnlyList.cs new file mode 100644 index 000000000..3df49ac22 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Aggregation/Sum/Sum.ValueReadOnlyList.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static TSum Sum(this TEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSum : struct + => ValueReadOnlyCollectionExtensions.Sum(source); + } +} + diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs similarity index 97% rename from NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs index 7727606b0..442427cd2 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { - [GeneratorIgnore] + public static async ValueTask SumAsync(this TEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -26,7 +26,7 @@ public static async ValueTask SumAsync SumAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -51,7 +51,7 @@ internal static async ValueTask SumAsync SumAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -76,7 +76,7 @@ internal static async ValueTask SumAtAsync SumAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -100,7 +100,7 @@ internal static async ValueTask SumAsync SumAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -124,7 +124,7 @@ internal static async ValueTask SumAtAsync SumAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsAsyncEnumerable/AsAsyncEnumerable.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncEnumerable.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs similarity index 98% rename from NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs index 09046a183..b0b7bffb5 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs @@ -14,7 +14,6 @@ public static AsyncValueEnumerable AsAsyncValueEnumerable< where TEnumerator : struct, IAsyncEnumerator => new(source); - [GeneratorBindings(source: "source", sourceImplements: "IAsyncValueEnumerable`2", enumerableType: "IAsyncValueEnumerable")] [StructLayout(LayoutKind.Auto)] public readonly partial struct AsyncValueEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs similarity index 99% rename from NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs index ea9b2f9c8..f418e35d8 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs @@ -11,14 +11,14 @@ namespace NetFabric.Hyperlinq public static partial class AsyncEnumerableExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator) where TEnumerable : IAsyncEnumerable where TEnumerator : struct, IAsyncEnumerator => AsAsyncValueEnumerable>(source, new FunctionWrapper(getAsyncEnumerator)); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default) where TEnumerable : IAsyncEnumerable @@ -26,7 +26,7 @@ public static AsyncValueEnumerable => new(source, getAsyncEnumerator, getAsyncEnumerator); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator, Func getAsyncEnumerator2) where TEnumerable : IAsyncEnumerable @@ -34,7 +34,7 @@ public static AsyncValueEnumerable AsAsyncValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getAsyncEnumerator), new FunctionWrapper(getAsyncEnumerator2)); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default, TGetAsyncEnumerator2 getAsyncEnumerator2 = default) where TEnumerable : IAsyncEnumerable @@ -54,8 +54,10 @@ public partial struct AsyncValueEnumerable { readonly TEnumerable source; +#pragma warning disable IDE0044 // Add readonly modifier TGetAsyncEnumerator getAsyncEnumerator; TGetAsyncEnumerator2 getAsyncEnumerator2; +#pragma warning restore IDE0044 // Add readonly modifier internal AsyncValueEnumerable(TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator, TGetAsyncEnumerator2 getAsyncEnumerator2) => (this.source, this.getAsyncEnumerator, this.getAsyncEnumerator2) = (source, getAsyncEnumerator, getAsyncEnumerator2); diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs similarity index 98% rename from NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs index 7fc40740b..c54d790ba 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs @@ -10,14 +10,14 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator => AsAsyncValueEnumerable>(source, new FunctionWrapper(getAsyncEnumerator)); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default) where TEnumerable : IAsyncValueEnumerable @@ -25,7 +25,7 @@ public static AsyncValueEnumerable => new(source, getAsyncEnumerator, getAsyncEnumerator); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator, Func getAsyncEnumerator2) where TEnumerable : IAsyncValueEnumerable @@ -33,7 +33,7 @@ public static AsyncValueEnumerable AsAsyncValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getAsyncEnumerator), new FunctionWrapper(getAsyncEnumerator2)); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default, TGetAsyncEnumerator2 getAsyncEnumerator2 = default) where TEnumerable : IAsyncValueEnumerable @@ -43,7 +43,6 @@ public static AsyncValueEnumerable => new(source, getAsyncEnumerator, getAsyncEnumerator2); - [GeneratorBindings(source: "source", sourceImplements: "IAsyncValueEnumerable`2")] [StructLayout(LayoutKind.Auto)] public partial struct AsyncValueEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsyncValueEnumerator.cs b/NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsyncValueEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsyncValueEnumerator.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsAsyncValueEnumerable/AsyncValueEnumerator.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsEnumerable/AsEnumerable.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs similarity index 93% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs index b9cd3a2dc..318d761c2 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs @@ -6,7 +6,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ArraySegmentValueEnumerable AsValueEnumerable(this TSource[] source) => new(new ArraySegment(source)); diff --git a/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs new file mode 100644 index 000000000..c39e49457 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -0,0 +1,240 @@ +using System; +using System.Buffers; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ArrayExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ArraySegmentValueEnumerable AsValueEnumerable(this ArraySegment source) + => new(source); + + [StructLayout(LayoutKind.Auto)] + public readonly partial struct ArraySegmentValueEnumerable + : IValueReadOnlyList.DisposableEnumerator> + , IList + { + internal readonly ArraySegment source; + + internal ArraySegmentValueEnumerable(ArraySegment source) + => this.source = source; + + public int Count + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source.Count; + } + + public TSource this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ThrowIfArgument.OutOfRange(index, Count, nameof(index)); + return source.Array![source.Offset + index]; + } + } + + TSource IList.this[int index] + { + get => this[index]; + + [ExcludeFromCodeCoverage] + // ReSharper disable once ValueParameterNotUsed + set => Throw.NotSupportedException(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SpanEnumerator GetEnumerator() + => new(source); + + DisposableEnumerator IValueEnumerable.GetEnumerator() + => new(source); + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => new DisposableEnumerator(source); + + IEnumerator IEnumerable.GetEnumerator() + // ReSharper disable once HeapView.BoxingAllocation + => new DisposableEnumerator(source); + + + bool ICollection.IsReadOnly + => true; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(Span span) + => source.AsReadOnlySpan().CopyTo(span); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TSource[] array, int arrayIndex) + => ((ICollection)source).CopyTo(array, arrayIndex); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TSource item) + => ((ICollection)source).Contains(item); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int IndexOf(TSource item) + => ((IList)source).IndexOf(item); + + [ExcludeFromCodeCoverage] + void ICollection.Add(TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + bool ICollection.Remove(TSource item) + => Throw.NotSupportedException(); + [ExcludeFromCodeCoverage] + void ICollection.Clear() + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void IList.Insert(int index, TSource item) + => Throw.NotSupportedException(); + + [ExcludeFromCodeCoverage] + void IList.RemoveAt(int index) + => Throw.NotSupportedException(); + + [StructLayout(LayoutKind.Auto)] + public struct DisposableEnumerator + : IEnumerator + { + readonly ArraySegment source; + int index; + + internal DisposableEnumerator(ArraySegment source) + { + this.source = source; + index = -1; + } + + public readonly TSource Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source.Array![source.Offset + index]; + } + readonly object? IEnumerator.Current + // ReSharper disable once HeapView.PossibleBoxingAllocation + => Current; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() + => ++index < source.Count; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [ExcludeFromCodeCoverage] + public void Reset() + => index = -1; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly void Dispose() { } + } + + #region Partitioning + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ArraySegmentValueEnumerable Skip(int count) + { + var (newOffset, newCount) = Utils.Skip(source.Count, count); + return new ArraySegmentValueEnumerable(new ArraySegment(source.Array!, source.Offset + newOffset, newCount)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ArraySegmentValueEnumerable Take(int count) + => new(new ArraySegment(source.Array!, source.Offset, Utils.Take(source.Count, count))); + + #endregion + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nint Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static nuint Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().SumVector(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal Sum(this ArraySegmentValueEnumerable source) + => source.source.AsReadOnlySpan().Sum(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool ContainsVector(this ArraySegmentValueEnumerable source, TSource value) + where TSource : struct + => source.source.AsReadOnlySpan().ContainsVector(value); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ArraySegmentValueEnumerable source, Func, Vector> vectorSelector, Func selector) + where TSource : struct + where TResult : struct + => source.source.AsReadOnlySpan().SelectVector(vectorSelector, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SpanSelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TSelector selector = default) + where TSelector : struct, IFunction, Vector>, IFunction + where TSource : struct + where TResult : struct + => source.source.AsReadOnlySpan().SelectVector(selector, selector); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static SpanSelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TVectorSelector vectorSelector = default, TSelector selector = default) + where TVectorSelector : struct, IFunction, Vector> + where TSelector : struct, IFunction + where TSource : struct + where TResult : struct + => source.source.AsReadOnlySpan().SelectVector(vectorSelector, selector); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArrayExtensions.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ImmutableArray.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArrayExtensions.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ImmutableArray.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.List.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.List.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs similarity index 76% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs index ce41542a3..7b25a3c4e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs @@ -6,9 +6,8 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static MemoryValueEnumerable AsValueEnumerable(this Memory source) - => ((ReadOnlyMemory)source).AsValueEnumerable(); + => source.AsReadOnlyMemory().AsValueEnumerable(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs similarity index 91% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index 621f02484..d58c7cf91 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -11,12 +11,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static MemoryValueEnumerable AsValueEnumerable(this ReadOnlyMemory source) => new(source); - [GeneratorBindings(source: "source.Span", sourceImplements: "ReadOnlySpan`1")] [StructLayout(LayoutKind.Auto)] public readonly partial struct MemoryValueEnumerable : IValueReadOnlyList.DisposableEnumerator> @@ -236,28 +235,6 @@ public MemoryDistinctEnumerable Distinct(IEqualityComparer? co #endregion } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemoryValueEnumerable source) - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemoryValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemoryValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemoryValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this MemoryValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.CountAt(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this MemoryValueEnumerable source) => source.source.Span.SumVector(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs similarity index 54% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index 3d8b97c67..ac5a927cf 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -10,12 +10,10 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SpanValueEnumerable AsValueEnumerable(this ReadOnlySpan source) => new(source); - [GeneratorBindings(source: "source", sourceImplements: "ReadOnlySpan`1")] [StructLayout(LayoutKind.Auto)] public readonly ref partial struct SpanValueEnumerable { @@ -24,6 +22,12 @@ public readonly ref partial struct SpanValueEnumerable internal SpanValueEnumerable(ReadOnlySpan source) => this.source = source; + public ReadOnlySpan Span + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source; + } + public int Count { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -39,48 +43,6 @@ public TSource this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] public SpanEnumerator GetEnumerator() => new(source); - - #region Aggregation - - #endregion - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanValueEnumerable AsEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanValueEnumerable AsValueEnumerable() - => this; - - #endregion - - #region Element - - #endregion - - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanWhereEnumerable> Where(Func predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanWhereEnumerable Where(TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanWhereAtEnumerable> Where(Func predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanWhereAtEnumerable WhereAt(TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.WhereAt(predicate); - - #endregion #region Partitioning @@ -97,53 +59,6 @@ public SpanValueEnumerable Take(int count) #endregion - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectEnumerable> Select(Func selector) - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectEnumerable Select(TSelector selector = default) - where TSelector : struct, IFunction - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectAtEnumerable> Select(Func selector) - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectAtEnumerable SelectAt(TSelector selector = default) - where TSelector : struct, IFunction - => source.SelectAt(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectManyEnumerable> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => source.SelectMany(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectManyEnumerable SelectMany(TSelector selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.SelectMany(selector); - - #endregion - - #region Quantifier - - #endregion - - #region Set - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanDistinctEnumerable Distinct(IEqualityComparer? comparer = default) - => source.Distinct(comparer); - - #endregion - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) { comparer ??= EqualityComparer.Default; @@ -167,28 +82,6 @@ public bool SequenceEqual(IEnumerable other, IEqualityComparer } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanValueEnumerable source) - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this SpanValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.CountAt(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SpanValueEnumerable source) => source.source.SumVector(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs similarity index 77% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs index 821f8da57..3384b4eac 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs @@ -6,9 +6,9 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SpanValueEnumerable AsValueEnumerable(this Span source) - => ((ReadOnlySpan)source).AsValueEnumerable(); + => source.AsReadOnlySpan().AsValueEnumerable(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/SpanEnumerator.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/SpanEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/SpanEnumerator.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/SpanEnumerator.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/ValueEnumerator.cs b/NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/ValueEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/ValueEnumerator.cs rename to NetFabric.Hyperlinq.Core/Conversion/AsValueEnumerable/ValueEnumerator.cs diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ReadOnlySpan.cs similarity index 96% rename from NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ReadOnlySpan.cs index c7343d194..844bf3341 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -23,7 +23,6 @@ public static Lease ToArray(this ReadOnlySpan source, ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] static TSource[] ToArray(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -34,7 +33,6 @@ static TSource[] ToArray(this ReadOnlySpan source, return arrayBuilder.ToArray(); } - [GeneratorIgnore] static Lease ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { @@ -48,7 +46,6 @@ static Lease ToArray(this ReadOnlySpan so ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] static TSource[] ToArrayAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -59,7 +56,6 @@ static TSource[] ToArrayAt(this ReadOnlySpan sourc return arrayBuilder.ToArray(); } - [GeneratorIgnore] static Lease ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction { @@ -73,7 +69,6 @@ static Lease ToArrayAt(this ReadOnlySpan ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] static TResult[] ToArray(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction { @@ -85,7 +80,6 @@ static TResult[] ToArray(this ReadOnlySpan return result; } - [GeneratorIgnore] static TResult[] ToArrayVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction @@ -100,7 +94,6 @@ static TResult[] ToArrayVector(thi return result; } - [GeneratorIgnore] static Lease ToArrayVector(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction @@ -115,7 +108,6 @@ static Lease ToArrayVector ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { @@ -129,7 +121,6 @@ static Lease ToArray(this ReadOnlySpan(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction { @@ -141,7 +132,6 @@ static TResult[] ToArrayAt(this ReadOnlySpan ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction { @@ -156,7 +146,6 @@ static Lease ToArrayAt(this ReadOnlySpan(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction @@ -168,7 +157,6 @@ static TResult[] ToArray(this ReadOnlyS return arrayBuilder.ToArray(); } - [GeneratorIgnore] static Lease ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ValueEnumerable.cs similarity index 97% rename from NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ValueEnumerable.cs index 36108fba9..33ce977bc 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -49,7 +49,6 @@ public static Lease ToArray(this TEn ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] internal static TSource[] ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -59,7 +58,6 @@ internal static TSource[] ToArray return arrayBuilder.ToArray(); } - [GeneratorIgnore] internal static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -72,7 +70,6 @@ internal static Lease ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -82,7 +79,6 @@ internal static TSource[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -95,7 +91,6 @@ internal static Lease ToArrayAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -105,7 +100,6 @@ static TResult[] ToArray( return arrayBuilder.ToArray(); } - [GeneratorIgnore] static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -117,7 +111,6 @@ static Lease ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -127,7 +120,6 @@ static TResult[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -139,8 +131,6 @@ static Lease ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -151,7 +141,6 @@ internal static TResult[] ToArray ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -162,4 +151,4 @@ internal static Lease ToArray ToArray(this TEn ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] static TSource[] ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -52,7 +51,6 @@ static TSource[] ToArray(this TEn ? Array.Empty() : ValueEnumerableExtensions.ToArray(source, predicate); - [GeneratorIgnore] static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -63,7 +61,6 @@ static Lease ToArray(thi ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] static TSource[] ToArrayAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -72,7 +69,7 @@ static TSource[] ToArrayAt(this T ? Array.Empty() : ValueEnumerableExtensions.ToArrayAt(source, predicate); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Lease ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -84,7 +81,6 @@ static Lease ToArrayAt(t ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] internal static TResult[] ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -98,7 +94,6 @@ internal static TResult[] ToArray ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -115,7 +110,6 @@ internal static Lease ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -129,7 +123,6 @@ internal static TResult[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -145,7 +138,6 @@ internal static Lease ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -155,7 +147,6 @@ static TResult[] ToArray() : ValueEnumerableExtensions.ToArray(source, predicate, selector); - [GeneratorIgnore] static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ValueReadOnlyList.cs new file mode 100644 index 000000000..1ea33e6da --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArray.ValueReadOnlyList.cs @@ -0,0 +1,24 @@ +using System; +using System.Buffers; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static TSource[] ToArray(this TEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.ToArray(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Lease ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.ToArray(source, pool, clearOnDispose); + } +} diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs similarity index 97% rename from NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs index a062b1ec7..58bfebf82 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs @@ -23,7 +23,7 @@ public static async ValueTask> ToArrayAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -31,7 +31,7 @@ static async ValueTask ToArrayAsync => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -41,7 +41,7 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -49,7 +49,7 @@ static async ValueTask ToArrayAtAsync => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, false, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -59,7 +59,7 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -67,7 +67,7 @@ static async ValueTask ToArrayAsync => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, selector).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -77,7 +77,7 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -85,7 +85,7 @@ static async ValueTask ToArrayAtAsync => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, false, cancellationToken, selector).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -95,7 +95,7 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -104,7 +104,7 @@ static async ValueTask ToArrayAsync => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, predicate, selector).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs similarity index 98% rename from NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs index 5631d82a0..a01acfc42 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs @@ -24,7 +24,7 @@ static Dictionary ToDictionary(this return dictionary; } - [GeneratorIgnore] + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TKey : notnull where TKeySelector : struct, IFunction @@ -40,7 +40,7 @@ static Dictionary ToDictionary ToDictionaryAt(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TKey : notnull where TKeySelector : struct, IFunction @@ -57,7 +57,7 @@ static Dictionary ToDictionaryAt ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TKey : notnull where TKeySelector : struct, IFunction @@ -98,7 +98,7 @@ static Dictionary ToDictionary ToDictionary( this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, @@ -118,7 +118,7 @@ static Dictionary return dictionary; } - [GeneratorIgnore] + static Dictionary ToDictionaryAt( this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, @@ -140,7 +140,7 @@ static Dictionary return dictionary; } - [GeneratorIgnore] + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TKey : notnull where TKeySelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs similarity index 85% rename from NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs index 7bdd23b00..72e8f2c28 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs @@ -8,13 +8,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this TEnumerable source, Func keySelector, IEqualityComparer? comparer = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TKey : notnull - => source.ToDictionary>(new FunctionWrapper(keySelector), comparer); - public static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -31,7 +24,7 @@ public static Dictionary ToDictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -51,7 +44,7 @@ internal static Dictionary ToDictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -73,7 +66,7 @@ internal static Dictionary ToDictionaryAt ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -98,13 +91,6 @@ internal static Dictionary ToDictionary ToDictionary(this TEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TKey : notnull - => source.ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - public static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -124,7 +110,7 @@ public static Dictionary ToDictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -144,7 +130,7 @@ internal static Dictionary ToDictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -167,7 +153,7 @@ internal static Dictionary ToDictionaryAt ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs similarity index 83% rename from NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs index 6d3eb4e85..da53b8cae 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs @@ -6,13 +6,6 @@ namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyCollectionExtensions { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this TEnumerable source, Func keySelector, IEqualityComparer? comparer = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TKey : notnull - => ToDictionary>(source, new FunctionWrapper(keySelector), comparer); public static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer = default) where TEnumerable : IValueReadOnlyCollection @@ -24,7 +17,7 @@ public static Dictionary ToDictionary() : ValueEnumerableExtensions.ToDictionary(source, keySelector, comparer); - [GeneratorIgnore] + static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -37,7 +30,7 @@ static Dictionary ToDictionary(source, keySelector, comparer, predicate); - [GeneratorIgnore] + static Dictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -49,7 +42,7 @@ static Dictionary ToDictionaryAt() : ValueEnumerableExtensions.ToDictionaryAt(source, keySelector, comparer, predicate); - [GeneratorIgnore] + static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -64,13 +57,6 @@ static Dictionary ToDictionary ToDictionary(this TEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TKey : notnull - => ToDictionary, FunctionWrapper>(source, new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); public static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TEnumerable : IValueReadOnlyCollection @@ -84,7 +70,7 @@ public static Dictionary ToDictionary(source, keySelector, elementSelector, comparer); - [GeneratorIgnore] + static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -98,7 +84,7 @@ static Dictionary ToDictionary(source, keySelector, elementSelector, comparer, predicate); - [GeneratorIgnore] + static Dictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -111,7 +97,7 @@ static Dictionary ToDictionaryAt() : ValueEnumerableExtensions.ToDictionaryAt(source, keySelector, elementSelector, comparer, predicate); - [GeneratorIgnore] + static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs new file mode 100644 index 000000000..edac0afbb --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionary.ValueReadOnlyList.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TKey : notnull + where TKeySelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.ToDictionary(source, keySelector, comparer); + + ////////////////////////////////////////////////////////////////////////////////////////////////// + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TKey : notnull + where TKeySelector : struct, IFunction + where TElementSelector : struct, IFunction + => ValueReadOnlyCollectionExtensions.ToDictionary(source, keySelector, elementSelector, comparer); + } +} + diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs similarity index 88% rename from NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs index 8dd683283..e098c5d12 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs @@ -9,16 +9,6 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueTask> ToDictionaryAsync( - this TEnumerable source, - Func> keySelector, - IEqualityComparer? comparer = default, - CancellationToken cancellationToken = default) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TKey : notnull - => source.ToDictionaryAsync>(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); public static ValueTask> ToDictionaryAsync( this TEnumerable source, @@ -58,7 +48,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -93,7 +83,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAtAsync( this TEnumerable source, TKeySelector keySelector, @@ -131,7 +121,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -172,18 +162,6 @@ static async ValueTask> ToDictionaryAsync> ToDictionaryAsync( - this TEnumerable source, - Func> keySelector, - Func> elementSelector, - IEqualityComparer? comparer = default, - CancellationToken cancellationToken = default) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - where TKey : notnull - => source.ToDictionaryAsync, AsyncFunctionWrapper>(new AsyncFunctionWrapper(keySelector), new AsyncFunctionWrapper(elementSelector), comparer, cancellationToken); - public static ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -223,7 +201,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -260,7 +238,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAtAsync( this TEnumerable source, TKeySelector keySelector, @@ -300,7 +278,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ReadOnlySpan.cs similarity index 94% rename from NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ReadOnlySpan.cs index ab86e865f..bb4f7dfb4 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ReadOnlySpan.cs @@ -13,25 +13,25 @@ public static partial class ArrayExtensions static List ToList(this ReadOnlySpan source) => source.ToArray().AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction => source.ToArray(predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction => source.ToArrayAt(predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source.ToArray(selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> @@ -40,13 +40,13 @@ static List ToListVector( where TResult : struct => source.ToArrayVector(vectorSelector, selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source.ToArrayAt(selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueEnumerable.cs similarity index 96% rename from NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueEnumerable.cs index 9a42620e6..2b03337c3 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueEnumerable.cs @@ -14,7 +14,7 @@ public static List ToList(this TEnum => source.ToArray().AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -23,7 +23,7 @@ static List ToList(this => source.ToArray(predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -32,7 +32,7 @@ static List ToListAt(thi => source.ToArrayAt(predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -41,7 +41,7 @@ static List ToList source.ToArray(selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -49,7 +49,7 @@ static List ToListAt => source.ToArrayAt(selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueReadOnlyCollection.cs similarity index 96% rename from NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueReadOnlyCollection.cs index 73e8947a8..ae60dc6d8 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueReadOnlyCollection.cs @@ -17,7 +17,7 @@ public static List ToList(this TEnum _ => ToArray(source).AsList(), }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -25,7 +25,7 @@ static List ToList(this where TPredicate : struct, IFunction => ToArray(source, predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -33,7 +33,7 @@ static List ToListAt(thi where TPredicate : struct, IFunction => ToArrayAt(source, predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static List ToList(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -41,7 +41,7 @@ internal static List ToList => ToArray(source, selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static List ToListAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -49,7 +49,7 @@ internal static List ToListAt => ToArrayAt(source, selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueReadOnlyList.cs new file mode 100644 index 000000000..e69e0402f --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToList.ValueReadOnlyList.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static List ToList(this TEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.ToList(source); + } +} diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs similarity index 96% rename from NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs index 465d62854..3d4a0f681 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs @@ -16,7 +16,7 @@ public static async ValueTask> ToListAsync (await source.ToArrayAsync(cancellationToken).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -25,7 +25,7 @@ static async ValueTask> ToListAsync (await source.ToArrayAsync(cancellationToken, predicate).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -34,7 +34,7 @@ static async ValueTask> ToListAtAsync (await source.ToArrayAtAsync(cancellationToken, predicate).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -43,7 +43,7 @@ static async ValueTask> ToListAsync (await source.ToArrayAsync(cancellationToken, selector).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -52,7 +52,7 @@ static async ValueTask> ToListAtAsync (await source.ToArrayAtAsync(cancellationToken, selector).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ReadOnlyList.cs similarity index 95% rename from NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs rename to NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ReadOnlyList.cs index 9a77a2622..371ffb7d7 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ReadOnlyList.cs @@ -8,7 +8,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this TList source, int index) where TList : struct, IReadOnlyList @@ -17,7 +17,7 @@ static Option ElementAt(this TList source, int index) : Option.Some(source[index]); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option ElementAt(this TList source, int index, TSelector selector) where TList : struct, IReadOnlyList @@ -27,7 +27,7 @@ internal static Option ElementAt(th : Option.Some(selector.Invoke(source[index])); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option ElementAtAt(this TList source, int index, TSelector selector) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ReadOnlySpan.cs similarity index 95% rename from NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ReadOnlySpan.cs index 60e1dad20..a452d86e8 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ReadOnlySpan.cs @@ -13,7 +13,7 @@ static Option ElementAt(this ReadOnlySpan source, int : Option.Some(source[index]); - [GeneratorIgnore] + static Option ElementAt(this ReadOnlySpan source, int index, TPredicate predicate) where TPredicate : struct, IFunction { @@ -29,7 +29,7 @@ static Option ElementAt(this ReadOnlySpan } - [GeneratorIgnore] + static Option ElementAtAt(this ReadOnlySpan source, int index, TPredicate predicate) where TPredicate : struct, IFunction { @@ -46,7 +46,7 @@ static Option ElementAtAt(this ReadOnlySpan ElementAt(this ReadOnlySpan source, int index, TSelector selector) where TSelector : struct, IFunction => index < 0 || index >= source.Length @@ -54,7 +54,7 @@ static Option ElementAt(this ReadOnlySpan< : Option.Some(selector.Invoke(source[index])); - [GeneratorIgnore] + static Option ElementAtAt(this ReadOnlySpan source, int index, TSelector selector) where TSelector : struct, IFunction => index < 0 || index >= source.Length @@ -62,7 +62,7 @@ static Option ElementAtAt(this ReadOnlySpa : Option.Some(selector.Invoke(source[index], index)); - [GeneratorIgnore] + static Option ElementAt(this ReadOnlySpan source, int index, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueEnumerable.cs similarity index 97% rename from NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueEnumerable.cs index 914a38426..c79dfe2c5 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueEnumerable.cs @@ -23,7 +23,7 @@ public static Option ElementAt(this } - [GeneratorIgnore] + internal static Option ElementAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -42,7 +42,7 @@ internal static Option ElementAt ElementAtAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -64,7 +64,7 @@ internal static Option ElementAtAt ElementAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -84,7 +84,7 @@ internal static Option ElementAt ElementAtAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -106,7 +106,7 @@ internal static Option ElementAtAt ElementAt(this TEnumerable source, int index, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs similarity index 97% rename from NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs index 68cac0e57..80eb7020b 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs @@ -18,7 +18,7 @@ public static Option ElementAt(this : Option.None }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -30,7 +30,7 @@ static Option ElementAt( _ => ValueEnumerableExtensions.ElementAt(source, index, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAtAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -42,7 +42,7 @@ static Option ElementAtAt ValueEnumerableExtensions.ElementAtAt(source, index, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -57,7 +57,7 @@ static Option ElementAt ElementAtAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -71,7 +71,7 @@ static Option ElementAtAt ElementAt(this TEnumerable source, int index, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueReadOnlyList.cs new file mode 100644 index 000000000..736663171 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAt.ValueReadOnlyList.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Option ElementAt(this TEnumerable source, int index) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + => source switch + { + {Count: 0} => Option.None, + _ => index < source.Count + ? ValueEnumerableExtensions.ElementAt(source, index) + : Option.None + }; + } +} diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs similarity index 98% rename from NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs index c9c3f5aca..c073a15ea 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs @@ -35,7 +35,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -65,7 +65,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -98,7 +98,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -128,7 +128,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -161,7 +161,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Element/First/First.ReadOnlyList.cs similarity index 94% rename from NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs rename to NetFabric.Hyperlinq.Core/Element/First/First.ReadOnlyList.cs index 7b9af035e..d2aa13217 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core/Element/First/First.ReadOnlyList.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TList source) where TList : struct, IReadOnlyList @@ -17,7 +17,7 @@ static Option First(this TList source) _ => Option.Some(source[0]) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option First(this TList source, TSelector selector) where TList : struct, IReadOnlyList @@ -29,7 +29,7 @@ internal static Option First(this T }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option FirstAt(this TList source, TSelector selector) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Element/First/First.ReadOnlySpan.cs similarity index 95% rename from NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Element/First/First.ReadOnlySpan.cs index 2e34346c1..830e8f082 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Element/First/First.ReadOnlySpan.cs @@ -14,7 +14,7 @@ static Option First(this ReadOnlySpan source) _ => Option.Some(source[0]) }; - [GeneratorIgnore] + static Option First(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -28,7 +28,7 @@ static Option First(this ReadOnlySpan sou } - [GeneratorIgnore] + static Option FirstAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -42,7 +42,7 @@ static Option FirstAt(this ReadOnlySpan s } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -53,7 +53,7 @@ static Option First(this ReadOnlySpan FirstAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -64,7 +64,7 @@ static Option FirstAt(this ReadOnlySpan First(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Element/First/First.ValueEnumerable.cs similarity index 96% rename from NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Element/First/First.ValueEnumerable.cs index 50251b11b..95379dea5 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Element/First/First.ValueEnumerable.cs @@ -18,7 +18,7 @@ public static Option First(this TEnu } - [GeneratorIgnore] + internal static Option First(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -36,7 +36,7 @@ internal static Option First FirstAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -56,7 +56,7 @@ internal static Option FirstAt First(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -71,7 +71,7 @@ internal static Option First FirstAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -86,7 +86,7 @@ internal static Option FirstAt First(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Element/First/First.ValueReadOnlyCollection.cs similarity index 94% rename from NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Element/First/First.ValueReadOnlyCollection.cs index 2f01ff17e..dcdd30bba 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Element/First/First.ValueReadOnlyCollection.cs @@ -20,12 +20,12 @@ public static Option First(this TEnu static Option GetFirst(TEnumerable source) { using var enumerator = source.GetEnumerator(); - enumerator.MoveNext(); + _ = enumerator.MoveNext(); return Option.Some(enumerator.Current); } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -37,7 +37,7 @@ static Option First(this _ => ValueEnumerableExtensions.First(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option FirstAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -49,7 +49,7 @@ static Option FirstAt(th _ => ValueEnumerableExtensions.FirstAt(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -65,13 +65,13 @@ static Option First GetFirst(TEnumerable source, TSelector selector) { using var enumerator = source.GetEnumerator(); - enumerator.MoveNext(); + _ = enumerator.MoveNext(); return Option.Some(selector.Invoke(enumerator.Current)); } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option FirstAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -87,13 +87,13 @@ static Option FirstAt GetFirst(TEnumerable source, TSelector selector) { using var enumerator = source.GetEnumerator(); - enumerator.MoveNext(); + _ = enumerator.MoveNext(); return Option.Some(selector.Invoke(enumerator.Current, 0)); } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq.Core/Element/First/First.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Element/First/First.ValueReadOnlyList.cs new file mode 100644 index 000000000..19488681e --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Element/First/First.ValueReadOnlyList.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Option First(this TEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.First(source); + } +} diff --git a/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Element/First/FirstAsync.AsyncValueEnumerable.cs similarity index 98% rename from NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Element/First/FirstAsync.AsyncValueEnumerable.cs index 4ac0040c0..2216e721e 100644 --- a/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Element/First/FirstAsync.AsyncValueEnumerable.cs @@ -28,7 +28,7 @@ public static async ValueTask> FirstAsync> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -52,7 +52,7 @@ static async ValueTask> FirstAsync> FirstAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -79,7 +79,7 @@ static async ValueTask> FirstAtAsync> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -102,7 +102,7 @@ static async ValueTask> FirstAsync> FirstAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -125,7 +125,7 @@ static async ValueTask> FirstAtAsync> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Element/Single/Single.ReadOnlyList.cs similarity index 94% rename from NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs rename to NetFabric.Hyperlinq.Core/Element/Single/Single.ReadOnlyList.cs index b121eaf53..45d81b242 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core/Element/Single/Single.ReadOnlyList.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + static Option Single(this TList source) where TList : struct, IReadOnlyList => source switch @@ -15,7 +15,7 @@ static Option Single(this TList source) _ => Option.None, }; - [GeneratorIgnore] + internal static Option Single(this TList source, TSelector selector) where TList : struct, IReadOnlyList where TSelector : struct, IFunction @@ -26,7 +26,7 @@ internal static Option Single(this }; - [GeneratorIgnore] + internal static Option SingleAt(this TList source, TSelector selector) where TList : struct, IReadOnlyList where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Element/Single/Single.ReadOnlySpan.cs similarity index 96% rename from NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Element/Single/Single.ReadOnlySpan.cs index 56f05ceee..4042a258f 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Element/Single/Single.ReadOnlySpan.cs @@ -12,7 +12,6 @@ static Option Single(this ReadOnlySpan source) _ => Option.None, }; - [GeneratorIgnore] static Option Single(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -35,7 +34,6 @@ static Option Single(this ReadOnlySpan so } - [GeneratorIgnore] static Option SingleAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -58,7 +56,6 @@ static Option SingleAt(this ReadOnlySpan } - [GeneratorIgnore] static Option Single(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source switch @@ -68,7 +65,6 @@ static Option Single(this ReadOnlySpan SingleAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source switch @@ -78,7 +74,7 @@ static Option SingleAt(this ReadOnlySpan Single(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Element/Single/Single.ValueEnumerable.cs similarity index 96% rename from NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Element/Single/Single.ValueEnumerable.cs index 9ab5eeb54..ae7ac435c 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Element/Single/Single.ValueEnumerable.cs @@ -13,7 +13,7 @@ public static Option Single(this TEn => source.GetSingle(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option Single(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -22,7 +22,7 @@ internal static Option Single source.GetSingle(predicate); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option SingleAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -31,7 +31,7 @@ internal static Option SingleAt source.GetSingleAt(predicate); - [GeneratorIgnore] + static Option Single(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -41,7 +41,7 @@ static Option Single(selector); - [GeneratorIgnore] + static Option SingleAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -63,7 +63,7 @@ public TResult Invoke(TSource item) => selector.Invoke(item, 0); } - [GeneratorIgnore] + internal static Option Single(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -75,7 +75,7 @@ internal static Option Single GetSingle(this TEnumerable source) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -93,7 +93,7 @@ static Option GetSingle(this TEnumer } - [GeneratorIgnore] + static Option GetSingle(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -120,7 +120,7 @@ static Option GetSingle( } - [GeneratorIgnore] + static Option GetSingleAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Element/Single/Single.ValueReadOnlyCollection.cs similarity index 97% rename from NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Element/Single/Single.ValueReadOnlyCollection.cs index e0a00e1ce..899a89bd4 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Element/Single/Single.ValueReadOnlyCollection.cs @@ -25,7 +25,7 @@ static Option GetSingle(TEnumerable source) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option Single(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -37,7 +37,7 @@ static Option Single(thi _ => ValueEnumerableExtensions.Single(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option SingleAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -49,7 +49,7 @@ static Option SingleAt(t _ => ValueEnumerableExtensions.SingleAt(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option Single(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -70,7 +70,7 @@ static Option GetSingle(TEnumerable source, TSelector selector) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option SingleAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -92,7 +92,7 @@ static Option GetSingle(TEnumerable source, TSelector selector) } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option Single(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq.Core/Element/Single/Single.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Element/Single/Single.ValueReadOnlyList.cs new file mode 100644 index 000000000..49e6dd264 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Element/Single/Single.ValueReadOnlyList.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Option Single(this TEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.Single(source); + } +} diff --git a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Element/Single/SingleAsync.AsyncValueEnumerable.cs similarity index 97% rename from NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Element/Single/SingleAsync.AsyncValueEnumerable.cs index 436690e85..1b46d236d 100644 --- a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Element/Single/SingleAsync.AsyncValueEnumerable.cs @@ -15,7 +15,7 @@ public static ValueTask> SingleAsync source.GetSingleAsync(cancellationToken); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable @@ -24,7 +24,7 @@ static ValueTask> SingleAsync source.GetSingleAsync(cancellationToken, predicate); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueTask> SingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable @@ -33,7 +33,7 @@ static ValueTask> SingleAtAsync source.GetSingleAtAsync(cancellationToken, predicate); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -45,7 +45,7 @@ static async ValueTask> SingleAsync> SingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -69,7 +69,7 @@ public ValueTask InvokeAsync(TSource item, CancellationToken cancellati => selector.InvokeAsync(item, 0, cancellationToken); } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -85,7 +85,7 @@ static async ValueTask> SingleAsync> GetSingleAsync(this TEnumerable source, CancellationToken cancellationToken) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -109,7 +109,6 @@ static async ValueTask> GetSingleAsync> GetSingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -144,7 +143,7 @@ static async ValueTask> GetSingleAsync> GetSingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs similarity index 98% rename from NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs index a8ff05a86..6b6a86359 100644 --- a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs @@ -5,7 +5,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore] + static bool SequenceEqual(this ReadOnlySpan first, TEnumerable second, IEqualityComparer? comparer = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ArraySegment.cs similarity index 81% rename from NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ArraySegment.cs index e1443b60a..15df2b3f2 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ArraySegment.cs @@ -10,7 +10,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) => source.Where(new FunctionWrapper(predicate)); @@ -101,7 +101,7 @@ public readonly void Dispose() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() - => ((ReadOnlySpan)source.AsSpan()).Count(predicate); + => source.AsReadOnlySpan().Count(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -110,7 +110,7 @@ public int Count(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).Count(new PredicatePredicateCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().Count(new PredicatePredicateCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -119,14 +119,14 @@ public int Count(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).CountAt(new PredicatePredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().CountAt(new PredicatePredicateAtCombination(this.predicate, predicate)); #endregion #region Quantifier [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All() - => ((ReadOnlySpan)source.AsSpan()).All(predicate); + => source.AsReadOnlySpan().All(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -135,7 +135,7 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).All(new PredicatePredicateCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().All(new PredicatePredicateCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -144,11 +144,11 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AllAt(new PredicatePredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().AllAt(new PredicatePredicateAtCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() - => ((ReadOnlySpan)source.AsSpan()).Any(predicate); + => source.AsReadOnlySpan().Any(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -157,7 +157,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).Any(new PredicatePredicateCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().Any(new PredicatePredicateCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -166,7 +166,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AnyAt(new PredicatePredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().AnyAt(new PredicatePredicateAtCombination(this.predicate, predicate)); #endregion #region Filtering @@ -206,16 +206,16 @@ public ArraySegmentWhereSelectEnumerable ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAt(index, predicate); + => source.AsReadOnlySpan().ElementAt(index, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).First(predicate); + => source.AsReadOnlySpan().First(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() #pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() - => ((ReadOnlySpan)source.AsSpan()).Single(predicate); + => source.AsReadOnlySpan().Single(predicate); #pragma warning restore HLQ005 // Avoid Single() and SingleOrDefault() #endregion @@ -223,7 +223,7 @@ public Option Single() [MethodImpl(MethodImplOptions.AggressiveInlining)] public TSource[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate); + => source.AsReadOnlySpan().ToArray(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) @@ -231,7 +231,7 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToList(predicate); + => source.AsReadOnlySpan().ToList(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) @@ -242,7 +242,7 @@ public Dictionary ToDictionary(Func keySelec public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer, predicate); + => source.AsReadOnlySpan().ToDictionary(keySelector, comparer, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) @@ -254,7 +254,7 @@ public Dictionary ToDictionary where TElementSelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer, predicate); + => source.AsReadOnlySpan().ToDictionary(keySelector, elementSelector, comparer, predicate); #endregion } @@ -262,72 +262,72 @@ public Dictionary ToDictionary(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.AsyncValueEnumerable.cs similarity index 84% rename from NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index 622f4eeca..62c36eeaf 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -12,13 +12,6 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.AsyncFunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereEnumerable> Where(this TEnumerable source, Func> predicate) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - => source.Where>(new AsyncFunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereEnumerable Where(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable @@ -206,19 +199,11 @@ readonly void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine public ValueTask CountAsync(CancellationToken cancellationToken = default) => source.CountAsync(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) - => CountAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.CountAsync>(new AsyncPredicatePredicateCombination(this.predicate, predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) - => CountAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAtAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction @@ -231,19 +216,11 @@ public ValueTask CountAtAsync(TPredicate2 predicate = default, public ValueTask AllAsync(CancellationToken cancellationToken = default) => source.AllAsync(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AllAsync(Func> predicate, CancellationToken cancellationToken = default) - => AllAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AllAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.AllAsync>(new AsyncPredicatePredicateCombination(this.predicate, predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AllAsync(Func> predicate, CancellationToken cancellationToken = default) - => AllAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AllAtAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction @@ -253,19 +230,11 @@ public ValueTask AllAtAsync(TPredicate2 predicate = default, public ValueTask AnyAsync(CancellationToken cancellationToken = default) => source.AnyAsync(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AnyAsync(Func> predicate, CancellationToken cancellationToken = default) - => AnyAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AnyAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.AnyAsync>(new AsyncPredicatePredicateCombination(this.predicate, predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AnyAsync(Func> predicate, CancellationToken cancellationToken = default) - => AnyAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AnyAtAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction @@ -274,10 +243,6 @@ public ValueTask AnyAtAsync(TPredicate2 predicate = default, #endregion #region Projection - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereSelectEnumerable> Select(Func> selector) - => Select>(new AsyncFunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereSelectEnumerable Select(TSelector selector = default) where TSelector : struct, IAsyncFunction @@ -286,18 +251,10 @@ public WhereSelectEnumerable, TSource>> Where(Func> predicate) - => Where(new AsyncFunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereEnumerable> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IAsyncFunction => source.Where>(new AsyncPredicatePredicateCombination(this.predicate, predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TSource>> Where(Func> predicate) - => WhereAt(new AsyncFunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -335,11 +292,6 @@ public ValueTask> ToArrayAsync(ArrayPool pool, Cancellat [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) => source.ToListAsync(cancellationToken, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(Func> keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) - where TKey : notnull - => ToDictionaryAsync(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) @@ -347,11 +299,6 @@ public ValueTask> ToDictionaryAsync => source.ToDictionaryAsync(keySelector, comparer, cancellationToken, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(Func> keySelector, Func> elementSelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) - where TKey : notnull - => ToDictionaryAsync, AsyncFunctionWrapper>(new AsyncFunctionWrapper(keySelector), new AsyncFunctionWrapper(elementSelector), comparer, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ReadOnlyMemory.cs similarity index 99% rename from NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ReadOnlyMemory.cs index b6242cfcf..bc3a4da78 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -10,7 +10,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.Where(new FunctionWrapper(predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ReadOnlySpan.cs similarity index 99% rename from NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ReadOnlySpan.cs index b587ab670..2f3334d28 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereEnumerable> Where(this ReadOnlySpan source, Func predicate) => source.Where(new FunctionWrapper(predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueEnumerable.cs similarity index 83% rename from NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueEnumerable.cs index 42f503c9e..a7ce272bd 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -11,13 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereEnumerable> Where(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.Where>(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereEnumerable Where(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable @@ -103,19 +96,11 @@ public void Dispose() public int Count() => source.Count(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => Count(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Count>(new PredicatePredicateCombination(this.predicate, predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => CountAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -142,22 +127,12 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def public List ToList() => source.ToList(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary(new FunctionWrapper(keySelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction => source.ToDictionary(keySelector, comparer, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull @@ -172,19 +147,11 @@ public Dictionary ToDictionary source.All(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.All>(new PredicatePredicateCombination(this.predicate, predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -194,19 +161,11 @@ public bool AllAt(TPredicate2 predicate = default) public bool Any() => source.Any(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Any>(new PredicatePredicateCombination(this.predicate, predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -215,19 +174,11 @@ public bool AnyAt(TPredicate2 predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereEnumerable, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereEnumerable> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.Where>(new PredicatePredicateCombination(this.predicate, predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -236,10 +187,6 @@ public WhereAtEnumerable> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereSelectEnumerable Select(TSelector selector = default) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs similarity index 83% rename from NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index a0ec54406..6e4022ee0 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -11,13 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereEnumerable> Where(this TEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => Where>(source, new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereEnumerable Where(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection @@ -102,19 +95,11 @@ public void Dispose() public int Count() => ValueReadOnlyCollectionExtensions.Count(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => Count(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.Count>(source, new PredicatePredicateCombination(this.predicate, predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => CountAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -127,19 +112,11 @@ public int CountAt(TPredicate2 predicate = default) public bool All() => ValueReadOnlyCollectionExtensions.All(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.All>(source, new PredicatePredicateCombination(this.predicate, predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -149,19 +126,11 @@ public bool AllAt(TPredicate2 predicate = default) public bool Any() => ValueReadOnlyCollectionExtensions.Any(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.Any>(source, new PredicatePredicateCombination(this.predicate, predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -170,19 +139,11 @@ public bool AnyAt(TPredicate2 predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereEnumerable, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereEnumerable> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.Where>(source, new PredicatePredicateCombination(this.predicate, predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -191,10 +152,6 @@ public WhereAtEnumerable> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereSelectEnumerable Select(TSelector selector = default) where TSelector : struct, IFunction @@ -232,22 +189,12 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def public List ToList() => ValueReadOnlyCollectionExtensions.ToList(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary(new FunctionWrapper(keySelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction => ValueReadOnlyCollectionExtensions.ToDictionary(source, keySelector, comparer, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueReadOnlyList.cs new file mode 100644 index 000000000..15759c6ba --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/Where.ValueReadOnlyList.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueReadOnlyCollectionExtensions.WhereEnumerable Where(this TEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.Where(source, predicate); + } +} + diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/WhereEnumerator.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/Where/WhereEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/Where/WhereEnumerator.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/Where/WhereEnumerator.cs diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs similarity index 80% rename from NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index 63db8ad6c..545773f06 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -10,7 +10,6 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereAtEnumerable> Where(this in ArraySegment source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); @@ -107,7 +106,7 @@ public readonly void Dispose() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() - => ((ReadOnlySpan)source.AsSpan()).CountAt(predicate); + => source.AsReadOnlySpan().CountAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -116,7 +115,7 @@ public int Count(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).CountAt(new PredicatePredicateAtCombination(predicate, this.predicate)); + => source.AsReadOnlySpan().CountAt(new PredicatePredicateAtCombination(predicate, this.predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -125,7 +124,7 @@ public int Count(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).CountAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().CountAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); #endregion #region Quantifier @@ -133,7 +132,7 @@ public int CountAt(TPredicate2 predicate = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All() - => ((ReadOnlySpan)source.AsSpan()).AllAt(predicate); + => source.AsReadOnlySpan().AllAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -142,7 +141,7 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AllAt(new PredicatePredicateAtCombination(predicate, this.predicate)); + => source.AsReadOnlySpan().AllAt(new PredicatePredicateAtCombination(predicate, this.predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -151,11 +150,11 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AllAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().AllAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() - => ((ReadOnlySpan)source.AsSpan()).AnyAt(predicate); + => source.AsReadOnlySpan().AnyAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -164,7 +163,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AnyAt(new PredicatePredicateAtCombination(predicate, this.predicate)); + => source.AsReadOnlySpan().AnyAt(new PredicatePredicateAtCombination(predicate, this.predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -173,7 +172,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AnyAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().AnyAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); #endregion #region Filtering @@ -204,16 +203,16 @@ public ArraySegmentWhereAtEnumerable ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAtAt(index, predicate); + => source.AsReadOnlySpan().ElementAtAt(index, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).FirstAt(predicate); + => source.AsReadOnlySpan().FirstAt(predicate); #pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() - => ((ReadOnlySpan)source.AsSpan()).SingleAt(predicate); + => source.AsReadOnlySpan().SingleAt(predicate); #pragma warning restore HLQ005 // Avoid Single() and SingleOrDefault() #endregion @@ -221,7 +220,7 @@ public Option Single() [MethodImpl(MethodImplOptions.AggressiveInlining)] public TSource[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(predicate); + => source.AsReadOnlySpan().ToArrayAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) @@ -229,7 +228,7 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToListAt(predicate); + => source.AsReadOnlySpan().ToListAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) @@ -240,7 +239,7 @@ public Dictionary ToDictionary(Func keySelec public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionaryAt(keySelector, comparer, predicate); + => source.AsReadOnlySpan().ToDictionaryAt(keySelector, comparer, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) @@ -252,7 +251,7 @@ public Dictionary ToDictionary where TElementSelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionaryAt(keySelector, elementSelector, comparer, predicate); + => source.AsReadOnlySpan().ToDictionaryAt(keySelector, elementSelector, comparer, predicate); #endregion } @@ -260,72 +259,72 @@ public Dictionary ToDictionary(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs similarity index 85% rename from NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index cfacfac20..2c01b55c3 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -12,13 +12,6 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.AsyncFunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereAtEnumerable> Where(this TEnumerable source, Func> predicate) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - => source.WhereAt>(new AsyncFunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereAtEnumerable WhereAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable @@ -208,19 +201,11 @@ readonly void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine public ValueTask CountAsync(CancellationToken cancellationToken = default) => source.CountAtAsync(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) - => CountAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.CountAtAsync>(new AsyncPredicatePredicateAtCombination(predicate, this.predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) - => CountAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction @@ -233,19 +218,11 @@ public ValueTask CountAtAsync(TPredicate2 predicate, Cancellat public ValueTask AllAsync(CancellationToken cancellationToken = default) => source.AllAtAsync(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AllAsync(Func> predicate, CancellationToken cancellationToken = default) - => AllAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AllAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.AllAtAsync>(new AsyncPredicatePredicateAtCombination(predicate, this.predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AllAsync(Func> predicate, CancellationToken cancellationToken = default) - => AllAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AllAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction @@ -255,19 +232,11 @@ public ValueTask AllAtAsync(TPredicate2 predicate, Cancellati public ValueTask AnyAsync(CancellationToken cancellationToken = default) => source.AnyAtAsync(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AnyAsync(Func> predicate, CancellationToken cancellationToken = default) - => AnyAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AnyAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => source.AnyAtAsync>(new AsyncPredicatePredicateAtCombination(predicate, this.predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AnyAsync(Func> predicate, CancellationToken cancellationToken = default) - => AnyAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AnyAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction @@ -279,18 +248,10 @@ public ValueTask AnyAtAsync(TPredicate2 predicate, Cancellati #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TPredicate, TSource>> Where(Func> predicate) - => Where(new AsyncFunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IAsyncFunction => source.WhereAt>(new AsyncPredicatePredicateAtCombination(predicate, this.predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TSource>> Where(Func> predicate) - => WhereAt(new AsyncFunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) @@ -328,11 +289,6 @@ public ValueTask> ToArrayAsync(ArrayPool pool, Cancellat [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToListAsync(CancellationToken cancellationToken = default) => source.ToListAtAsync(cancellationToken, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(Func> keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) - where TKey : notnull - => ToDictionaryAsync(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) @@ -340,11 +296,6 @@ public ValueTask> ToDictionaryAsync => source.ToDictionaryAtAsync(keySelector, comparer, cancellationToken, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(Func> keySelector, Func> elementSelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) - where TKey : notnull - => ToDictionaryAsync, AsyncFunctionWrapper>(new AsyncFunctionWrapper(keySelector), new AsyncFunctionWrapper(elementSelector), comparer, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs similarity index 99% rename from NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index b5f9d02d4..a08a106c6 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereAtEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs similarity index 99% rename from NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index 69b2d3edd..c346fffda 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereAtEnumerable> Where(this ReadOnlySpan source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs similarity index 84% rename from NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index 9bc9a5b54..ccf932394 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -11,13 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereAtEnumerable> Where(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.WhereAt>(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereAtEnumerable WhereAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable @@ -108,19 +101,11 @@ public void Dispose() public int Count() => source.CountAt(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => Count(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.CountAt>(new PredicatePredicateAtCombination(predicate, this.predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => CountAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -133,19 +118,11 @@ public int CountAt(TPredicate2 predicate = default) public bool All() => source.AllAt(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AllAt>(new PredicatePredicateAtCombination(predicate, this.predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -155,19 +132,11 @@ public bool AllAt(TPredicate2 predicate = default) public bool Any() => source.AnyAt(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.AnyAt>(new PredicatePredicateAtCombination(predicate, this.predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -176,19 +145,11 @@ public bool AnyAt(TPredicate2 predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TPredicate, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => source.WhereAt>(new PredicatePredicateAtCombination(predicate, this.predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -229,22 +190,12 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def public List ToList() => source.ToListAt(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionaryAt(new FunctionWrapper(keySelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionaryAt(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction => source.ToDictionaryAt(keySelector, comparer, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionaryAt, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionaryAt(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs similarity index 84% rename from NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index 52701135b..686e5fffe 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -11,13 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static WhereAtEnumerable> Where(this TEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => WhereAt>(source, new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereAtEnumerable WhereAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection @@ -107,19 +100,11 @@ public void Dispose() public int Count() => CountAt(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => Count(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.CountAt>(source, new PredicatePredicateAtCombination(predicate, this.predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => CountAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -132,19 +117,11 @@ public int CountAt(TPredicate2 predicate = default) public bool All() => ValueReadOnlyCollectionExtensions.AllAt(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.AllAt>(source, new PredicatePredicateAtCombination(predicate, this.predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -154,19 +131,11 @@ public bool AllAt(TPredicate2 predicate = default) public bool Any() => ValueReadOnlyCollectionExtensions.AnyAt(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.AnyAt>(source, new PredicatePredicateAtCombination(predicate, this.predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -175,19 +144,11 @@ public bool AnyAt(TPredicate2 predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TPredicate, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueReadOnlyCollectionExtensions.WhereAt>(source, new PredicatePredicateAtCombination(predicate, this.predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, TSource>> Where(Func predicate) - => WhereAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -228,22 +189,12 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def public List ToList() => ToListAt(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary(new FunctionWrapper(keySelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction => ToDictionaryAt(source, keySelector, comparer, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs new file mode 100644 index 000000000..8d1102f04 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyList.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueReadOnlyCollectionExtensions.WhereAtEnumerable WhereAt(this TEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.WhereAt(source, predicate); + } +} + diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAtEnumerator.cs b/NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAtEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAtEnumerator.cs rename to NetFabric.Hyperlinq.Core/Filtering/Where/WhereAt/WhereAtEnumerator.cs diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs similarity index 76% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs rename to NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index 0af6eba60..656f059a8 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -10,7 +10,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereSelectEnumerable WhereSelect( this in ArraySegment source, @@ -20,7 +20,6 @@ static ArraySegmentWhereSelectEnumerable => new(source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct ArraySegmentWhereSelectEnumerable : IValueEnumerable.Enumerator> @@ -105,7 +104,7 @@ public readonly void Dispose() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() - => ((ReadOnlySpan)source.AsSpan()).Count(predicate); + => source.AsReadOnlySpan().Count(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -131,7 +130,7 @@ public int CountAt(TPredicate2 predicate = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All() - => ((ReadOnlySpan)source.AsSpan()).All(predicate); + => source.AsReadOnlySpan().All(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -153,7 +152,7 @@ public bool AllAt(TPredicate2 predicate = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() - => ((ReadOnlySpan)source.AsSpan()).Any(predicate); + => source.AsReadOnlySpan().Any(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -176,19 +175,11 @@ public bool AnyAt(TPredicate2 predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Where, Enumerator, TResult, TPredicate2>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -197,21 +188,11 @@ public ValueEnumerableExtensions.WhereAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ArraySegmentWhereSelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable @@ -224,22 +205,22 @@ public ValueEnumerableExtensions.SelectManyEnumerable ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAt(index, predicate, selector); + => source.AsReadOnlySpan().ElementAt(index, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).First(predicate, selector); + => source.AsReadOnlySpan().First(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() - => ((ReadOnlySpan)source.AsSpan()).Single(predicate, selector); + => source.AsReadOnlySpan().Single(predicate, selector); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate, selector); + => source.AsReadOnlySpan().ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) @@ -247,7 +228,7 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToList(predicate, selector); + => source.AsReadOnlySpan().ToList(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) @@ -258,7 +239,7 @@ public Dictionary ToDictionary(Func keySelec public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer, predicate, selector); + => source.AsReadOnlySpan().ToDictionary(keySelector, comparer, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) @@ -270,7 +251,7 @@ public Dictionary ToDictionary where TElementSelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer, predicate, selector); + => source.AsReadOnlySpan().ToDictionary(keySelector, elementSelector, comparer, predicate, selector); #endregion } @@ -279,85 +260,85 @@ public Dictionary ToDictionary(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); } } diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs similarity index 86% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index 02d24b5d6..dd5799b49 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TEnumerable source, @@ -23,7 +23,6 @@ static WhereSelectEnumerable => new(in source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct WhereSelectEnumerable : IAsyncValueEnumerable.Enumerator> @@ -234,19 +233,11 @@ void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) public ValueTask CountAsync(CancellationToken cancellationToken = default) => source.CountAsync(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) - => CountAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => AsyncValueEnumerableExtensions.CountAsync, Enumerator, TResult, TPredicate2>(this, predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask CountAsync(Func> predicate, CancellationToken cancellationToken = default) - => CountAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask CountAtAsync(TPredicate2 predicate = default, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction @@ -259,19 +250,11 @@ public ValueTask CountAtAsync(TPredicate2 predicate = default, public ValueTask AllAsync(CancellationToken cancellationToken = default) => source.AllAsync(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AllAsync(Func> predicate, CancellationToken cancellationToken = default) - => AllAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AllAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => this.AllAsync, Enumerator, TResult, TPredicate2>(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AllAsync(Func> predicate, CancellationToken cancellationToken = default) - => AllAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AllAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction @@ -281,19 +264,11 @@ public ValueTask AllAtAsync(TPredicate2 predicate, Cancellati public ValueTask AnyAsync(CancellationToken cancellationToken = default) => source.AnyAsync(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AnyAsync(Func> predicate, CancellationToken cancellationToken = default) - => AnyAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AnyAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction => this.AnyAsync, Enumerator, TResult, TPredicate2>(predicate, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask AnyAsync(Func> predicate, CancellationToken cancellationToken = default) - => AnyAtAsync(new AsyncFunctionWrapper(predicate), cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask AnyAtAsync(TPredicate2 predicate, CancellationToken cancellationToken = default) where TPredicate2 : struct, IAsyncFunction @@ -302,19 +277,11 @@ public ValueTask AnyAtAsync(TPredicate2 predicate, Cancellati #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereEnumerable, Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) - => this.Where, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IAsyncFunction => this.Where, Enumerator, TResult, TPredicate2>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, Enumerator, TResult, AsyncFunctionWrapper> Where(Func> predicate) - => this.Where, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IAsyncFunction @@ -323,10 +290,6 @@ public WhereAtEnumerable, TSource, TResult, TResult2>> Select(Func> selector) - => Select>(new AsyncFunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereSelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IAsyncFunction @@ -364,22 +327,12 @@ public ValueTask> ToArrayAsync(ArrayPool pool, Cancellat public ValueTask> ToListAsync(CancellationToken cancellationToken = default) => source.ToListAsync(cancellationToken, predicate, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(Func> keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) - where TKey : notnull - => ToDictionaryAsync(new AsyncFunctionWrapper(keySelector), comparer, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull where TKeySelector : struct, IAsyncFunction => source.ToDictionaryAsync(keySelector, comparer, cancellationToken, predicate, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(Func> keySelector, Func> elementSelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) - where TKey : notnull - => ToDictionaryAsync, AsyncFunctionWrapper>(new AsyncFunctionWrapper(keySelector), new AsyncFunctionWrapper(elementSelector), comparer, cancellationToken); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueTask> ToDictionaryAsync(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs similarity index 90% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index 883bdc1c2..bfb1469e9 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereSelectEnumerable WhereSelect( this ReadOnlyMemory source, @@ -21,7 +21,6 @@ static MemoryWhereSelectEnumerable Wher where TSelector : struct, IFunction => new(source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct MemoryWhereSelectEnumerable : IValueEnumerable.Enumerator> @@ -173,19 +172,11 @@ public bool AnyAt(TPredicate2 predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Where, Enumerator, TResult, TPredicate2>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -194,21 +185,11 @@ public ValueEnumerableExtensions.WhereAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public MemoryWhereSelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs similarity index 99% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index 07cfb1f15..5cbabe94b 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -9,7 +9,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereSelectEnumerable WhereSelect( this ReadOnlySpan source, @@ -19,7 +19,6 @@ static SpanWhereSelectEnumerable WhereS where TSelector : struct, IFunction => new(source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly ref struct SpanWhereSelectEnumerable where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs similarity index 83% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index 8a816f47e..212b14883 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TEnumerable source, @@ -23,7 +23,6 @@ static WhereSelectEnumerable => new(in source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct WhereSelectEnumerable : IValueEnumerable.Enumerator> @@ -108,19 +107,11 @@ public void Dispose() public int Count() => source.Count(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => Count(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueEnumerableExtensions.Count, Enumerator, TResult, TPredicate2>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => CountAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -133,19 +124,11 @@ public int CountAt(TPredicate2 predicate = default) public bool All() => source.All(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.All, Enumerator, TResult, TPredicate2>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -155,19 +138,11 @@ public bool AllAt(TPredicate2 predicate = default) public bool Any() => source.Any(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Any, Enumerator, TResult, TPredicate2>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -176,19 +151,11 @@ public bool AnyAt(TPredicate2 predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Where, Enumerator, TResult, TPredicate2>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => this.Where, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -197,21 +164,11 @@ public WhereAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereSelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => source.WhereSelect>(predicate, new SelectorSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable @@ -249,22 +206,12 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def public List ToList() => source.ToList(predicate, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary(new FunctionWrapper(keySelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction => source.ToDictionary(keySelector, comparer, predicate, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs similarity index 84% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index f0f53d467..d163a0fce 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TEnumerable source, @@ -23,7 +23,6 @@ static WhereSelectEnumerable => new(in source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct WhereSelectEnumerable : IValueEnumerable.Enumerator> @@ -108,19 +107,11 @@ public void Dispose() public int Count() => ValueReadOnlyCollectionExtensions.Count(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => Count(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueEnumerableExtensions.Count, Enumerator, TResult, TPredicate2>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count(Func predicate) - => CountAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -133,19 +124,11 @@ public int CountAt(TPredicate2 predicate = default) public bool All() => ValueReadOnlyCollectionExtensions.All(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.All, Enumerator, TResult, TPredicate2>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -155,19 +138,11 @@ public bool AllAt(TPredicate2 predicate = default) public bool Any() => ValueReadOnlyCollectionExtensions.Any(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => this.Any, Enumerator, TResult, TPredicate2>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -176,19 +151,11 @@ public bool AnyAt(TPredicate2 predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate2> Where(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction => ValueEnumerableExtensions.Where, Enumerator, TResult, TPredicate2>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate2> WhereAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction @@ -197,21 +164,11 @@ public ValueEnumerableExtensions.WhereAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereSelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => WhereSelect>(source, predicate, new SelectorSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => ValueEnumerableExtensions.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable @@ -249,22 +206,12 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def public List ToList() => ValueReadOnlyCollectionExtensions.ToList(source, predicate, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary(new FunctionWrapper(keySelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction => ValueReadOnlyCollectionExtensions.ToDictionary(source, keySelector, comparer, predicate, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs b/NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs rename to NetFabric.Hyperlinq.Core/Filtering/WhereSelect/WhereSelect/WhereSelectEnumerator.cs diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs b/NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Empty.cs similarity index 100% rename from NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Empty.cs rename to NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Empty.cs diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs b/NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Range.cs similarity index 99% rename from NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs rename to NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Range.cs index 474d2d5a8..63f676f55 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Range.cs @@ -29,7 +29,6 @@ public static RangeEnumerable Range(int start, int count) return new RangeEnumerable(start, count, end); } - [GeneratorMapping("TSource", "int", true)] [StructLayout(LayoutKind.Auto)] public readonly partial struct RangeEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Repeat.cs similarity index 96% rename from NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs rename to NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Repeat.cs index e175a1a28..7989ab37d 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Repeat.cs @@ -155,10 +155,6 @@ public ValueTask ContainsAsync(TSource value, IEqualityComparer? ? new ValueTask(result: count is not 0 && EqualityComparer.Default.Equals(this.value, value)) : new ValueTask(result: count is not 0 && comparer.Equals(this.value, value)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RepeatEnumerable Select(Func> selector) - => Select>(new AsyncFunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public RepeatEnumerable Select(TSelector selector = default) where TSelector : struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs b/NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Return.cs similarity index 72% rename from NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs rename to NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Return.cs index f9887481d..3e936f76c 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Return.cs +++ b/NetFabric.Hyperlinq.Core/Generation/AsyncValueEnumerable/Return.cs @@ -93,10 +93,6 @@ public ValueTask ContainsAsync(TSource value, IEqualityComparer? ? new ValueTask(result: EqualityComparer.Default.Equals(this.value, value)) : new ValueTask(result: comparer.Equals(this.value, value)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReturnEnumerable Select(Func> selector) - => Select>(new AsyncFunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReturnEnumerable Select(TSelector selector = default) where TSelector : struct, IAsyncFunction @@ -129,29 +125,19 @@ public ValueTask> ToListAsync() => new(result: new List(1) { value }); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionaryAsync(new FunctionWrapper(keySelector), comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default) + public async ValueTask> ToDictionaryAsync(TKeySelector keySelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull - where TKeySelector : struct, IFunction + where TKeySelector : struct, IAsyncFunction // ReSharper disable once HeapView.ObjectAllocation.Evident - => new(result: new Dictionary(1, comparer) { { keySelector.Invoke(value), value } }); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionaryAsync, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); + => new Dictionary(1, comparer) { { await keySelector.InvokeAsync(value, cancellationToken).ConfigureAwait(false), value } }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueTask> ToDictionaryAsync(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) + public async ValueTask> ToDictionaryAsync(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default, CancellationToken cancellationToken = default) where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction + where TKeySelector : struct, IAsyncFunction + where TElementSelector : struct, IAsyncFunction // ReSharper disable once HeapView.ObjectAllocation.Evident - => new(result: new Dictionary(1, comparer) { { keySelector.Invoke(value), elementSelector.Invoke(value) } }); + => new Dictionary(1, comparer) { { await keySelector.InvokeAsync(value, cancellationToken).ConfigureAwait(false), await elementSelector.InvokeAsync(value, cancellationToken).ConfigureAwait(false) } }; } #pragma warning disable IDE0060 // Remove unused parameter diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/CreateValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Generation/ValueEnumerable/CreateValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/CreateValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs b/NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Empty.cs similarity index 100% rename from NetFabric.Hyperlinq/Generation/ValueEnumerable/Empty.cs rename to NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Empty.cs diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Range.cs similarity index 92% rename from NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs rename to NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Range.cs index dbe032359..2443a0670 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Range.cs @@ -29,7 +29,6 @@ public static RangeEnumerable Range(int start, int count) return new RangeEnumerable(start, count); } - [GeneratorMapping("TSource", "int", true)] [StructLayout(LayoutKind.Auto)] public readonly partial struct RangeEnumerable : IValueReadOnlyList @@ -123,23 +122,20 @@ void IList.RemoveAt(int index) public struct Enumerator { readonly int end; - int current; internal Enumerator(in RangeEnumerable enumerable) { - current = enumerable.start - 1; - end = current + enumerable.Count; + Current = enumerable.start - 1; + end = Current + enumerable.Count; } - public int Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => current; + public int Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; private set; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++current <= end; + => ++Current <= end; } [StructLayout(LayoutKind.Auto)] @@ -147,26 +143,23 @@ public struct DisposableEnumerator : IEnumerator { readonly int end; - int current; internal DisposableEnumerator(in RangeEnumerable enumerable) { - current = enumerable.start - 1; - end = current + enumerable.Count; + Current = enumerable.start - 1; + end = Current + enumerable.Count; } - public int Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => current; + public int Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; private set; } object? IEnumerator.Current // ReSharper disable once HeapView.BoxingAllocation - => current; + => Current; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++current <= end; + => ++Current <= end; [ExcludeFromCodeCoverage] [DoesNotReturn] diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs b/NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Repeat.cs similarity index 97% rename from NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs rename to NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Repeat.cs index 2f3a0ac0b..e45ccc3f7 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Repeat.cs +++ b/NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Repeat.cs @@ -166,10 +166,6 @@ public bool Contains(TSource value, IEqualityComparer? comparer) _ => count is not 0 && comparer.Equals(this.value, value) }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RepeatEnumerable Select(Func selector) - => Select>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public RepeatEnumerable Select(TSelector selector = default) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs b/NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Return.cs similarity index 88% rename from NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs rename to NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Return.cs index 58f85cb90..2011435bd 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Return.cs +++ b/NetFabric.Hyperlinq.Core/Generation/ValueEnumerable/Return.cs @@ -173,10 +173,6 @@ public bool Contains(TSource value, IEqualityComparer? comparer) _ => comparer.Equals(this.value, value) }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReturnEnumerable Select(Func selector) - => Select>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReturnEnumerable Select(TSelector selector = default) where TSelector : struct, IFunction @@ -207,11 +203,6 @@ public TSource[] ToArray() public List ToList() => new(1) { value }; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary(new FunctionWrapper(keySelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull @@ -219,11 +210,6 @@ public Dictionary ToDictionary(TKeySelector k // ReSharper disable once HeapView.ObjectAllocation.Evident => new(new Dictionary(1, comparer) { { keySelector.Invoke(value), value } }); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ToDictionary, FunctionWrapper>(new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) where TKey : notnull diff --git a/NetFabric.Hyperlinq/GlobalSuppressions.cs b/NetFabric.Hyperlinq.Core/GlobalSuppressions.cs similarity index 100% rename from NetFabric.Hyperlinq/GlobalSuppressions.cs rename to NetFabric.Hyperlinq.Core/GlobalSuppressions.cs diff --git a/NetFabric.Hyperlinq/Lease.cs b/NetFabric.Hyperlinq.Core/Lease.cs similarity index 100% rename from NetFabric.Hyperlinq/Lease.cs rename to NetFabric.Hyperlinq.Core/Lease.cs diff --git a/NetFabric.Hyperlinq.Core/NetFabric.Hyperlinq.Core.csproj b/NetFabric.Hyperlinq.Core/NetFabric.Hyperlinq.Core.csproj new file mode 100644 index 000000000..c36b41a0c --- /dev/null +++ b/NetFabric.Hyperlinq.Core/NetFabric.Hyperlinq.Core.csproj @@ -0,0 +1,84 @@ + + + + netstandard2.0;netcoreapp3.1;net5.0;net6.0 + NetFabric.Hyperlinq.Core + NetFabric.Hyperlinq.Core + The main assembly of NetFabric.Hyperlinq. + 1.0.0-beta00 + Icon.png + LICENSE + netfabric, hyperlinq, linq, enumeration, extensions, performance + true + true + true + snupkg + true + + NetFabric.Hyperlinq + + + + + $(NoWarn);8600;8601;8602;8603;8604 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + True + True + Resource.resx + + + + + + ResXFileCodeGenerator + Resource.Designer.cs + + + + diff --git a/NetFabric.Hyperlinq/Option/NoneOption.cs b/NetFabric.Hyperlinq.Core/Option/NoneOption.cs similarity index 100% rename from NetFabric.Hyperlinq/Option/NoneOption.cs rename to NetFabric.Hyperlinq.Core/Option/NoneOption.cs diff --git a/NetFabric.Hyperlinq/Option/Option.cs b/NetFabric.Hyperlinq.Core/Option/Option.cs similarity index 99% rename from NetFabric.Hyperlinq/Option/Option.cs rename to NetFabric.Hyperlinq.Core/Option/Option.cs index 6eb50cea1..88744c90d 100644 --- a/NetFabric.Hyperlinq/Option/Option.cs +++ b/NetFabric.Hyperlinq.Core/Option/Option.cs @@ -222,7 +222,6 @@ public List ToList() }; - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectManyEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Partitioning/Skip/Skip.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ReadOnlyList.cs similarity index 94% rename from NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs rename to NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ReadOnlyList.cs index 4e30d7049..132bfd81a 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ReadOnlyList.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static SkipTakeEnumerable Skip(this TList source, int count) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ValueReadOnlyCollection.cs similarity index 100% rename from NetFabric.Hyperlinq/Partitioning/Skip/Skip.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ValueReadOnlyCollection.cs diff --git a/NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ValueReadOnlyList.cs new file mode 100644 index 000000000..6c808b833 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Partitioning/Skip/Skip.ValueReadOnlyList.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueReadOnlyCollectionExtensions.SkipTakeEnumerable Skip(this TEnumerable source, int count) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.Skip(source, count); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs similarity index 88% rename from NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs rename to NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs index d98d9f8f1..69727b49b 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.ReadOnlyList.cs @@ -278,32 +278,5 @@ static bool ComparerContains(TList source, TSource value, IEqualityComparer(this in SkipTakeEnumerable source) - where TList : struct, IReadOnlyList - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SkipTakeEnumerable source, Func predicate) - where TList : struct, IReadOnlyList - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SkipTakeEnumerable source, TPredicate predicate = default) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SkipTakeEnumerable source, Func predicate) - where TList : struct, IReadOnlyList - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this SkipTakeEnumerable source, TPredicate predicate = default) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => source.CountAt(predicate); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs similarity index 82% rename from NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs index ab93810ac..d3070fa55 100644 --- a/NetFabric.Hyperlinq/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Partitioning/SkipTake/SkipTake.ValueReadOnlyCollection.cs @@ -250,37 +250,5 @@ public SkipTakeEnumerable Take(int count) #endregion } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in SkipTakeEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SkipTakeEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SkipTakeEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SkipTakeEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this SkipTakeEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.CountAt(predicate); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Partitioning/Take/Take.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Partitioning/Take/Take.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Partitioning/Take/Take.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ReadOnlyList.cs similarity index 94% rename from NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs rename to NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ReadOnlyList.cs index c9c2f0361..915fe8bcf 100644 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ReadOnlyList.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static SkipTakeEnumerable Take(this TList source, int count) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Partitioning/Take/Take.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ValueReadOnlyCollection.cs similarity index 100% rename from NetFabric.Hyperlinq/Partitioning/Take/Take.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ValueReadOnlyCollection.cs diff --git a/NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ValueReadOnlyList.cs new file mode 100644 index 000000000..02fa9d9ad --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Partitioning/Take/Take.ValueReadOnlyList.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueReadOnlyCollectionExtensions.SkipTakeEnumerable Take(this TEnumerable source, int count) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.Take(source, count); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ArraySegment.cs similarity index 73% rename from NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ArraySegment.cs index f72ec8ee4..a8a19b00d 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ArraySegment.cs @@ -10,7 +10,6 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentSelectEnumerable> Select(this in ArraySegment source, Func selector) => source.Select>(new FunctionWrapper(selector)); @@ -20,7 +19,6 @@ static ArraySegmentSelectEnumerable Select => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct ArraySegmentSelectEnumerable : IValueReadOnlyList.Enumerator> @@ -92,7 +90,7 @@ void ICollection.Add(TResult item) void ICollection.Clear() => Throw.NotSupportedException(); public bool Contains(TResult item) - => ((ReadOnlySpan)source.AsSpan()).Contains(item, default, selector); + => source.AsReadOnlySpan().Contains(item, default, selector); bool ICollection.Remove(TResult item) => Throw.NotSupportedException(); @@ -183,41 +181,28 @@ public ArraySegmentSelectAtEnumerable => source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - #endregion #region Element [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAt(index, selector); + => source.AsReadOnlySpan().ElementAt(index, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).First(selector); + => source.AsReadOnlySpan().First(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() - => ((ReadOnlySpan)source.AsSpan()).Single(selector); + => source.AsReadOnlySpan().Single(selector); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArray(selector); + => source.AsReadOnlySpan().ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) @@ -225,32 +210,17 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToList(selector); + => source.AsReadOnlySpan().ToList(selector); #endregion } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentSelectEnumerable source) - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentSelectEnumerable source, Func predicate) - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this ArraySegmentSelectEnumerable source, TPredicate predicate = default) where TSelector : struct, IFunction where TPredicate : struct, IFunction => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentSelectEnumerable source, Func predicate) - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountAt(this ArraySegmentSelectEnumerable source, TPredicate predicate = default) where TSelector : struct, IFunction @@ -260,72 +230,72 @@ public static int CountAt(this ArraySeg [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.AsyncValueEnumerable.cs similarity index 92% rename from NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.AsyncValueEnumerable.cs index 49d3d76a7..cf9417147 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -12,13 +12,6 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.AsyncFunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectEnumerable> Select(this TEnumerable source, Func> selector) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - => source.Select>(new AsyncFunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectEnumerable Select(this TEnumerable source, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -26,7 +19,6 @@ public static SelectEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectEnumerable : IAsyncValueEnumerable.Enumerator> @@ -216,20 +208,12 @@ public ValueTask AnyAsync(CancellationToken cancellationToken = default) #endregion #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectEnumerable, TSource, TResult, TResult2>> Select(Func> selector) - => Select>(new AsyncFunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IAsyncFunction => source.Select>(new AsyncSelectorSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func> selector) - => SelectAt>(new AsyncFunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ReadOnlyMemory.cs similarity index 84% rename from NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ReadOnlyMemory.cs index b62a3715c..6b7094a0f 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.Select>(new FunctionWrapper(selector)); @@ -21,7 +20,6 @@ static MemorySelectEnumerable Select => new(source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct MemorySelectEnumerable : IValueReadOnlyList.Enumerator> @@ -171,19 +169,6 @@ public MemorySelectAtEnumerable => source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - #endregion #region Element @@ -215,27 +200,12 @@ public List ToList() #endregion } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemorySelectEnumerable source) - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemorySelectEnumerable source, Func predicate) - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, MemorySelectEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this MemorySelectEnumerable source, TPredicate predicate = default) where TSelector : struct, IFunction where TPredicate : struct, IFunction => ValueReadOnlyCollectionExtensions.Count, MemorySelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemorySelectEnumerable source, Func predicate) - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, MemorySelectEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountAt(this MemorySelectEnumerable source, TPredicate predicate = default) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ReadOnlySpan.cs similarity index 96% rename from NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ReadOnlySpan.cs index 7c3bae6fa..81181db8a 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectEnumerable> Select(this ReadOnlySpan source, Func selector) => source.Select>(new FunctionWrapper(selector)); @@ -19,7 +18,6 @@ static SpanSelectEnumerable Select => new(source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public ref struct SpanSelectEnumerable where TSelector : struct, IFunction @@ -132,11 +130,6 @@ public bool SequenceEqual(IEnumerable other, IEqualityComparer } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanSelectEnumerable source) - where TSelector : struct, IFunction - => source.Count; - // [MethodImpl(MethodImplOptions.AggressiveInlining)] // public static int Count(this SpanSelectEnumerable source, Func predicate) // where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ValueEnumerable.cs similarity index 86% rename from NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ValueEnumerable.cs index 868a3013e..f45fc6316 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ValueEnumerable.cs @@ -11,13 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectEnumerable> Select(this TEnumerable source, Func selector) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.Select>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectEnumerable Select(this TEnumerable source, TSelector selector = default) where TEnumerable : IValueEnumerable @@ -25,7 +18,6 @@ public static SelectEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectEnumerable : IValueEnumerable.Enumerator> @@ -106,31 +98,17 @@ public bool Any() #endregion #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => source.Select>(new SelectorSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => SelectAt>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction => source.SelectAt>(new SelectorSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ValueReadOnlyCollection.cs similarity index 77% rename from NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index 03ae3ac84..b472b0695 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -11,13 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectEnumerable> Select(this TEnumerable source, Func selector) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => Select>(source, new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectEnumerable Select(this TEnumerable source, TSelector selector = default) where TEnumerable : IValueReadOnlyCollection @@ -25,7 +18,6 @@ public static SelectEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct SelectEnumerable : IValueReadOnlyCollection.Enumerator> @@ -140,38 +132,17 @@ public bool Any() #endregion #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueReadOnlyCollectionExtensions.Select>(source, new SelectorSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => SelectAt>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueReadOnlyCollectionExtensions.SelectAt>(source, new SelectorSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - #endregion #region Element @@ -204,20 +175,6 @@ public List ToList() #endregion } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in SelectEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SelectEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => Count, SelectEnumerable.Enumerator, TResult>(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this SelectEnumerable source, TPredicate predicate = default) @@ -227,13 +184,6 @@ public static int Count => Count, SelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SelectEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => Count, SelectEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountAt(this SelectEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ValueReadOnlyList.cs similarity index 81% rename from NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ValueReadOnlyList.cs index 67ee2408c..9966ada5c 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyListExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectEnumerable> Select(this TEnumerable source, Func selector) where TEnumerable : struct, IValueReadOnlyList @@ -25,7 +24,6 @@ public static SelectEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct SelectEnumerable : IValueReadOnlyList.Enumerator> @@ -160,38 +158,17 @@ public void Dispose() #endregion #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueReadOnlyListExtensions.Select>(source, new SelectorSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => SelectAt>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueReadOnlyListExtensions.SelectAt>(source, new SelectorSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - #endregion #region Element @@ -230,20 +207,6 @@ public readonly List ToList() #endregion } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in SelectEnumerable source) - where TEnumerable : struct, IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SelectEnumerable source, Func predicate) - where TEnumerable : struct, IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, SelectEnumerable.Enumerator, TResult>(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this SelectEnumerable source, TPredicate predicate = default) @@ -253,13 +216,6 @@ public static int Count => ValueReadOnlyCollectionExtensions.Count, SelectEnumerable.Enumerator, TResult, TPredicate>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SelectEnumerable source, Func predicate) - where TEnumerable : struct, IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, SelectEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountAt(this SelectEnumerable source, TPredicate predicate = default) where TEnumerable : struct, IValueReadOnlyList diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/SelectEnumerator.cs b/NetFabric.Hyperlinq.Core/Projection/Select/Select/SelectEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/Select/SelectEnumerator.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/Select/SelectEnumerator.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ArraySegment.cs similarity index 81% rename from NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index 8c531f0d7..8a86230a4 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -10,7 +10,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentSelectAtEnumerable> Select(this in ArraySegment source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); @@ -20,7 +20,6 @@ static ArraySegmentSelectAtEnumerable SelectAt => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct ArraySegmentSelectAtEnumerable : IValueReadOnlyList.Enumerator> @@ -85,7 +84,7 @@ void ICollection.Add(TResult item) void ICollection.Clear() => Throw.NotSupportedException(); public bool Contains(TResult item) - => ((ReadOnlySpan)source.AsSpan()).ContainsAt(item, default, selector); + => source.AsReadOnlySpan().ContainsAt(item, default, selector); bool ICollection.Remove(TResult item) => Throw.NotSupportedException(); int IList.IndexOf(TResult item) @@ -175,40 +174,27 @@ public ArraySegmentSelectAtEnumerable => source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - #endregion #region Element [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAtAt(index, selector); + => source.AsReadOnlySpan().ElementAtAt(index, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).FirstAt(selector); + => source.AsReadOnlySpan().FirstAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() - => ((ReadOnlySpan)source.AsSpan()).SingleAt(selector); + => source.AsReadOnlySpan().SingleAt(selector); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(selector); + => source.AsReadOnlySpan().ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) @@ -216,32 +202,17 @@ public Lease ToArray(ArrayPool pool, bool clearOnDispose = def [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToListAt(selector); + => source.AsReadOnlySpan().ToListAt(selector); #endregion } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentSelectAtEnumerable source) - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentSelectAtEnumerable source, Func predicate) - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectAtEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this ArraySegmentSelectAtEnumerable source, TPredicate predicate = default) where TSelector : struct, IFunction where TPredicate : struct, IFunction => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectAtEnumerable.Enumerator, TResult, TPredicate>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentSelectAtEnumerable source, Func predicate) - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, ArraySegmentSelectAtEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountAt(this ArraySegmentSelectAtEnumerable source, TPredicate predicate = default) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs similarity index 92% rename from NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index f299225a0..d4b1152cd 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -12,13 +12,6 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.AsyncFunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectAtEnumerable> Select(this TEnumerable source, Func> selector) - where TEnumerable : IAsyncValueEnumerable - where TEnumerator : struct, IAsyncEnumerator - => source.SelectAt>(new AsyncFunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectAtEnumerable SelectAt(this TEnumerable source, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -26,7 +19,6 @@ public static SelectAtEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectAtEnumerable : IAsyncValueEnumerable.Enumerator> @@ -218,20 +210,12 @@ public ValueTask AnyAsync(CancellationToken cancellationToken = default) #endregion #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func> selector) - => Select>(new AsyncFunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IAsyncFunction => source.SelectAt>(new AsyncSelectorAtSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func> selector) - => SelectAt>(new AsyncFunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IAsyncFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs similarity index 83% rename from NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 74f31826f..b67c20fec 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectAtEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); @@ -21,7 +20,6 @@ static MemorySelectAtEnumerable SelectAt => new(source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct MemorySelectAtEnumerable : IValueReadOnlyList.Enumerator> @@ -163,19 +161,6 @@ public MemorySelectAtEnumerable => source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - #endregion #region Element @@ -207,27 +192,12 @@ public List ToList() #endregion } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemorySelectAtEnumerable source) - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemorySelectAtEnumerable source, Func predicate) - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, MemorySelectAtEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this MemorySelectAtEnumerable source, TPredicate predicate = default) where TSelector : struct, IFunction where TPredicate : struct, IFunction => source.Count(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this MemorySelectAtEnumerable source, Func predicate) - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, MemorySelectAtEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountAt(this MemorySelectAtEnumerable source, TPredicate predicate = default) where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs similarity index 96% rename from NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index dc30405c3..77490c8b0 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectAtEnumerable> Select(this ReadOnlySpan source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); @@ -19,7 +18,6 @@ static SpanSelectAtEnumerable SelectAt => new(source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public ref struct SpanSelectAtEnumerable where TSelector : struct, IFunction @@ -132,11 +130,6 @@ public bool SequenceEqual(IEnumerable other, IEqualityComparer } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanSelectAtEnumerable source) - where TSelector : struct, IFunction - => source.Count; - // [MethodImpl(MethodImplOptions.AggressiveInlining)] // public static int Count(this SpanSelectAtEnumerable source, Func predicate) // where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs similarity index 86% rename from NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index 524d6dc67..6ce156e76 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -11,13 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectAtEnumerable> Select(this TEnumerable source, Func selector) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.SelectAt>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectAtEnumerable SelectAt(this TEnumerable source, TSelector selector = default) where TEnumerable : IValueEnumerable @@ -25,7 +18,6 @@ public static SelectAtEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectAtEnumerable : IValueEnumerable.Enumerator> @@ -116,31 +108,17 @@ public bool Any() #endregion #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => source.SelectAt>(new SelectorAtSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => SelectAt>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction => source.SelectAt>(new SelectorAtSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) where TSubEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs similarity index 78% rename from NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index cfd0e6ca8..98f68523f 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -11,13 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectAtEnumerable> Select(this TEnumerable source, Func selector) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => SelectAt>(source, new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectAtEnumerable SelectAt(this TEnumerable source, TSelector selector = default) where TEnumerable : IValueReadOnlyCollection @@ -25,7 +18,6 @@ public static SelectAtEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct SelectAtEnumerable : IValueReadOnlyCollection.Enumerator> @@ -149,38 +141,17 @@ public bool Any() #endregion #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueReadOnlyCollectionExtensions.SelectAt>(source, new SelectorAtSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => SelectAt>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueReadOnlyCollectionExtensions.SelectAt>(source, new SelectorAtSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - #endregion #region Element @@ -213,20 +184,6 @@ public List ToList() #endregion } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in SelectAtEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SelectAtEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => Count, SelectAtEnumerable.Enumerator, TResult>(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this SelectAtEnumerable source, TPredicate predicate = default) @@ -236,13 +193,6 @@ public static int Count => Count, SelectAtEnumerable.Enumerator, TResult, TPredicate>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SelectAtEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => Count, SelectAtEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountAt(this SelectAtEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs similarity index 81% rename from NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs index 6c8435ce8..9d270ce69 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyListExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectAtEnumerable> Select(this TEnumerable source, Func selector) where TEnumerable : struct, IValueReadOnlyList @@ -25,7 +24,6 @@ public static SelectAtEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct SelectAtEnumerable : IValueReadOnlyList.Enumerator> @@ -176,38 +174,17 @@ public void Dispose() #endregion #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select>(new FunctionWrapper(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly SelectAtEnumerable> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueReadOnlyListExtensions.SelectAt>(source, new SelectorAtSelectorCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectAtEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => SelectAt>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly SelectAtEnumerable> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueReadOnlyListExtensions.SelectAt>(source, new SelectorAtSelectorAtCombination(this.selector, selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, FunctionWrapper> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2>(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerableExtensions.SelectManyEnumerable, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2> SelectMany(TSelector2 selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector2 : struct, IFunction - => this.SelectMany, Enumerator, TResult, TSubEnumerable, TSubEnumerator, TResult2, TSelector2>(selector); - #endregion #region Element @@ -247,20 +224,6 @@ public readonly List ToList() #endregion } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this in SelectAtEnumerable source) - where TEnumerable : struct, IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SelectAtEnumerable source, Func predicate) - where TEnumerable : struct, IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, SelectAtEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this SelectAtEnumerable source, TPredicate predicate = default) where TEnumerable : struct, IValueReadOnlyList @@ -269,13 +232,6 @@ public static int Count => ValueReadOnlyCollectionExtensions.Count, SelectAtEnumerable.Enumerator, TResult, TPredicate>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SelectAtEnumerable source, Func predicate) - where TEnumerable : struct, IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => ValueReadOnlyCollectionExtensions.Count, SelectAtEnumerable.Enumerator, TResult>(source, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CountAt(this SelectAtEnumerable source, TPredicate predicate = default) where TEnumerable : struct, IValueReadOnlyList diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAtEnumerator.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAtEnumerator.cs similarity index 100% rename from NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAtEnumerator.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectAt/SelectAtEnumerator.cs diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectVector/SelectVector.Range.cs similarity index 99% rename from NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectVector/SelectVector.Range.cs index db1b3deda..9da26df94 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/SelectVector/SelectVector.Range.cs @@ -30,7 +30,7 @@ static RangeSelectVectorContext SelectVecto where TResult : struct => new(start, count, vectorSelector, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public partial struct RangeSelectVectorContext where TVectorSelector : struct, IFunction, Vector> diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs similarity index 99% rename from NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs index a3a7aee03..63532d693 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs @@ -10,14 +10,12 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(true)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ReadOnlySpan source, Func, Vector> vectorSelector, Func selector) where TSource : struct where TResult : struct => source.SelectVector, Vector>, FunctionWrapper>(new FunctionWrapper, Vector>(vectorSelector), new FunctionWrapper(selector)); - [GeneratorIgnore(true)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectVectorContext SelectVector(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction, Vector>, IFunction diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs similarity index 88% rename from NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs rename to NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs index 0bd25b721..0ff7c776a 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs +++ b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentSelectManyEnumerable> SelectMany(this in ArraySegment source, Func selector) where TSubEnumerable : IValueEnumerable @@ -23,7 +22,7 @@ static ArraySegmentSelectManyEnumerable => new(source, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public readonly partial struct ArraySegmentSelectManyEnumerable : IValueEnumerable.Enumerator> @@ -131,19 +130,11 @@ public int Count() public bool Any() => this.Any, Enumerator, TResult>(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate predicate = default) where TPredicate : struct, IFunction => this.Any, Enumerator, TResult, TPredicate>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate predicate = default) where TPredicate : struct, IFunction @@ -152,19 +143,11 @@ public bool AnyAt(TPredicate predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) where TPredicate : struct, IFunction => ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, IFunction @@ -173,19 +156,11 @@ public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2, TSelector2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs similarity index 88% rename from NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs index 5fa18194b..fa71360ee 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs @@ -10,7 +10,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectManyEnumerable> SelectMany(this in ReadOnlyMemory source, Func selector) where TSubEnumerable : IValueEnumerable @@ -24,7 +23,7 @@ static MemorySelectManyEnumerable => new(source, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public readonly partial struct MemorySelectManyEnumerable : IValueEnumerable.Enumerator> @@ -130,19 +129,11 @@ public int Count() public bool Any() => this.Any, Enumerator, TResult>(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate predicate = default) where TPredicate : struct, IFunction => this.Any, Enumerator, TResult, TPredicate>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate predicate = default) where TPredicate : struct, IFunction @@ -151,19 +142,11 @@ public bool AnyAt(TPredicate predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) where TPredicate : struct, IFunction => ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, IFunction @@ -172,19 +155,11 @@ public ValueEnumerableExtensions.WhereEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2, TSelector2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueEnumerableExtensions.SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs similarity index 99% rename from NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs index 6f7bff87a..32ba6343b 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectManyEnumerable> SelectMany(this ReadOnlySpan source, Func selector) where TSubEnumerable : IValueEnumerable @@ -23,7 +22,7 @@ static SpanSelectManyEnumerable => new(source, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public readonly ref struct SpanSelectManyEnumerable where TSubEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs similarity index 86% rename from NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs index bc5c33140..b07960280 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs @@ -10,15 +10,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SelectManyEnumerable> SelectMany(this TEnumerable source, Func selector) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => source.SelectMany>(new FunctionWrapper(selector)); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectManyEnumerable SelectMany(this TEnumerable source, TSelector selector = default) where TEnumerable : IValueEnumerable @@ -28,7 +19,7 @@ public static SelectManyEnumerable => new(source, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectManyEnumerable : IValueEnumerable.Enumerator> @@ -132,19 +123,11 @@ public int Count() public bool Any() => this.Any, Enumerator, TResult>(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate predicate = default) where TPredicate : struct, IFunction => this.Any, Enumerator, TResult, TPredicate>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => this.Any, Enumerator, TResult>(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate predicate = default) where TPredicate : struct, IFunction @@ -153,19 +136,11 @@ public bool AnyAt(TPredicate predicate = default) #endregion #region Filtering - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereAtEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereAtEnumerable, Enumerator, TResult, TPredicate> WhereAt(TPredicate predicate = default) where TPredicate : struct, IFunction => ValueEnumerableExtensions.WhereAt, Enumerator, TResult, TPredicate>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public WhereEnumerable, Enumerator, TResult, FunctionWrapper> Where(Func predicate) - => ValueEnumerableExtensions.Where, Enumerator, TResult>(this, predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public WhereEnumerable, Enumerator, TResult, TPredicate> Where(TPredicate predicate = default) where TPredicate : struct, IFunction @@ -174,19 +149,11 @@ public WhereEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectEnumerable, Enumerator, TResult, TResult2, TSelector2> Select(TSelector2 selector = default) where TSelector2 : struct, IFunction => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2, TSelector2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SelectAtEnumerable, Enumerator, TResult, TResult2, FunctionWrapper> Select(Func selector) - => ValueEnumerableExtensions.Select, Enumerator, TResult, TResult2>(this, selector); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectAtEnumerable, Enumerator, TResult, TResult2, TSelector2> SelectAt(TSelector2 selector = default) where TSelector2 : struct, IFunction diff --git a/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyCollection.cs new file mode 100644 index 000000000..b171a53c8 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyCollection.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadonlyCollectionExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerableExtensions.SelectManyEnumerable SelectMany(this TEnumerable source, TSelector selector = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueEnumerableExtensions.SelectMany(source, selector); + } +} + diff --git a/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs new file mode 100644 index 000000000..2425f25bb --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Projection/SelectMany/SelectMany/SelectMany.ValueReadOnlyList.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadonlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerableExtensions.SelectManyEnumerable SelectMany(this TEnumerable source, TSelector selector = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TSubEnumerable : IValueEnumerable + where TSubEnumerator : struct, IEnumerator + where TSelector : struct, IFunction + => ValueEnumerableExtensions.SelectMany(source, selector); + } +} + diff --git a/NetFabric.Hyperlinq.Core/Properties/AssemblyInfo.cs b/NetFabric.Hyperlinq.Core/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..c1bd8a3cf --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly:InternalsVisibleTo("NetFabric.Hyperlinq.Core.UnitTests")] \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Quantifier/All/All.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Quantifier/All/All.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Quantifier/All/All.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueEnumerable.cs similarity index 61% rename from NetFabric.Hyperlinq/Quantifier/All/All.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueEnumerable.cs index a43bc4eeb..356f3c912 100644 --- a/NetFabric.Hyperlinq/Quantifier/All/All.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueEnumerable.cs @@ -7,12 +7,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.All>(new FunctionWrapper(predicate)); - public static bool All(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -26,13 +20,6 @@ public static bool All(this TEnum } return true; } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.AllAt>(new FunctionWrapper(predicate)); public static bool AllAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueReadOnlyCollection.cs similarity index 57% rename from NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueReadOnlyCollection.cs index 7eb86823a..b1abcc6b7 100644 --- a/NetFabric.Hyperlinq/Quantifier/All/All.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueReadOnlyCollection.cs @@ -6,12 +6,6 @@ namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyCollectionExtensions { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this TEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => All>(source, new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool All(this TEnumerable source, TPredicate predicate = default) @@ -19,12 +13,6 @@ public static bool All(this TEnum where TEnumerator : struct, IEnumerator where TPredicate : struct, IFunction => source.Count is 0 || ValueEnumerableExtensions.All(source, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool All(this TEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => AllAt>(source, new FunctionWrapper(predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AllAt(this TEnumerable source, TPredicate predicate = default) diff --git a/NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueReadOnlyList.cs new file mode 100644 index 000000000..d94386393 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Quantifier/All/All.ValueReadOnlyList.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool All(this TEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.All(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool AllAt(this TEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.AllAt(source, predicate); + } +} + diff --git a/NetFabric.Hyperlinq/Quantifier/All/AllAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Quantifier/All/AllAsync.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Quantifier/All/AllAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Quantifier/All/AllAsync.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Quantifier/Any/Any.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueEnumerable.cs similarity index 66% rename from NetFabric.Hyperlinq/Quantifier/Any/Any.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueEnumerable.cs index 6cfd4c202..985603f09 100644 --- a/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueEnumerable.cs @@ -15,12 +15,6 @@ public static bool Any(this TEnumerable sourc return enumerator.MoveNext(); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.Any>(new FunctionWrapper(predicate)); - public static bool Any(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -35,12 +29,6 @@ public static bool Any(this TEnum return false; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.AnyAt>(new FunctionWrapper(predicate)); - public static bool AnyAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueReadOnlyCollection.cs similarity index 78% rename from NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueReadOnlyCollection.cs index 49d4c1145..5dad306eb 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueReadOnlyCollection.cs @@ -14,17 +14,18 @@ public static bool Any(this TEnumerable sourc => source.Count is not 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source, Func predicate) + public static bool Any(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator - => Any>(source, new FunctionWrapper(predicate)); + where TPredicate : struct, IFunction + => source.Count is not 0 && ValueEnumerableExtensions.Any(source, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source, TPredicate predicate = default) + public static bool AnyAt(this TEnumerable source, TPredicate predicate = default) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.Count is not 0 && ValueEnumerableExtensions.Any(source, predicate); + where TPredicate : struct, IFunction + => source.Count is not 0 && ValueEnumerableExtensions.AnyAt(source, predicate); } } diff --git a/NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueReadOnlyList.cs new file mode 100644 index 000000000..d2df510ab --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Quantifier/Any/Any.ValueReadOnlyList.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool Any(this TEnumerable source) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.Any(source); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool Any(this TEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.Any(source, predicate); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool AnyAt(this TEnumerable source, TPredicate predicate = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + where TPredicate : struct, IFunction + => ValueReadOnlyCollectionExtensions.AnyAt(source, predicate); + } +} + diff --git a/NetFabric.Hyperlinq/Quantifier/Any/AnyAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Quantifier/Any/AnyAsync.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Quantifier/Any/AnyAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Quantifier/Any/AnyAsync.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.Enumerable.cs similarity index 98% rename from NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs rename to NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.Enumerable.cs index 0d061f9d6..052400a66 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.Enumerable.cs @@ -4,7 +4,7 @@ namespace NetFabric.Hyperlinq { public static partial class EnumerableExtensions { - [GeneratorIgnore] + internal static bool Contains(this TEnumerable source, TSource value, IEqualityComparer? comparer = default) where TEnumerable : IEnumerable { @@ -44,7 +44,7 @@ static bool ComparerContains(TEnumerable source, TSource value, IEqualityCompare } } - [GeneratorIgnore] + internal static bool Contains(this TEnumerable source, TEnumeratorGenerator getEnumerator, TSource value, IEqualityComparer? comparer = default) where TEnumerable : IEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ReadOnlySpan.cs similarity index 98% rename from NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ReadOnlySpan.cs index 767f1619b..67fcb78d4 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ReadOnlySpan.cs @@ -37,7 +37,7 @@ static bool ReferenceContains(ReadOnlySpan source, TSource value, IEqua } } - [GeneratorIgnore] + static bool Contains(this ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) where TSelector : struct, IFunction { @@ -71,7 +71,7 @@ static bool ReferenceContains(ReadOnlySpan source, TResult value, IEqua } } - [GeneratorIgnore] + static bool ContainsAt(this ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) where TSelector : struct, IFunction { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueEnumerable.cs similarity index 98% rename from NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueEnumerable.cs index 6f5605ad9..0540ec1b5 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -45,7 +45,7 @@ static bool ComparerContains(TEnumerable source, TSource value, IEqualityCompare } - [GeneratorIgnore] + internal static bool Contains(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -80,7 +80,7 @@ static bool ReferenceContains(TEnumerable source, TResult value, IEqualityCompar } } - [GeneratorIgnore] + internal static bool ContainsAt(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs similarity index 97% rename from NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs index 080b9a4f3..4c4e1e62e 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs @@ -11,7 +11,7 @@ public static bool Contains(this TEnumerable where TEnumerator : struct, IEnumerator => source.Count is not 0 && ValueEnumerableExtensions.Contains(source, value, comparer); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool Contains(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -19,7 +19,7 @@ internal static bool Contains => source.Count is not 0 && ValueEnumerableExtensions.Contains(source, value, comparer, selector); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool ContainsAt(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueReadOnlyList.cs new file mode 100644 index 000000000..fd94cdc4d --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Quantifier/Contains/Contains.ValueReadOnlyList.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool Contains(this TEnumerable source, TSource value, IEqualityComparer? comparer = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.Contains(source, value, comparer); + } +} diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Quantifier/Contains/ContainsAsync.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs similarity index 98% rename from NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs index 516503ef2..11c7e6beb 100644 --- a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs @@ -34,7 +34,7 @@ static bool ContainsVector(this ReadOnlySpan source, TSource v return false; } - [GeneratorIgnore] + static bool ContainsVector(this ReadOnlySpan source, TResult value, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs b/NetFabric.Hyperlinq.Core/Quantifier/ContainsVector/ContainsVector.Span.cs similarity index 82% rename from NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs rename to NetFabric.Hyperlinq.Core/Quantifier/ContainsVector/ContainsVector.Span.cs index 9dbfc7401..0bfe618fe 100644 --- a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs +++ b/NetFabric.Hyperlinq.Core/Quantifier/ContainsVector/ContainsVector.Span.cs @@ -9,7 +9,7 @@ public static partial class ArrayExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool ContainsVector(this Span source, TSource value) where TSource : struct - => ((ReadOnlySpan)source).ContainsVector(value); + => source.AsReadOnlySpan().ContainsVector(value); } } diff --git a/NetFabric.Hyperlinq/Resource.Designer.cs b/NetFabric.Hyperlinq.Core/Resource.Designer.cs similarity index 100% rename from NetFabric.Hyperlinq/Resource.Designer.cs rename to NetFabric.Hyperlinq.Core/Resource.Designer.cs diff --git a/NetFabric.Hyperlinq/Resource.resx b/NetFabric.Hyperlinq.Core/Resource.resx similarity index 100% rename from NetFabric.Hyperlinq/Resource.resx rename to NetFabric.Hyperlinq.Core/Resource.resx diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ArraySegment.cs similarity index 58% rename from NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs rename to NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ArraySegment.cs index 8a2511cfc..ffbe3f74b 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs +++ b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ArraySegment.cs @@ -148,62 +148,6 @@ public List ToList() #endregion } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, nint, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, nint?, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, nuint, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, nuint?, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentDistinctEnumerable source) - => source.Sum, ArraySegmentDistinctEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.AsyncValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Set/Distinct/Distinct.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.AsyncValueEnumerable.cs diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ReadOnlyMemory.cs similarity index 59% rename from NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs rename to NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ReadOnlyMemory.cs index d028c5864..9a7d0fbd2 100644 --- a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ReadOnlyMemory.cs @@ -146,62 +146,6 @@ public List ToList() #endregion } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, nint, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, nint?, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, nuint, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, nuint?, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this MemoryDistinctEnumerable source) - => source.Sum, MemoryDistinctEnumerable.Enumerator, decimal?, decimal>(); } } diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Set/Distinct/Distinct.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueEnumerable.cs similarity index 100% rename from NetFabric.Hyperlinq/Set/Distinct/Distinct.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueEnumerable.cs diff --git a/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueReadOnlyCollection.cs new file mode 100644 index 000000000..bac8fe6d2 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueReadOnlyCollection.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyCollectionExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerableExtensions.DistinctEnumerable Distinct( + this TEnumerable source, + IEqualityComparer? comparer = default) + where TEnumerable : IValueReadOnlyCollection + where TEnumerator : struct, IEnumerator + => ValueEnumerableExtensions.Distinct(source, comparer); + } +} + diff --git a/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueReadOnlyList.cs new file mode 100644 index 000000000..dc8954e86 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Set/Distinct/Distinct.ValueReadOnlyList.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + public static partial class ValueReadOnlyListExtensions + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerableExtensions.DistinctEnumerable Distinct( + this TEnumerable source, + IEqualityComparer? comparer = default) + where TEnumerable : IValueReadOnlyList + where TEnumerator : struct, IEnumerator + => ValueReadOnlyCollectionExtensions.Distinct(source, comparer); + } +} + diff --git a/NetFabric.Hyperlinq/Set/Distinct/Set.cs b/NetFabric.Hyperlinq.Core/Set/Distinct/Set.cs similarity index 100% rename from NetFabric.Hyperlinq/Set/Distinct/Set.cs rename to NetFabric.Hyperlinq.Core/Set/Distinct/Set.cs diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ArrayBuilder.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs rename to NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ArrayBuilder.cs diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/LargeArrayBuilder.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/ArrayBuilder/LargeArrayBuilder.cs rename to NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/LargeArrayBuilder.cs diff --git a/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs new file mode 100644 index 000000000..585f4adc3 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs @@ -0,0 +1,70 @@ +using System.Buffers; +using System.Collections.Generic; + +namespace NetFabric.Hyperlinq +{ + public static partial class ReadOnlyListExtensions + { + + + static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) + where TList : struct, IReadOnlyList + where TPredicate: struct, IFunction + { + var builder = new LargeArrayBuilder(pool, clearOnDispose); + var end = offset + count; + for (var index = offset; index < end; index++) + { + var item = source[index]; + if (predicate.Invoke(item)) + builder.Add(item); + } + return builder; + } + + + static LargeArrayBuilder ToArrayBuilderAt(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) + where TList : struct, IReadOnlyList + where TPredicate: struct, IFunction + { + var builder = new LargeArrayBuilder(pool, clearOnDispose); + var end = count; + if (offset is 0) + { + for (var index = 0; index < end; index++) + { + var item = source[index]; + if (predicate.Invoke(item, index)) + builder.Add(item); + } + } + else + { + for (var index = 0; index < end; index++) + { + var item = source[index + offset]; + if (predicate.Invoke(item, index)) + builder.Add(item); + } + } + return builder; + } + + + static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector, int offset, int count) + where TList : struct, IReadOnlyList + where TSelector: struct, IFunction + where TPredicate: struct, IFunction + { + var builder = new LargeArrayBuilder(pool, clearOnDispose); + var end = offset + count; + for (var index = offset; index < end; index++) + { + var item = source[index]; + if (predicate.Invoke(item)) + builder.Add(selector.Invoke(item)); + } + return builder; + } + } +} diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs similarity index 96% rename from NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs index 4bf675d81..558e23fff 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TPredicate: struct, IFunction { @@ -19,7 +19,7 @@ static LargeArrayBuilder ToArrayBuilder(ReadOnlySp return builder; } - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilderAt(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TPredicate: struct, IFunction { @@ -33,7 +33,7 @@ static LargeArrayBuilder ToArrayBuilderAt(ReadOnly return builder; } - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate: struct, IFunction where TSelector: struct, IFunction diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs similarity index 96% rename from NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs index 4729f52c6..c85c6972c 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs @@ -6,7 +6,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorIgnore] internal static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -21,7 +20,7 @@ internal static LargeArrayBuilder ToArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -38,7 +37,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -55,7 +54,7 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -71,7 +70,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -90,7 +89,7 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs similarity index 97% rename from NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs rename to NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs index 4faaf8995..f4e6689a5 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.Core/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { - [GeneratorIgnore] + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -29,7 +29,7 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -55,7 +55,7 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -84,7 +84,7 @@ static async ValueTask> ToArrayBuilderAtAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -108,7 +108,7 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -135,7 +135,7 @@ static async ValueTask> ToArrayBuilderAtAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq.Core/Utils/ArrayExtensions.cs b/NetFabric.Hyperlinq.Core/Utils/ArrayExtensions.cs new file mode 100644 index 000000000..bdaa467ae --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Utils/ArrayExtensions.cs @@ -0,0 +1,16 @@ +using System; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class InternalArrayExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlySpan AsReadOnlySpan(this T[] source) + => source; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyMemory AsReadOnlyMemory(this T[] source) + => source; + } +} diff --git a/NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs b/NetFabric.Hyperlinq.Core/Utils/ArrayPoolExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/ArrayPoolExtensions.cs rename to NetFabric.Hyperlinq.Core/Utils/ArrayPoolExtensions.cs diff --git a/NetFabric.Hyperlinq/Utils/ArraySegmentExtensions.cs b/NetFabric.Hyperlinq.Core/Utils/ArraySegmentExtensions.cs similarity index 70% rename from NetFabric.Hyperlinq/Utils/ArraySegmentExtensions.cs rename to NetFabric.Hyperlinq.Core/Utils/ArraySegmentExtensions.cs index 30acec5f6..69fed9d4a 100644 --- a/NetFabric.Hyperlinq/Utils/ArraySegmentExtensions.cs +++ b/NetFabric.Hyperlinq.Core/Utils/ArraySegmentExtensions.cs @@ -12,7 +12,10 @@ public static bool IsEmpty(this in ArraySegment source) // NOTE: Inner array can only be null if length is zero. Should validate before calling this method. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWhole(this in ArraySegment source) - => source.Count == source.Array!.Length; + => source.Count == source.Array!.Length; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlySpan AsReadOnlySpan(this in ArraySegment source) + => source.AsSpan(); } } diff --git a/NetFabric.Hyperlinq/Utils/BooleanExtensions.cs b/NetFabric.Hyperlinq.Core/Utils/BooleanExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/BooleanExtensions.cs rename to NetFabric.Hyperlinq.Core/Utils/BooleanExtensions.cs diff --git a/NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs b/NetFabric.Hyperlinq.Core/Utils/Copy/Copy.Range.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/Copy/Copy.Range.cs rename to NetFabric.Hyperlinq.Core/Utils/Copy/Copy.Range.cs diff --git a/NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Utils/Copy/Copy.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/Copy/Copy.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Utils/Copy/Copy.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Utils/Copy/Copy.ValueReadOnlyCollection.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/Copy/Copy.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Utils/Copy/Copy.ValueReadOnlyCollection.cs diff --git a/NetFabric.Hyperlinq/Utils/Default.cs b/NetFabric.Hyperlinq.Core/Utils/Default.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/Default.cs rename to NetFabric.Hyperlinq.Core/Utils/Default.cs diff --git a/NetFabric.Hyperlinq/Utils/EnumeratorState.cs b/NetFabric.Hyperlinq.Core/Utils/EnumeratorState.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/EnumeratorState.cs rename to NetFabric.Hyperlinq.Core/Utils/EnumeratorState.cs diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncPredicateCombination.cs b/NetFabric.Hyperlinq.Core/Utils/FunctionCombination/AsyncPredicateCombination.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncPredicateCombination.cs rename to NetFabric.Hyperlinq.Core/Utils/FunctionCombination/AsyncPredicateCombination.cs diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncSelectorCombination.cs b/NetFabric.Hyperlinq.Core/Utils/FunctionCombination/AsyncSelectorCombination.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/FunctionCombination/AsyncSelectorCombination.cs rename to NetFabric.Hyperlinq.Core/Utils/FunctionCombination/AsyncSelectorCombination.cs diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateCombination.cs b/NetFabric.Hyperlinq.Core/Utils/FunctionCombination/PredicateCombination.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateCombination.cs rename to NetFabric.Hyperlinq.Core/Utils/FunctionCombination/PredicateCombination.cs diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateInCombination.cs b/NetFabric.Hyperlinq.Core/Utils/FunctionCombination/PredicateInCombination.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/FunctionCombination/PredicateInCombination.cs rename to NetFabric.Hyperlinq.Core/Utils/FunctionCombination/PredicateInCombination.cs diff --git a/NetFabric.Hyperlinq/Utils/FunctionCombination/SelectorCombination.cs b/NetFabric.Hyperlinq.Core/Utils/FunctionCombination/SelectorCombination.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/FunctionCombination/SelectorCombination.cs rename to NetFabric.Hyperlinq.Core/Utils/FunctionCombination/SelectorCombination.cs diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs b/NetFabric.Hyperlinq.Core/Utils/IndexOf/IndexOf.ReadOnlySpan.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ReadOnlySpan.cs rename to NetFabric.Hyperlinq.Core/Utils/IndexOf/IndexOf.ReadOnlySpan.cs diff --git a/NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.Core/Utils/IndexOf/IndexOf.ValueReadOnlyCollection.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/IndexOf/IndexOf.ValueReadOnlyCollection.cs rename to NetFabric.Hyperlinq.Core/Utils/IndexOf/IndexOf.ValueReadOnlyCollection.cs diff --git a/NetFabric.Hyperlinq/Utils/IntExtensions.cs b/NetFabric.Hyperlinq.Core/Utils/IntExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/IntExtensions.cs rename to NetFabric.Hyperlinq.Core/Utils/IntExtensions.cs diff --git a/NetFabric.Hyperlinq.Core/Utils/MemoryExtensions.cs b/NetFabric.Hyperlinq.Core/Utils/MemoryExtensions.cs new file mode 100644 index 000000000..99cfc73b2 --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Utils/MemoryExtensions.cs @@ -0,0 +1,12 @@ +using System; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class MemoryExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyMemory AsReadOnlyMemory(this Memory source) + => source; + } +} diff --git a/NetFabric.Hyperlinq/Utils/Scalar.cs b/NetFabric.Hyperlinq.Core/Utils/Scalar.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/Scalar.cs rename to NetFabric.Hyperlinq.Core/Utils/Scalar.cs diff --git a/NetFabric.Hyperlinq.Core/Utils/SpanExtensions.cs b/NetFabric.Hyperlinq.Core/Utils/SpanExtensions.cs new file mode 100644 index 000000000..07b150b9e --- /dev/null +++ b/NetFabric.Hyperlinq.Core/Utils/SpanExtensions.cs @@ -0,0 +1,12 @@ +using System; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class SpanExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlySpan AsReadOnlySpan(this Span source) + => source; + } +} diff --git a/NetFabric.Hyperlinq/Utils/Throw.cs b/NetFabric.Hyperlinq.Core/Utils/Throw.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/Throw.cs rename to NetFabric.Hyperlinq.Core/Utils/Throw.cs diff --git a/NetFabric.Hyperlinq/Utils/ThrowIfArgument.cs b/NetFabric.Hyperlinq.Core/Utils/ThrowIfArgument.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/ThrowIfArgument.cs rename to NetFabric.Hyperlinq.Core/Utils/ThrowIfArgument.cs diff --git a/NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs b/NetFabric.Hyperlinq.Core/Utils/Utils.AllocateUninitializedArray.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/Utils.AllocateUninitializedArray.cs rename to NetFabric.Hyperlinq.Core/Utils/Utils.AllocateUninitializedArray.cs diff --git a/NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs b/NetFabric.Hyperlinq.Core/Utils/Utils.EqualityComparer.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/Utils.EqualityComparer.cs rename to NetFabric.Hyperlinq.Core/Utils/Utils.EqualityComparer.cs diff --git a/NetFabric.Hyperlinq/Utils/Utils.SkipTake.cs b/NetFabric.Hyperlinq.Core/Utils/Utils.SkipTake.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/Utils.SkipTake.cs rename to NetFabric.Hyperlinq.Core/Utils/Utils.SkipTake.cs diff --git a/NetFabric.Hyperlinq/Utils/VectorExtensions.cs b/NetFabric.Hyperlinq.Core/Utils/VectorExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq/Utils/VectorExtensions.cs rename to NetFabric.Hyperlinq.Core/Utils/VectorExtensions.cs diff --git a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj deleted file mode 100644 index f433a0dbc..000000000 --- a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj +++ /dev/null @@ -1,55 +0,0 @@ - - - - netstandard2.0 - NetFabric.Hyperlinq.Immutable - NetFabric.Hyperlinq.Immutable - High performance LINQ implementation with minimal heap allocations. Supports all collections in System.Collections.Immutable. - 1.0.0-beta01 - Icon.png - LICENSE - netfabric, hyperlinq, linq, enumeration, extensions, performance - true - - - - - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers - - - all - runtime; build; native; contentfiles; analyzers - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - - - - - - - - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs deleted file mode 100644 index 1bf2b271d..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.CodeAnalysis; -using NetFabric.Assertive; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Xunit; - -namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests -{ - public class CollectExtensionMethodsTests - { - public static TheoryData ExtensionMethods - => new() - { - { new[] { "TestData/Source/NoExtensionMethods.cs" }, 0 }, - { new[] { "TestData/Source/ExtensionMethods.cs" }, 3 }, - - { new[] { "TestData/Source/Distinct.ArraySegment.cs" }, 1}, - { new[] { "TestData/Source/Count.ValueEnumerable.cs" }, 1 }, - { new[] { "TestData/Source/Distinct.ValueEnumerable.cs" }, 1 }, - - { new[] { "TestData/Source/Where.ArraySegment.cs" }, 2 }, - { new[] { "TestData/Source/Select.ArraySegment.cs" }, 2 }, - { new[] { "TestData/Source/Where.ValueEnumerable.cs" }, 2 }, - { new[] { "TestData/Source/Select.ValueEnumerable.cs" }, 2 }, - }; - - [Theory] - [MemberData(nameof(ExtensionMethods))] - public async Task ShouldCollectExpectedNumberOfExtensionMethods(string[] paths, int expected) - { - // Arrange - var generator = new OverloadsGenerator(); - var project = Verifier.CreateProject( - paths - .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) - .Concat(Directory.EnumerateFiles("../../../../NetFabric.Hyperlinq.SourceGenerator/Attributes/", "*.cs", SearchOption.AllDirectories)) - .Select(path => File.ReadAllText(path))); - var context = new CompilationContext(await project.GetCompilationAsync().ConfigureAwait(false) ?? throw new System.Exception("Error getting compilation!")); - - // Act - var result = generator.CollectExtensionMethods(context); - - // Assert - _ = result.Count.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs deleted file mode 100644 index 44078968f..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs +++ /dev/null @@ -1,241 +0,0 @@ -using Microsoft.CodeAnalysis; -using NetFabric.Assertive; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Xunit; - -namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests -{ - public class GenerateSourceTests - { - public static TheoryData ClassesWithOverloads - => new() - { - new[] { - "TestData/Source/Count.ValueEnumerable.cs", - }, - new[] { - "TestData/Source/Where.ValueEnumerable.cs", - }, - new[] { - "TestData/Source/Select.ValueEnumerable.cs", - }, - }; - - [Theory] - [MemberData(nameof(ClassesWithOverloads))] - public async Task ClassesWithOverloadsShouldNotGenerate(string[] paths) - { - // Arrange - var generator = new OverloadsGenerator(); - var project = Verifier.CreateProject( - paths - .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) - .Concat(Directory.EnumerateFiles("../../../../NetFabric.Hyperlinq.SourceGenerator/Attributes/", "*.cs", SearchOption.AllDirectories)) - .Select(path => File.ReadAllText(path))); - var context = new CompilationContext(await project.GetCompilationAsync().ConfigureAwait(false) ?? throw new System.Exception("Error getting compilation!")); - - // Act - var extensionMethods = generator.CollectExtensionMethods(context); - var result = generator.GenerateSource(extensionMethods, context); - - // Assert - _ = result.Must() - .BeEnumerableOf<(INamedTypeSymbol, INamedTypeSymbol, string)>() - .BeEmpty(); - } - - // ----------------------------------------------------- - - public static TheoryData GeneratorSources - => new() - { - { - new[] { - "TestData/Source/Range.cs", - "TestData/Source/Contains.ValueEnumerable.cs", - }, - new string[] { - } - }, - { - new[] { - "TestData/Source/Select.ArraySegment.cs", - "TestData/Source/Contains.ValueEnumerable.cs", - }, - new string[] { - } - }, - { - new[] { - "TestData/Source/Range.cs", - "TestData/Source/Count.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Range.Count.cs", - } - }, - { - new[] { - "TestData/Source/Repeat.cs", - "TestData/Source/Count.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Repeat.Count.cs", - } - }, - { - new[] { - "TestData/Source/Range.cs", - "TestData/Source/Where.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Range.Where.cs", - } - }, - { - new[] { - "TestData/Source/Range.cs", - "TestData/Source/Select.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Range.Select.cs", - } - }, - { - new[] { - "TestData/Source/Count.ValueEnumerable.cs", - "TestData/Source/Where.ArraySegment.cs", - }, - new[] { - "TestData/Results/Where.ArraySegment.Count.cs", - } - }, - { - new[] { - "TestData/Source/Any.ArraySegment.cs", - "TestData/Source/Any.ValueReadOnlyList.cs", - "TestData/Source/Any.ValueEnumerable.cs", - "TestData/Source/Any.ValueReadOnlyCollection.cs", - "TestData/Source/Where.ValueEnumerable.cs", - }, - new string[] { - } - }, - { - new[] { - "TestData/Source/Any.ArraySegment.cs", - "TestData/Source/Any.ValueReadOnlyList.cs", - "TestData/Source/Any.ValueEnumerable.cs", - "TestData/Source/Any.ValueReadOnlyCollection.cs", - "TestData/Source/Select.ArraySegment.cs", - }, - new[] { - "TestData/Results/Select.ArraySegment.Any.cs", - } - }, - { - new[] { - "TestData/Source/Any.ArraySegment.cs", - "TestData/Source/Any.ValueReadOnlyList.cs", - "TestData/Source/Any.ValueEnumerable.cs", - "TestData/Source/Any.ValueReadOnlyCollection.cs", - "TestData/Source/Select.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Select.ValueEnumerable.Any.cs", - } - }, - { - new[] { - "TestData/Source/Count.ValueEnumerable.cs", - "TestData/Source/Where.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Where.ValueEnumerable.Count.cs", - } - }, - { - new[] { - "TestData/Source/First.ValueEnumerable.cs", - "TestData/Source/Where.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Where.ValueEnumerable.First.cs", - } - }, - { - new[] { - "TestData/Source/First.ValueEnumerable.cs", - "TestData/Source/Select.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Select.ValueEnumerable.First.cs", - } - }, - { - new[] { - "TestData/Source/Where.ValueEnumerable.cs", - "TestData/Source/Distinct.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Where.ValueEnumerable.Distinct.cs", - "TestData/Results/Distinct.ValueEnumerable.Where.cs", - } - }, - { - new[] { - "TestData/Source/Where.ValueEnumerable.cs", - "TestData/Source/Select.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Where.ValueEnumerable.Select.cs", - "TestData/Results/Select.ValueEnumerable.Where.cs", - } - }, - { - new[] { - "TestData/Source/Where.ValueEnumerable.cs", - "TestData/Source/Dictionary.Bindings.cs", - }, - new[] { - "TestData/Results/Dictionary.Where.cs", - } - }, - { - new[] { - "TestData/Source/Select.ValueEnumerable.cs", - "TestData/Source/Dictionary.Bindings.cs", - }, - new[] { - "TestData/Results/Dictionary.Select.cs", - } - }, - }; - - [Theory] - [MemberData(nameof(GeneratorSources))] - public async Task GenerateSourceShouldGenerate(string[] paths, string[] expected) - { - // Arrange - var generator = new OverloadsGenerator(); - var project = Verifier.CreateProject( - paths - .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) - .Concat(Directory.EnumerateFiles("../../../../NetFabric.Hyperlinq.SourceGenerator/Attributes/", "*.cs", SearchOption.AllDirectories)) - .Select(path => File.ReadAllText(path))); - var context = new CompilationContext(await project.GetCompilationAsync().ConfigureAwait(false) ?? throw new System.Exception("Error getting compilation!")); - - // Act - var extensionMethods = generator.CollectExtensionMethods(context); - var result = generator.GenerateSource(extensionMethods, context); - - // Assert - _ = result.Select(item => item.Source) - .ToArray() - .Must() - .BeEqualTo(expected.Select(path => File.ReadAllText(path))); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs deleted file mode 100644 index 00caa8d8c..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class DictionaryBindings - { - public partial struct ValueWrapper - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult, NetFabric.Hyperlinq.FunctionWrapper, TResult>> Select(System.Func, TResult> selector) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult>(this, selector); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult, TSelector> Select(TSelector selector = default) - where TSelector : struct, NetFabric.Hyperlinq.IFunction, TResult> - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult, TSelector>(this, selector); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs deleted file mode 100644 index 1e44137c6..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class DictionaryBindings - { - public partial struct ValueWrapper - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, NetFabric.Hyperlinq.FunctionWrapper, bool>> Where(System.Func, bool> predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TPredicate> Where(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction, bool> - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TPredicate>(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs deleted file mode 100644 index 85119f091..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs +++ /dev/null @@ -1,36 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct DistinctEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource, NetFabric.Hyperlinq.FunctionWrapper> Where(System.Func predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource, TPredicate> Where(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource, TPredicate>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource> Distinct() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Distinct, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs deleted file mode 100644 index cad14e728..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs +++ /dev/null @@ -1,20 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this NetFabric.Hyperlinq.ValueEnumerable.RangeEnumerable source) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count(source); - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs deleted file mode 100644 index 87cf749f7..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - public partial struct RangeEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable> Select(System.Func selector) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select(this, selector); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable Select(TSelector selector = default) - where TSelector : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select(this, selector); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs deleted file mode 100644 index 14219e17f..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - public partial struct RangeEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable> Where(System.Func predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable Where(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs deleted file mode 100644 index 41ac35b3f..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs +++ /dev/null @@ -1,20 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable source) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count, NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable.DisposableEnumerator, TSource>(source); - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs deleted file mode 100644 index f44a33abe..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - public partial struct ArraySegmentSelectEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any(System.Func predicate) - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Any, TResult>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Any, TResult, TPredicate>(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs deleted file mode 100644 index 76ba1132a..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs +++ /dev/null @@ -1,36 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct SelectEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Any, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any(System.Func predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Any, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Any, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, TPredicate>(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs deleted file mode 100644 index 77c913be7..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct SelectEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.Option First() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.First, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs deleted file mode 100644 index 6c9ed4726..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct SelectEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, NetFabric.Hyperlinq.FunctionWrapper> Where(System.Func predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, TPredicate> Where(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, TPredicate>(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs deleted file mode 100644 index 444845022..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - public partial struct ArraySegmentWhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentWhereEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs deleted file mode 100644 index a68c8d6da..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct WhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs deleted file mode 100644 index 6f5f15c16..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct WhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource> Distinct() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Distinct, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs deleted file mode 100644 index 8b13b25f7..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct WhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.Option First() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.First, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs deleted file mode 100644 index c9b3e7b9b..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct WhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult, NetFabric.Hyperlinq.FunctionWrapper> Select(System.Func selector) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult>(this, selector); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) - where TSelector : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult, TSelector>(this, selector); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ArraySegment.cs deleted file mode 100644 index fb6d8bcbb..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ArraySegment.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - public static bool Any(this in ArraySegment source) - => source.Count != 0; - - public static bool Any(this in ArraySegment source, Func predicate) - => source.Any(new FunctionWrapper(predicate)); - - public static bool Any(this in ArraySegment source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => default; - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueEnumerable.cs deleted file mode 100644 index 2c79e1b31..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueEnumerable.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - public static bool Any(this TEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => default; - - public static bool Any(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.Any>(new FunctionWrapper(predicate)); - - public static bool Any(this TEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => default; - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs deleted file mode 100644 index 085c79a11..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source) - where TList : struct, IReadOnlyList - => source.Count is not 0; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.Any>(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source, TPredicate predicate = default) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => default; - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunction.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunction.cs deleted file mode 100644 index 719dbb63a..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunction.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace NetFabric.Hyperlinq -{ - public interface IFunction - { - TResult Invoke(T arg); - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunctionWrapper.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunctionWrapper.cs deleted file mode 100644 index ce38a1db7..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunctionWrapper.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace NetFabric.Hyperlinq -{ - public readonly struct FunctionWrapper - : IFunction - { - readonly Func function; - - public FunctionWrapper(Func function) - => this.function = function; - - public TResult Invoke(T arg) - => function(arg); - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IValueEnumerable.cs deleted file mode 100644 index d4efc695c..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IValueEnumerable.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public interface IValueEnumerable - : IEnumerable - where TEnumerator - : struct - , IEnumerator - { - new TEnumerator GetEnumerator(); - } - - public interface IValueReadOnlyCollection - : IReadOnlyCollection - , IValueEnumerable - where TEnumerator - : struct - , IEnumerator - { - } - - public interface IValueReadOnlyList - : IReadOnlyList - , IValueReadOnlyCollection - where TEnumerator - : struct - , IEnumerator - { - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Option.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Option.cs deleted file mode 100644 index 4c68b37b2..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Option.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public readonly struct Option - { - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/PredicateCombination.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/PredicateCombination.cs deleted file mode 100644 index 27b56347f..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/PredicateCombination.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace NetFabric.Hyperlinq -{ - public struct PredicateCombination - : IFunction - where TPredicate1 : struct, IFunction - where TPredicate2 : struct, IFunction - { - TPredicate1 first; - TPredicate2 second; - - public PredicateCombination(TPredicate1 first, TPredicate2 second) - => (this.first, this.second) = (first, second); - - public bool Invoke(TSource item) - => first.Invoke(item) && second.Invoke(item); - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/SelectorCombination.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/SelectorCombination.cs deleted file mode 100644 index f7dfe9134..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/SelectorCombination.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace NetFabric.Hyperlinq -{ - public readonly struct SelectorCombination - : IFunction - where TSelector1 : struct, IFunction - where TSelector2 : struct, IFunction - { - readonly TSelector1 first; - readonly TSelector2 second; - - public SelectorCombination(TSelector1 first, TSelector2 second) - => (this.first, this.second) = (first, second); - - public TResult Invoke(TSource item) - => second.Invoke(first.Invoke(item)); - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Contains.ValueEnumerable.cs deleted file mode 100644 index 7de29c2c4..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Contains.ValueEnumerable.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public static bool Contains(this TEnumerable source, TSource value) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => default; - - public static bool Contains(this TEnumerable source, TSource value, IEqualityComparer? comparer) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => default; - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.ValueEnumerable.cs deleted file mode 100644 index 897fe92b1..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.ValueEnumerable.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public static int Count(this TEnumerable _) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => 0; - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs deleted file mode 100644 index 68137e488..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class DictionaryBindings - { - [GeneratorMapping("TSource", "System.Collections.Generic.KeyValuePair", true)] - public readonly partial struct ValueWrapper - : IValueReadOnlyCollection, Dictionary.Enumerator> - , ICollection> - where TKey : notnull - { - readonly Dictionary source; - - public ValueWrapper(Dictionary source) - => this.source = source; - - public int Count - => source.Count; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary.Enumerator GetEnumerator() - => source.GetEnumerator(); - - IEnumerator> IEnumerable>.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => GetEnumerator(); - - bool ICollection>.IsReadOnly - => true; - - void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) - => ((ICollection>)source).CopyTo(array, arrayIndex); - - void ICollection>.Add(KeyValuePair item) - => throw new NotSupportedException(); - void ICollection>.Clear() - => throw new NotSupportedException(); - bool ICollection>.Contains(KeyValuePair item) - => throw new NotSupportedException(); - bool ICollection>.Remove(KeyValuePair item) - => throw new NotSupportedException(); - } - - public static int Count(this ValueWrapper source) - where TKey : notnull - => source.Count; - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs deleted file mode 100644 index a950046e1..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - public static ArraySegmentDistinctEnumerable Distinct(this in ArraySegment source) - => new(source); - - public readonly partial struct ArraySegmentDistinctEnumerable - : IValueEnumerable.DisposableEnumerator> - { - readonly ArraySegment source; - - internal ArraySegmentDistinctEnumerable(in ArraySegment source) - => this.source = source; - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TSource Current => default!; - readonly TSource IEnumerator.Current => default!; - readonly object IEnumerator.Current => default!; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs deleted file mode 100644 index 493f1a6f3..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public static DistinctEnumerable Distinct(this TEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => new(source); - - public readonly partial struct DistinctEnumerable - : IValueEnumerable.DisposableEnumerator> - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - { - readonly TEnumerable source; - - internal DistinctEnumerable(TEnumerable source) - => this.source = source; - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TSource Current => default!; - readonly TSource IEnumerator.Current => default!; - readonly object? IEnumerator.Current => default; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs deleted file mode 100644 index 629a8d4f2..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static class ExtensionMethods - { - public static void NotConstrainedExtensionMethod(this ArraySegment _) { } - - static void NotIgnoredExtensionMethod(this TEnumerable _) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - { } - - public static void PublicExtensionMethod(this TEnumerable _) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - { } - } - -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/First.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/First.ValueEnumerable.cs deleted file mode 100644 index 967f11668..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/First.ValueEnumerable.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - public static Option First(this TEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => default; - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs deleted file mode 100644 index 9b7e6861a..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - //public class NotStaticClass - //{ - // public void Method(TEnumerable _) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // { } - //} - - //static class NotPublicStaticClass - //{ - // public static void ExtensionMethod(this TEnumerable _) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // { } - //} - - public static class NoExtensionMethods - { - //public static void NotExtensionMethod(TEnumerable _) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - //{ } - - //static void NotPublicExtensionMethod(this TEnumerable _) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - //{ } - - [GeneratorIgnore] - public static void IgnoredExtensionMethod(this TEnumerable _) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - { } - } - -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs deleted file mode 100644 index c2659d429..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - public static RangeEnumerable Range(int start, int count) - => new(start, count); - - [GeneratorMapping("TSource", "int", true)] - public readonly partial struct RangeEnumerable - : IValueReadOnlyCollection - , ICollection - { - readonly int start; - readonly int end; - - internal RangeEnumerable(int start, int count) - { - this.start = start; - Count = count; - end = checked(start + count); - } - - public int Count { get; } - - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(int[] array, int arrayIndex) - { - } - - public bool Contains(int value) - => value >= start && value < end; - - void ICollection.Add(int item) - => throw new NotSupportedException(); - void ICollection.Clear() - => throw new NotSupportedException(); - bool ICollection.Remove(int item) - => throw new NotSupportedException(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly int Current => 0; - readonly int IEnumerator.Current => 0; - readonly object IEnumerator.Current => 0; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public bool Contains(int value, IEqualityComparer? comparer) - => default; - - public RangeEnumerable Skip(int count) - => default; - } - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs deleted file mode 100644 index 4a343102c..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - - public static RepeatEnumerable Repeat(TSource value, int count) - { - if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - - return new RepeatEnumerable(value, count); - } - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct RepeatEnumerable - : IValueReadOnlyCollection.DisposableEnumerator> - , ICollection - { - readonly TSource value; - readonly int count; - - internal RepeatEnumerable(TSource value, int count) - { - this.value = value; - this.count = count; - } - - public int Count - => count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() - => new(in this); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - - } - - public void CopyTo(TSource[] array, int arrayIndex) - { - - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => count is not 0 && EqualityComparer.Default.Equals(value, item); - - public int IndexOf(TSource item) - => count is not 0 && EqualityComparer.Default.Equals(value, item) - ? 0 - : -1; - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => throw new NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => throw new NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => throw new NotSupportedException(); - - [StructLayout(LayoutKind.Sequential)] - public struct Enumerator - { - int counter; - readonly int end; - - internal Enumerator(in RepeatEnumerable enumerable) - { - Current = enumerable.value; - counter = -1; - end = counter + enumerable.Count; - } - - public TSource Current { get; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++counter <= end; - } - - [StructLayout(LayoutKind.Sequential)] - public struct DisposableEnumerator - : IEnumerator - { - int counter; - readonly int end; - - internal DisposableEnumerator(in RepeatEnumerable enumerable) - { - Current = enumerable.value; - counter = -1; - end = counter + enumerable.Count; - } - - public TSource Current { get; } - readonly TSource IEnumerator.Current - => Current; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => Current; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++counter <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => throw new NotSupportedException(); - - public readonly void Dispose() { } - } - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs deleted file mode 100644 index b943fa420..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - static ArraySegmentSelectEnumerable> Select(this in ArraySegment source, Func selector) - => Select>(source, new FunctionWrapper(selector)); - - static ArraySegmentSelectEnumerable Select(this in ArraySegment source, TSelector selector = default) - where TSelector : struct, IFunction - => new(source, selector); - - [GeneratorMapping("TSource", "TResult")] - public readonly partial struct ArraySegmentSelectEnumerable - : IValueReadOnlyList.DisposableEnumerator> - , IList - where TSelector : struct, IFunction - { - readonly ArraySegment source; - readonly TSelector selector; - - internal ArraySegmentSelectEnumerable(in ArraySegment source, TSelector selector) - => (this.source, this.selector) = (source, selector); - - public int Count - => 0; - - bool ICollection.IsReadOnly - => true; - - void ICollection.CopyTo(TResult[] array, int arrayIndex) - { } - void ICollection.Add(TResult item) - => throw new NotSupportedException(); - void ICollection.Clear() - => throw new NotSupportedException(); - public bool Contains(TResult item) - => default; - bool ICollection.Remove(TResult item) - => throw new NotSupportedException(); - int IList.IndexOf(TResult item) - => default; - void IList.Insert(int index, TResult item) - => throw new NotSupportedException(); - void IList.RemoveAt(int index) - => throw new NotSupportedException(); - - public TResult this[int index] - => default!; - TResult IReadOnlyList.this[int index] - => this[index]; - TResult IList.this[int index] - { - get => this[index]!; - set => throw new NotSupportedException(); - } - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TResult Current => default!; - readonly object IEnumerator.Current => default!; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public bool Any() - => source.Count is not 0; - - public bool Contains(TResult value, IEqualityComparer? comparer = default) - => default; - - public ArraySegmentSelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select, TResult2>(new FunctionWrapper(selector)); - - public ArraySegmentSelectEnumerable> Select(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => Select>(source, new SelectorCombination(this.selector, selector)); - } - - public static int Count(this ArraySegmentSelectEnumerable source) - where TSelector : struct, IFunction - => 0; - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs deleted file mode 100644 index 022d483f3..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - public static SelectEnumerable> Select(this TEnumerable source, Func selector) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => Select>(source, new FunctionWrapper(selector)); - - public static SelectEnumerable Select(this TEnumerable source, TSelector selector = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => new(source, selector); - - [GeneratorMapping("TSource", "TResult")] - public readonly partial struct SelectEnumerable - : IValueEnumerable.DisposableEnumerator> - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - { - readonly TEnumerable source; - readonly TSelector selector; - - internal SelectEnumerable(TEnumerable source, TSelector selector) - => (this.source, this.selector) = (source, selector); - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TResult Current => default!; - readonly object IEnumerator.Current => default!; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public int Count() - => source.Count(); - - public SelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select, TResult2>(new FunctionWrapper(selector)); - - public SelectEnumerable> Select(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => Select>(source, new SelectorCombination(this.selector, selector)); - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ToDictionary.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ToDictionary.ArraySegment.cs deleted file mode 100644 index da24d7b1b..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ToDictionary.ArraySegment.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this in ArraySegment source, Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - { - if (keySelector is null) throw new ArgumentNullException(nameof(keySelector)); - - return ToDictionary>(source, new FunctionWrapper(keySelector), comparer); - } - - public static Dictionary ToDictionary(this in ArraySegment source, TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - { - var dictionary = new Dictionary(source.Count, comparer); - return dictionary; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this in ArraySegment source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - { - if (keySelector is null) throw new ArgumentNullException(nameof(keySelector)); - if (elementSelector is null) throw new ArgumentNullException(nameof(elementSelector)); - - return ToDictionary, FunctionWrapper>(source, new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - } - - public static Dictionary ToDictionary(this in ArraySegment source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - { - var dictionary = new Dictionary(source.Count, comparer); - return dictionary; - } - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs deleted file mode 100644 index 9b5686549..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) - => Where(source, new FunctionWrapper(predicate)); - - static ArraySegmentWhereEnumerable Where(this in ArraySegment source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => new(source, predicate); - - public readonly partial struct ArraySegmentWhereEnumerable - : IValueEnumerable.DisposableEnumerator> - where TPredicate : struct, IFunction - { - readonly ArraySegment source; - readonly TPredicate predicate; - - internal ArraySegmentWhereEnumerable(in ArraySegment source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TSource Current => default!; - readonly TSource IEnumerator.Current => default!; - readonly object? IEnumerator.Current => default; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public bool Any() - => source.Any(predicate); - - public static bool Any(Func predicate) - => default; - - public static bool Any(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => default; - - public ArraySegmentWhereEnumerable, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - - public ArraySegmentWhereEnumerable> Where(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => Where>(source, new PredicateCombination(this.predicate, predicate)); - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs deleted file mode 100644 index 6d5a8dcc0..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - public static WhereEnumerable> Where(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => Where>(source, new FunctionWrapper(predicate)); - - public static WhereEnumerable Where(this TEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => new(source, predicate); - - public readonly partial struct WhereEnumerable - : IValueEnumerable.DisposableEnumerator> - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - { - readonly TEnumerable source; - readonly TPredicate predicate; - - internal WhereEnumerable(TEnumerable source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TSource Current => default!; - readonly TSource IEnumerator.Current => default!; - readonly object? IEnumerator.Current => default; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public bool Any() - => source.Any(predicate); - - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - - public bool Any(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => source.Any>(new PredicateCombination(this.predicate, predicate)); - - public WhereEnumerable, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - - public WhereEnumerable> Where(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => Where>(source, new PredicateCombination(this.predicate, predicate)); - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs deleted file mode 100644 index a22381d28..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Text; -using System.Collections.Generic; -using System.Linq; - -namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests -{ - sealed class Verifier - { - static readonly MetadataReference corlibReference = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); - static readonly MetadataReference systemCoreReference = MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location); - static readonly MetadataReference cSharpSymbolsReference = MetadataReference.CreateFromFile(typeof(CSharpCompilation).Assembly.Location); - static readonly MetadataReference codeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location); - - static readonly string defaultFilePathPrefix = "Test"; - static readonly string testProjectName = "TestProject"; - - public static Project CreateProject(IEnumerable sources) - { - var projectId = ProjectId.CreateNewId(debugName: testProjectName); - - var solution = new AdhocWorkspace() - .CurrentSolution - .AddProject(projectId, testProjectName, testProjectName, LanguageNames.CSharp) - .AddMetadataReference(projectId, corlibReference) - .AddMetadataReference(projectId, systemCoreReference) - .AddMetadataReference(projectId, cSharpSymbolsReference) - .AddMetadataReference(projectId, codeAnalysisReference); - - var count = 0; - foreach (var source in sources) - { - var newFileName = defaultFilePathPrefix + count + ".cs"; - var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName); - solution = solution.AddDocument(documentId, newFileName, SourceText.From(source)); - count++; - } - return solution.GetProject(projectId)!; - } - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj deleted file mode 100644 index 538195793..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - netstandard2.0 - true - - - - https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json ;$(RestoreAdditionalProjectSources) - - - - - - - all - runtime; build; native; contentfiles; analyzers - - - - diff --git a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs deleted file mode 100644 index 1852dbec3..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs +++ /dev/null @@ -1,409 +0,0 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Text; -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using System.Text; - -namespace NetFabric.Hyperlinq.SourceGenerator -{ - [Generator] - public class OverloadsGenerator - : ISourceGenerator - { - static readonly DiagnosticDescriptor unhandledExceptionError = new( - id: "HPLG001", - title: "Unhandled exception while generating overloads", - messageFormat: "Unhandled exception while generating overloads: {0}", - category: "OverloadsGenerator", - DiagnosticSeverity.Error, - isEnabledByDefault: true); - - - public void Initialize(GeneratorInitializationContext context) - { - } - - public void Execute(GeneratorExecutionContext context) - { - //_ = Debugger.Launch(); // uncomment to debug this source generator - - var compilationContext = new CompilationContext(context.Compilation); - - try - { - var collectedExtensionMethods = CollectExtensionMethods(compilationContext); - - var generatedSources = GenerateSource(collectedExtensionMethods, compilationContext); - foreach (var (containerClass, extendingType, generatedSource) in generatedSources) - { - var hitName = $"{containerClass.OriginalDefinition.MetadataName}.{extendingType.OriginalDefinition.MetadataName}.g.cs"; - hitName = hitName.Replace('`', '.'); - context.AddSource(hitName, SourceText.From(generatedSource, Encoding.UTF8)); - } - - } - catch (Exception ex) - { - context.ReportDiagnostic(Diagnostic.Create(unhandledExceptionError, Location.None, ex.Message)); - } - } - - /// - /// Collects all the extension methods defined - /// - /// - /// A dictionary containing collections of the extension methods per type extended. - internal DictionarySet CollectExtensionMethods(CompilationContext context) - { - var collectedExtensionMethods = new DictionarySet(); - - // go through all implemented static types and get all the extension methods implemented - var extensionMethods = context.Compilation.SourceModule.GlobalNamespace - .GetAllTypes() - .Where(typeSymbol => - typeSymbol.IsStatic - && typeSymbol.IsPublic() - ) - .SelectMany(typeSymbol => - typeSymbol.GetMembers() - .OfType() - .Where(methodSymbol => - methodSymbol.IsExtensionMethod - //&& methodSymbol.IsPublic() - && !methodSymbol.ShouldIgnore(context) - ) - ); - - // go through all extension methods - foreach (var extensionMethod in extensionMethods) - { - var extensionType = extensionMethod.Parameters[0].Type; - var generic = extensionMethod.TypeParameters - .FirstOrDefault(typeParameter - => typeParameter.ConstraintTypes.Length > 0 - && typeParameter.Name == extensionType.Name); - if (generic is null) - { - var name = extensionMethod.Parameters[0].Type.OriginalDefinition.MetadataName; - switch (name) - { - case "ArraySegment`1": - case "ReadOnlySpan`1": - case "ReadOnlyMemory`1": - collectedExtensionMethods.Add(name, extensionMethod.GetInfo(context, 1)); - break; - } - } - else - { - // the extended type is a constrained generic parameter - var extendingType = generic.ConstraintTypes[0]; - var name = extendingType.OriginalDefinition.MetadataName; - switch (name) - { - case "IValueEnumerable`2": - case "IValueReadOnlyCollection`2": - case "IValueReadOnlyList`2": - case "IReadOnlyList`1": - case "IAsyncValueEnumerable`2": - collectedExtensionMethods.Add(name, extensionMethod.GetInfo(context, 1)); - break; - } - } - } - - return collectedExtensionMethods; - } - - /// - /// Generates the source for the overloads based on the defined extension methods. - /// - /// - /// A dictionary containing the defined extension methods. - /// The path where to serialize the generated code for debugging. - internal IEnumerable<(INamedTypeSymbol ContainerClass, INamedTypeSymbol ExtendedType, string Source)> GenerateSource(DictionarySet collectedExtensionMethods, CompilationContext context) - { - // go through all candidate types to be extended - // these are inner types of a public static class that are not static and not interfaces - foreach (var extendingType in context.Compilation.SourceModule.GlobalNamespace - .GetAllTypes() - .Where(type => type.IsStatic && type.IsReferenceType && type.IsPublic() && !type.ShouldIgnore(context)) - .SelectMany(containerType => containerType.GetTypeMembers().OfType() - .Where(type => !(type.IsStatic || type.IsInterface() || type.ShouldIgnore(context))))) - { - var bindingAttribute = extendingType.GetBindingsAttribute(context); - foreach (var source in GenerateSource(collectedExtensionMethods, context, extendingType, bindingAttribute)) - yield return source; - } - } - - IEnumerable<(INamedTypeSymbol ContainerClass, INamedTypeSymbol ExtendedType, string Source)> GenerateSource(DictionarySet collectedExtensionMethods, CompilationContext context, INamedTypeSymbol extendingType, GeneratorBindingsAttribute? bindingsAttribute) - { - // check if it's a value enumerable and keep a reference to the implemented interface - var valueEnumerableInterface = extendingType.GetAllInterfaces() - .FirstOrDefault(@interface => @interface.Name is "IValueEnumerable" or "IAsyncValueEnumerable"); - if (valueEnumerableInterface is not null || bindingsAttribute is not null) - { - // get the types of the enumerable, enumerator and source from the generic parameters declaration - var enumerableType = extendingType; - var enumeratorType = valueEnumerableInterface?.TypeArguments[1]; - var sourceType = valueEnumerableInterface?.TypeArguments[0]; - - // get the type mappings from the GeneratorMappingsAttribute, if found. - var typeGenericsMapping = extendingType.GetGenericsMappings(context); - - // get the info of all the instance methods declared in the type to be extended - var implementedInstanceMethods = extendingType.GetMembers().OfType() - .Where(method => method.Name is not ".ctor") // ignore the constructors - .Select(method => method.GetInfo(context)) - .ToArray(); - - // get the extension methods for this type declared in the outter static type - var implementedExtensionMethods = extendingType.ContainingType.GetMembers().OfType() - .Where(method - => method.IsExtensionMethod - && method.Parameters[0].Type.ToDisplayString() == extendingType.ToDisplayString()) - .Select(method => method.GetInfo(context, 1)) - .ToArray(); - - // join the two lists together as these are the implemented methods for this type - var implementedMethods = implementedInstanceMethods.Concat(implementedExtensionMethods) - .ToList(); - - // lists of methods to be generated - var instanceMethodsToBeGenerated = new List(); - var extensionMethodsToBeGenerated = new List(); - - // go through all the implemented interfaces so that - // the overloads are generated based on the extension methods defined for these - var implementedTypes = - bindingsAttribute?.SourceImplements?.Split(',') - ?? extendingType.AllInterfaces.Select(type => type.OriginalDefinition.MetadataName); - - foreach (var implementedType in implementedTypes) - { - // get the extension methods collected for this interface - if (!collectedExtensionMethods.TryGetValue(implementedType, out var overloadingMethods)) - continue; - - // check which ones should be generated - // the method can be already defined by a more performant custom implementation - for (var methodIndex = 0; methodIndex < overloadingMethods.Count; methodIndex++) - { - var overloadingMethod = overloadingMethods[methodIndex]; - - // check if already implemented - var mappedOverloadingMethods = overloadingMethod.ApplyMappings(typeGenericsMapping); - if (!implementedMethods.Any(method => method.IsOverload(mappedOverloadingMethods)) - && !((mappedOverloadingMethods.Name is "Select" || mappedOverloadingMethods.Name is "SelectAt") && (extendingType.Name.EndsWith("SelectEnumerable") || extendingType.Name.EndsWith("SelectAtEnumerable")))) // these cases are hard to fix other way - { - // check if there's a collision with a property - if (extendingType.GetMembers().OfType() - .Any(property => property.Name == mappedOverloadingMethods.Name)) - { - // this method will be generated as an extension method - extensionMethodsToBeGenerated.Add(mappedOverloadingMethods); - } - else - { - // this method will generated as an instance method - instanceMethodsToBeGenerated.Add(mappedOverloadingMethods); - } - - implementedMethods.Add(mappedOverloadingMethods); - } - } - } - - // generate the code for the instance methods and extension methods, if any... - if (instanceMethodsToBeGenerated.Count is not 0 || extensionMethodsToBeGenerated.Count is not 0) - { - var builder = new CodeBuilder(); - _ = builder - .AppendLine("#nullable enable") - .AppendLine() - .AppendLine("using System;") - .AppendLine("using System.CodeDom.Compiler;") - .AppendLine("using System.Diagnostics;") - .AppendLine("using System.Runtime.CompilerServices;") - .AppendLine(); - - using (builder.AppendBlock($"namespace NetFabric.Hyperlinq")) - { - // the generator extends the types by adding partial types - // both the outter and the inner types have to be declared as partial - using (builder.AppendBlock($"public static partial class {extendingType.ContainingType.Name}")) - { - // generate the instance methods in the inner type - if (instanceMethodsToBeGenerated.Count is not 0) - { - var extendingTypeGenericParameters = string.Empty; - if (extendingType.IsGenericType) - { - var parametersDefinition = new StringBuilder(); - _ = parametersDefinition.Append($"<{extendingType.TypeParameters.Select(parameter => parameter.ToDisplayString()).ToCommaSeparated()}>"); - // foreach (var typeParameter in extendingType.TypeParameters.Where(typeParameter => typeParameter.ConstraintTypes.Length is not 0)) - // _ = parametersDefinition.Append($" where {typeParameter.Name} : {typeParameter.AsConstraintsStrings().ToCommaSeparated()}"); - extendingTypeGenericParameters = parametersDefinition.ToString(); - } - - var entity = extendingType.IsValueType - ? "struct" - : "class"; - using (builder.AppendBlock($"public partial {entity} {extendingType.Name}{extendingTypeGenericParameters}")) - { - foreach (var instanceMethod in instanceMethodsToBeGenerated) - { - var methodGenericsMapping = typeGenericsMapping.AddRange(instanceMethod.GenericsMapping); - GenerateMethodSource(builder, context, extendingType, instanceMethod, enumerableType, enumeratorType, sourceType, methodGenericsMapping, false, bindingsAttribute); - } - } - } - _ = builder.AppendLine(); - - // generate the extension methods in the outter type - foreach (var extensionMethod in extensionMethodsToBeGenerated) - { - var methodGenericsMapping = typeGenericsMapping.AddRange(extensionMethod.GenericsMapping); - GenerateMethodSource(builder, context, extendingType, extensionMethod, enumerableType, enumeratorType, sourceType, methodGenericsMapping, true, bindingsAttribute); - } - } - } - - var source = builder.ToString().Replace("TResult, TResult", "TSource, TResult"); - yield return (extendingType.ContainingType, extendingType, source); - } - } - } - - void GenerateMethodSource(CodeBuilder builder, CompilationContext context, INamedTypeSymbol extendingType, MethodInfo methodToGenerate, ITypeSymbol? enumerableType, ITypeSymbol? enumeratorType, ITypeSymbol sourceType, ImmutableArray genericsMapping, bool isExtensionMethod, GeneratorBindingsAttribute? bindingsAttribute) - { - var extendingTypeTypeArguments = extendingType.MappedTypeArguments(genericsMapping) - .ToArray(); - var typeParameters = isExtensionMethod - ? methodToGenerate.TypeParameters - .Where(typeParameter => - !typeParameter.IsConcreteType - && typeParameter.Name is not "TEnumerable" and not "TEnumerator" and not "TList") - .ToArray() - : methodToGenerate.TypeParameters - .Where(typeParameter => - !typeParameter.IsConcreteType - && typeParameter.Name is not "TEnumerable" and not "TEnumerator" and not "TList" - && !extendingTypeTypeArguments.Any(argument => argument.Name == typeParameter.Name)) - .ToArray(); - - var methodReturnType = methodToGenerate.ReturnType.ToDisplayString(); - var genericsIndex = methodReturnType.IndexOf('<'); - if (genericsIndex >= 0) - { - methodReturnType = methodReturnType.Substring(0, genericsIndex); - if (methodToGenerate.ReturnType is INamedTypeSymbol namedMethodReturnType) - { - if (bindingsAttribute is null) - methodReturnType += MapTypeProperties(namedMethodReturnType.TypeArguments.Select(argument => argument.ToDisplayString()), enumerableType!, enumeratorType!, sourceType, genericsMapping); - else - methodReturnType += MapTypeProperties(namedMethodReturnType.TypeArguments.Select(argument => argument.ToDisplayString()), bindingsAttribute); - } - } - if (methodReturnType is "TEnumerable") - methodReturnType = extendingType.ToDisplayString(); - - var methodName = methodToGenerate.Name; - var methodExtensionType = extendingType.ToDisplayString(); - var methodParameters = methodToGenerate.Parameters - .Select(parameter => parameter.DefaultValue is null - ? $"{parameter.Type} {parameter.Name}" - : $"{parameter.Type} {parameter.Name} = {parameter.DefaultValue}") - .ToCommaSeparated(); - var methodGenericParameters = typeParameters - .Select(typeParameter => typeParameter.Name) - .ToCommaSeparated(); - var methodGenericParametersString = methodGenericParameters.Any() - ? $"<{methodGenericParameters}>" - : string.Empty; - - var returnKeyword = string.Empty; - var callContainingType = methodToGenerate.ContainingType; - var callTypeParameters = bindingsAttribute is null - ? MapTypeProperties(methodToGenerate.TypeParameters.Select(parameter => parameter.Name), enumerableType!, enumeratorType!, sourceType, genericsMapping) - : MapTypeProperties(methodToGenerate.TypeParameters.Select(parameter => parameter.Name), bindingsAttribute); - var callParameters = methodToGenerate.Parameters.Select(parameter => parameter.Name).ToCommaSeparated(); - - // generate the source - _ = builder - .AppendLine(context.GeneratedCodeAttribute) - .AppendLine("[DebuggerNonUserCode]") - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]"); - - var firstCallParameter = bindingsAttribute?.Source ?? "this"; - - if (isExtensionMethod) - { - var extraMethodParameter = methodParameters is { Length: 0 } - ? string.Empty - : $", {methodParameters}"; - _ = builder.AppendLine($"public static {methodReturnType} {methodName}{methodGenericParametersString}(this {methodExtensionType} source{extraMethodParameter})"); - - firstCallParameter = bindingsAttribute is null - ? "source" - : $"source.{bindingsAttribute.Source}"; - } - else - { - var methodReadonly = extendingType.IsValueType ? "readonly" : string.Empty; - _ = builder.AppendLine($"public {methodReadonly} {methodReturnType} {methodName}{methodGenericParametersString}({methodParameters})"); - } - foreach (var (name, constraints, _) in typeParameters.Where(typeParameter => typeParameter.Constraints.Any())) - _ = builder.AppendLine($"where {name} : {constraints}"); - - callParameters = StringExtensions.CommaSeparateIfNotNullOrEmpty(firstCallParameter, callParameters, bindingsAttribute?.ExtraParameters); - - _ = builder - .AppendLine($"=> {callContainingType}.{methodName}{callTypeParameters}({callParameters});") - .AppendLine(); - } - - string MapTypeProperties(IEnumerable typePropertyNames, ITypeSymbol enumerableType, ITypeSymbol enumeratorType, ITypeSymbol sourceType, ImmutableArray genericsMapping) - { - var str = typePropertyNames.Select(typePropertyName => typePropertyName switch - { - "TEnumerable" or "TList" => enumerableType.ToDisplayString(genericsMapping), - "TEnumerator" => enumeratorType.ToDisplayString(genericsMapping), - "TSource" => sourceType.ToDisplayString(genericsMapping), - _ => typePropertyName.ApplyMappings(genericsMapping, out _), - }) - .ToCommaSeparated(); - - return str switch - { - { Length: 0 } => string.Empty, - _ => $"<{str}>" - }; - } - - string MapTypeProperties(IEnumerable typePropertyNames, GeneratorBindingsAttribute? bindingsAttribute) - { - var str = typePropertyNames.Select(typePropertyName => typePropertyName switch - { - "TEnumerable" or "TList" => bindingsAttribute?.EnumerableType ?? typePropertyName, - "TEnumerator" => bindingsAttribute?.EnumeratorType ?? typePropertyName, - "TSource" => bindingsAttribute?.ElementType ?? typePropertyName, - _ => typePropertyName, - }) - .ToCommaSeparated(); - - str = StringExtensions.CommaSeparateIfNotNullOrEmpty(str, bindingsAttribute?.ExtraTypeParameters); - - return str switch - { - { Length: 0 } => string.Empty, - _ => $"<{str}>" - }; - } - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator/Properties/AssemblyInfo.cs b/NetFabric.Hyperlinq.SourceGenerator/Properties/AssemblyInfo.cs deleted file mode 100644 index 423b8e090..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("NetFabric.Hyperlinq.SourceGenerator.UnitTests")] \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/CodeBuilder.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/CodeBuilder.cs deleted file mode 100644 index 1c57c05b2..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/CodeBuilder.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Text; - -namespace NetFabric.Hyperlinq.SourceGenerator -{ - class CodeBuilder - { - static readonly string tab = " "; - - readonly StringBuilder builder = new(); - int currentLevel = 0; - - StringBuilder AppendIndentation() - { - for (var level = 0; level < currentLevel; level++) - _ = builder.Append(tab); - - return builder; - } - - public CodeBuilder AppendLine() - { - _ = builder.AppendLine(); - return this; - } - - public CodeBuilder AppendLine(char line) - { - _ = AppendIndentation().Append(line).AppendLine(); - return this; - } - - public CodeBuilder AppendLine(string line) - { - _ = AppendIndentation().AppendLine(line); - return this; - } - - public CodeBuilder AppendLine(Action line) - { - _ = AppendIndentation(); - line(builder); - _ = AppendLine(); - return this; - } - - public IDisposable AppendBlock(string line) - { - _ = AppendLine(line).AppendLine('{'); - currentLevel++; - return new CloseBlock(this); - } - - class CloseBlock : IDisposable - { - readonly CodeBuilder builder; - - public CloseBlock(CodeBuilder builder) - => this.builder = builder; - - public void Dispose() - { - builder.currentLevel--; - _ = builder.AppendLine('}'); - } - } - - public override string ToString() - => builder.ToString(); - } -} diff --git a/NetFabric.Hyperlinq.UnitTests/GenerateSourceTests.cs b/NetFabric.Hyperlinq.UnitTests/GenerateSourceTests.cs new file mode 100644 index 000000000..45984f065 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/GenerateSourceTests.cs @@ -0,0 +1,143 @@ +using Microsoft.CodeAnalysis.CSharp.Syntax; +using NetFabric.Assertive; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests +{ + public class GenerateSourceTests + { + public static TheoryData GeneratorSources + => new() + { + { + new[] { "TestData/Source/AsValueEnumerable.Empty.cs" }, + "TestData/Results/Empty.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.Empty2.cs" }, + "TestData/Results/Empty.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.Empty3.cs" }, + "TestData/Results/Empty.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.Repeat.cs" }, + "TestData/Results/AsValueEnumerable.Repeat.cs" + }, + + { + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestCollection.cs" }, + "TestData/Results/AsValueEnumerable.TestCollection.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs" }, + "TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestList.cs" }, + "TestData/Results/AsValueEnumerable.TestList.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.IReadOnlyList.cs" }, + "TestData/Results/AsValueEnumerable.IReadOnlyList.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs" }, + "TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestReadOnlyList.cs" }, + "TestData/Results/AsValueEnumerable.TestReadOnlyList.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestValueEnumerable.cs" }, + "TestData/Results/AsValueEnumerable.TestValueEnumerable.cs" + }, + { + new[] { "TestData/Source/Count.Array.cs" }, + "TestData/Results/Count.Array.cs" + }, + { + new[] { "TestData/Source/Select.Array.cs" }, + "TestData/Results/Select.Array.cs" + }, + { + new[] { "TestData/Source/Where.Array.cs" }, + "TestData/Results/Where.Array.cs" + }, + { + new[] { "TestData/Source/Skip.Take.Array.cs" }, + "TestData/Results/Skip.Take.Array.cs" + }, + //{ + // new[] { "TestData/Source/Count.Span.cs" }, + // "TestData/Results/Count.Span.cs" + //}, + { + new[] { "TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs" }, + "TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs" + }, + { + new[] { "TestData/Source/Select.TestEnumerableWithValueTypeEnumerator.cs" }, + "TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs" + }, + }; + + [Theory] + [MemberData(nameof(GeneratorSources))] + public async Task GenerateSourceShouldGenerate(string[] paths, string expected) + { + // Arrange + var sources = paths + .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) + .Select(path => File.ReadAllText(path)); + var project = Verifier.CreateProject(sources); + var compilation = await project.GetCompilationAsync().ConfigureAwait(false) + ?? throw new System.Exception("Error getting compilation!"); + //var errors = compilation + // .GetDiagnostics() + // .Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error) + // .ToArray(); + //_ = errors.Must().BeEqualTo(Array.Empty()); + var typeSymbolsCache = new TypeSymbolsCache(compilation); + var memberAccessExpressions = compilation.SyntaxTrees + .SelectMany(tree => tree.GetRoot().DescendantNodes().OfType()) + .Where(memberAccess => Generator.methods.Contains(memberAccess.Name.Identifier.ValueText)) + .ToList(); + + // Act + var builder = new CodeBuilder(isUnitTest: true); + Generator.GenerateSource(compilation, typeSymbolsCache, memberAccessExpressions, builder, CancellationToken.None); + var result = builder.ToString(); + + // Assert + _ = result.Must() + .BeEqualTo(File.ReadAllText(expected)); + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj index 0158308fc..6e7e4b860 100644 --- a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj +++ b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj @@ -1,32 +1,31 @@  - net48;netcoreapp2.1;netcoreapp3.1;net6.0 + net6.0 + false + true - + + + NOT_TESTING + + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - runtime; build; native; contentfiles; analyzers - - - - - @@ -34,7 +33,9 @@ - + + Always + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..3d9b3be63 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,50 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) + // => new(source, source); + + //public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ + // : IValueEnumerable.Enumerator> + // where TEnumerable : IEnumerable + //{ + // readonly TestEnumerableWithValueTypeEnumerator source; + // readonly TEnumerable source2; + + // internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) + // => (this.source, this.source2) = (source, source2); + + // // Implement IValueEnumerable.Enumerator> + + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); + + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + //} + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsEnumerable(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source) + => NetFabric.Hyperlinq.ValueEnumerableExtensions.AsEnumerable>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType>(source); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs new file mode 100644 index 000000000..3c797fc8b --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs @@ -0,0 +1,112 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_> AsValueEnumerable(this System.Collections.Generic.IReadOnlyList source) + => new(source, source); + + public readonly struct AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_ + : IValueReadOnlyList>, IList + where TEnumerable : IReadOnlyList + { + readonly System.Collections.Generic.IReadOnlyList source; + readonly TEnumerable source2; + + internal AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_(System.Collections.Generic.IReadOnlyList source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() => new(source2.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + public bool Contains(TestValueType item) + { + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return true; + } + return true; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex)); + + // Implement IList + + public TestValueType this[int index] => source2[index]; + + TestValueType IList.this[int index] + { + get => source2[index]; + set => throw new NotSupportedException(); + } + + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + public int IndexOf(TestValueType item) + { + if (Count is not 0) + { + var index = 0; + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return index; + + checked { index++; } + } + } + return -1; + } + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs new file mode 100644 index 000000000..0542b8e23 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs @@ -0,0 +1,26 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable AsValueEnumerable(this NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable source) + => source; + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs new file mode 100644 index 000000000..3ba688a87 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs @@ -0,0 +1,77 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestCollection_TestValueType_> AsValueEnumerable(this TestCollection source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestCollection_TestValueType_ + : IValueReadOnlyCollection.Enumerator>, ICollection + where TEnumerable : ICollection + { + readonly TestCollection source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestCollection_TestValueType_(TestCollection source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestCollection.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TestValueType item) => source2.Contains(item); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs new file mode 100644 index 000000000..c701217ff --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs @@ -0,0 +1,66 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithInterfacelessPublicEnumerator source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_ + : IValueEnumerable.Enumerator> + where TEnumerable : IEnumerable + { + readonly TestEnumerableWithInterfacelessPublicEnumerator source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_(TestEnumerableWithInterfacelessPublicEnumerator source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() => new(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + public struct Enumerator : IEnumerator + { + readonly TestEnumerableWithInterfacelessPublicEnumerator.Enumerator source; + + internal Enumerator(TestEnumerableWithInterfacelessPublicEnumerator.Enumerator source) + => this.source = source; + + public TestValueType Current => source.Current; + + object? IEnumerator.Current => source.Current; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() => source.MoveNext(); + + public void Reset() => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() { } + } + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs new file mode 100644 index 000000000..5d9a02f2a --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs @@ -0,0 +1,64 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfaces source) + => new(source); + + public readonly struct AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ + : IValueEnumerable + { + readonly TestEnumerableWithNoInterfaces source; + + internal AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_(TestEnumerableWithNoInterfaces source) + => this.source = source; + + // Implement IValueEnumerable + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() => new(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + public struct Enumerator : IEnumerator + { + readonly TestEnumerableWithNoInterfaces.Enumerator source; + + internal Enumerator(TestEnumerableWithNoInterfaces.Enumerator source) + => this.source = source; + + public TestValueType Current => source.Current; + + object? IEnumerator.Current => source.Current; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() => source.MoveNext(); + + public void Reset() => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() { } + } + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs new file mode 100644 index 000000000..5b2664cdf --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs @@ -0,0 +1,65 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) + => new(source); + + public readonly struct AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ + : IValueEnumerable + { + readonly TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source; + + internal AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_(TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) + => this.source = source; + + // Implement IValueEnumerable + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() => new(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + public struct Enumerator : IEnumerator + { + readonly TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.Enumerator source; + + internal Enumerator(TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.Enumerator source) + => this.source = source; + + public TestValueType Current => source.Current; + + object? IEnumerator.Current => source.Current; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() => source.MoveNext(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Reset() => source.Reset(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() => source.Dispose(); + } + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs new file mode 100644 index 000000000..0f37dc567 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs @@ -0,0 +1,46 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithReferenceTypeEnumerator source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_ + : IValueEnumerable> + where TEnumerable : IEnumerable + { + readonly TestEnumerableWithReferenceTypeEnumerator source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_(TestEnumerableWithReferenceTypeEnumerator source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() => new(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..8157ae353 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,46 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ + : IValueEnumerable.Enumerator> + where TEnumerable : IEnumerable + { + readonly TestEnumerableWithValueTypeEnumerator source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs new file mode 100644 index 000000000..03212937a --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs @@ -0,0 +1,94 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestList_TestValueType_> AsValueEnumerable(this TestList source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestList_TestValueType_ + : IValueReadOnlyList.Enumerator>, IList + where TEnumerable : IList + { + readonly TestList source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestList_TestValueType_(TestList source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestList.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TestValueType item) => source2.Contains(item); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex); + + // Implement IList + + public TestValueType this[int index] => source2[index]; + + TestValueType IList.this[int index] + { + get => source2[index]; + set => throw new NotSupportedException(); + } + + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int IndexOf(TestValueType item) => source2.IndexOf(item); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs new file mode 100644 index 000000000..3c1ec6b62 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs @@ -0,0 +1,94 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_> AsValueEnumerable(this TestListWithExplicitInterfaces source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_ + : IValueReadOnlyList>, IList + where TEnumerable : IList + { + readonly TestListWithExplicitInterfaces source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_(TestListWithExplicitInterfaces source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() => new(source2.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TestValueType item) => source2.Contains(item); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex); + + // Implement IList + + public TestValueType this[int index] => source2[index]; + + TestValueType IList.this[int index] + { + get => source2[index]; + set => throw new NotSupportedException(); + } + + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int IndexOf(TestValueType item) => source2.IndexOf(item); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs new file mode 100644 index 000000000..83c1c9336 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs @@ -0,0 +1,83 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestReadOnlyCollection_TestValueType_> AsValueEnumerable(this TestReadOnlyCollection source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestReadOnlyCollection_TestValueType_ + : IValueReadOnlyCollection.Enumerator>, ICollection + where TEnumerable : IReadOnlyCollection + { + readonly TestReadOnlyCollection source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestReadOnlyCollection_TestValueType_(TestReadOnlyCollection source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestReadOnlyCollection.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + public bool Contains(TestValueType item) + { + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return true; + } + return true; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex)); + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs new file mode 100644 index 000000000..4875c6a3b --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs @@ -0,0 +1,112 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestReadOnlyList_TestValueType_> AsValueEnumerable(this TestReadOnlyList source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestReadOnlyList_TestValueType_ + : IValueReadOnlyList.Enumerator>, IList + where TEnumerable : IReadOnlyList + { + readonly TestReadOnlyList source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestReadOnlyList_TestValueType_(TestReadOnlyList source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestReadOnlyList.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + public bool Contains(TestValueType item) + { + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return true; + } + return true; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex)); + + // Implement IList + + public TestValueType this[int index] => source2[index]; + + TestValueType IList.this[int index] + { + get => source2[index]; + set => throw new NotSupportedException(); + } + + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + public int IndexOf(TestValueType item) + { + if (Count is not 0) + { + var index = 0; + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return index; + + checked { index++; } + } + } + return -1; + } + } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs new file mode 100644 index 000000000..94f110fde --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs @@ -0,0 +1,26 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static TestValueEnumerable AsValueEnumerable(this TestValueEnumerable source) + => source; + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs new file mode 100644 index 000000000..dc87a08ad --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs @@ -0,0 +1,26 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func predicate) + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, predicate); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs new file mode 100644 index 000000000..d968d7718 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs @@ -0,0 +1,26 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.SpanValueEnumerable source, Func predicate) + => NetFabric.Hyperlinq.ArrayExtensions.Count(source.Span, predicate); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Empty.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Empty.cs new file mode 100644 index 000000000..8b9f8f882 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Empty.cs @@ -0,0 +1,17 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs new file mode 100644 index 000000000..81acc3241 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs @@ -0,0 +1,26 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueReadOnlyListExtensions.SelectEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper> Select(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Select, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType>(source, selector); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..744875c7b --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,56 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + //[GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + //[DebuggerNonUserCode] + //[ExcludeFromCodeCoverage] + //[EditorBrowsable(EditorBrowsableState.Never)] + //[Obsolete("This method is not intended to be used directly by user code")] + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) + // => new(source, source); + + //public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ + // : IValueEnumerable.Enumerator> + // where TEnumerable : IEnumerable + //{ + // readonly TestEnumerableWithValueTypeEnumerator source; + // readonly TEnumerable source2; + + // internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) + // => (this.source, this.source2) = (source, source2); + + // // Implement IValueEnumerable.Enumerator> + + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); + + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + //} + + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerableExtensions.SelectEnumerable>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType, FunctionWrapper> Select(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source, System.Func selector) + => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType>(source, selector); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs new file mode 100644 index 000000000..4351753f4 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs @@ -0,0 +1,35 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Skip(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Skip, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Take(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) + => NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.Take, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs new file mode 100644 index 000000000..6f0f0469b --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs @@ -0,0 +1,26 @@ +#nullable enable + +using System; +using System.CodeDom.Compiler; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] + [DebuggerNonUserCode] + [ExcludeFromCodeCoverage] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.WhereEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper> Where(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Where, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, selector); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..c95d5f829 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Count_TestEnumerableWithValueTypeEnumerator() + { + _ = new TestEnumerableWithValueTypeEnumerator() + .AsValueEnumerable() + .AsEnumerable(); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty.cs new file mode 100644 index 000000000..0b0b74e93 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty.cs @@ -0,0 +1,28 @@ +using System; +//using NetFabric.Hyperlinq; => DO NOT UNCOMMENT + +partial class TestsSource +{ + static void AsValueEnumerable_Empty() + { + // test calling AsValueEnumerable() for types that don't need source generation + // with NetFabric.Hyperlinq namespace NOT in a using clause + +#if !NOT_TESTING + var array = Array.Empty(); + + _ = array.AsValueEnumerable(); + _ = new ArraySegment(array).AsValueEnumerable(); + + _ = array.AsMemory().AsValueEnumerable(); + _ = ((ReadOnlyMemory)array.AsMemory()).AsValueEnumerable(); + + _ = array.AsSpan().AsValueEnumerable(); + _ = ((ReadOnlySpan)array.AsSpan()).AsValueEnumerable(); + + var list = new List(); + _ = list.AsValueEnumerable(); +#endif + } +} + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty2.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty2.cs new file mode 100644 index 000000000..6c0371f60 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty2.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using NetFabric.Hyperlinq; // namespace is known at compile time + +partial class TestsSource +{ + static void AsValueEnumerable_Empty2() + { + // test calling AsValueEnumerable() for types that don't need source generation + + var array = Array.Empty(); + + _ = array.AsValueEnumerable(); + _ = ArrayExtensions.AsValueEnumerable(array); + _ = new ArraySegment(array).AsValueEnumerable(); + + _ = array.AsMemory().AsValueEnumerable(); + _ = ((ReadOnlyMemory)array.AsMemory()).AsValueEnumerable(); + + _ = array.AsSpan().AsValueEnumerable(); + _ = ((ReadOnlySpan)array.AsSpan()).AsValueEnumerable(); + + var list = new List(); + _ = list.AsValueEnumerable(); + } +} + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty3.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty3.cs new file mode 100644 index 000000000..d7d379d2c --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Empty3.cs @@ -0,0 +1,18 @@ +using System; +using System.Linq; +using NetFabric.Hyperlinq; // namespace is known at compile time + +partial class TestsSource +{ + static void AsValueEnumerable_Empty3() + { + var valueEnumerable = Array + .Empty() + .AsValueEnumerable(); + + _ = Enumerable.Count(valueEnumerable); + _ = Enumerable.Count(valueEnumerable, _ => true); + _ = Enumerable.Take(Enumerable.Skip(valueEnumerable, 1), 2); + } +} + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.IReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.IReadOnlyList.cs new file mode 100644 index 000000000..33b500a91 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.IReadOnlyList.cs @@ -0,0 +1,17 @@ +using NetFabric.Hyperlinq; +using System.Collections.Generic; + +partial class TestsSource +{ + static void AsValueEnumerable_IReadOnlyList() + { + // test calling AsValueEnumerable() on an IReadOnlyList<> + IReadOnlyList list = new TestReadOnlyList(); + _ = list.AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Repeat.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Repeat.cs new file mode 100644 index 000000000..834978c04 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.Repeat.cs @@ -0,0 +1,13 @@ +using System; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_Repeat() + { + // test calling AsValueEnumerable() for types that implement IValueEnumerable<,> + + _ = ValueEnumerable.Repeat(0, 100).AsValueEnumerable(); + } +} + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestCollection.cs new file mode 100644 index 000000000..c66f27f10 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestCollection.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_Collection() + { + // test calling AsValueEnumerable() on an implementation of ICollection<> + _ = new TestCollection().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs new file mode 100644 index 000000000..d9734c3b4 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator() + { + // test calling AsValueEnumerable() for types that implement IEnumerable<> + // but the public GetEnumerator() returns a type that doesn't implement IEnumerator<> + + _ = new TestEnumerableWithInterfacelessPublicEnumerator().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs new file mode 100644 index 000000000..12071aee1 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_TestEnumerableWithNoInterfaces() + { + // test calling AsValueEnumerable() for types that do not implement IEnumerable<> + // but the public GetEnumerator() returns a type that doesn't implement IEnumerator<> + + _ = new TestEnumerableWithNoInterfaces().AsValueEnumerable(); + } +} + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs new file mode 100644 index 000000000..7554e76fe --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose() + { + // test calling AsValueEnumerable() for types that do not implement IEnumerable<> + // and the public GetEnumerator() returns a type that implement IDisposable and has a Reset() method + + _ = new TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs new file mode 100644 index 000000000..304df9a9d --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator() + { + // test calling AsValueEnumerable() for types that implement IEnumerable<> and the enumerator is not a value type + + _ = new TestEnumerableWithReferenceTypeEnumerator().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..1ff2412ec --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_EnumerableWithValueTypeEnumerator() + { + // test calling AsValueEnumerable() for types that implement IEnumerable<> and the enumerator is a value type + + _ = new TestEnumerableWithValueTypeEnumerator().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestList.cs new file mode 100644 index 000000000..f1421d0ab --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestList.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_List() + { + // test calling AsValueEnumerable() on an implementation of IList<> + _ = new TestList().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs new file mode 100644 index 000000000..72d84d63f --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_ReadOnlyListWithExplicitInterfaces() + { + // test calling AsValueEnumerable() on an IValueEnumerable + _ = new TestListWithExplicitInterfaces().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs new file mode 100644 index 000000000..15c9cce44 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_ReadOnlyCollection() + { + // test calling AsValueEnumerable() on an IValueEnumerable + _ = new TestReadOnlyCollection().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyList.cs new file mode 100644 index 000000000..cb02ca0d8 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyList.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_ReadOnlyList() + { + // test calling AsValueEnumerable() on an IValueEnumerable + _ = new TestReadOnlyList().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestValueEnumerable.cs new file mode 100644 index 000000000..fbb432ef8 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/AsValueEnumerable.TestValueEnumerable.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_ValueEnumerable() + { + // test calling AsValueEnumerable() on an IValueEnumerable + _ = new TestValueEnumerable().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/Enumerables.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/Enumerables.cs new file mode 100644 index 000000000..283f0f9df --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/Enumerables.cs @@ -0,0 +1,327 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +public class TestEnumerableWithNoInterfaces +{ + public Enumerator GetEnumerator() + => new(); + + public readonly struct Enumerator + { + public T Current + => default!; + + public bool MoveNext() + => false; + } +} + +public class TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose +{ + public Enumerator GetEnumerator() + => new(); + + public readonly struct Enumerator + : IDisposable + { + public T Current + => default!; + + public bool MoveNext() + => false; + + public void Reset() + { } + + public void Dispose() + { } + } +} + +public readonly struct TestEnumerableWithInterfacelessPublicEnumerator + : IEnumerable +{ + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(); + + public struct Enumerator + { + public T Current + => default!; + + public bool MoveNext() + => false; + } + + class DisposableEnumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestEnumerableWithValueTypeEnumerator + : IEnumerable +{ + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + + +public readonly struct TestEnumerableWithReferenceTypeEnumerator + : IEnumerable +{ + public IEnumerator GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + class Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestReadOnlyCollection + : IReadOnlyCollection +{ + public int Count => default; + + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestCollection + : ICollection +{ + public int Count => default; + + public bool IsReadOnly => true; + public bool Contains(T item) => default; + public void CopyTo(T[] array, int arrayIndex) { } + void ICollection.Add(T item) => throw new NotSupportedException(); + bool ICollection.Remove(T item) => throw new NotSupportedException(); + void ICollection.Clear() => throw new NotSupportedException(); + + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestReadOnlyList + : IReadOnlyList +{ + public int Count => default; + + public T this[int index] => default!; + + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestList + : IList +{ + public int Count => default; + + public bool IsReadOnly => true; + + public T this[int index] + { + get => default!; + set => throw new NotSupportedException(); + } + + public bool Contains(T item) => default; + public void CopyTo(T[] array, int arrayIndex) { } + void ICollection.Add(T item) => throw new NotSupportedException(); + bool ICollection.Remove(T item) => throw new NotSupportedException(); + void ICollection.Clear() => throw new NotSupportedException(); + + public int IndexOf(T item) => -1; + void IList.Insert(int index, T item) => throw new NotSupportedException(); + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + + +public readonly struct TestListWithExplicitInterfaces + : IList +{ + int ICollection.Count => default; + + bool ICollection.IsReadOnly => true; + + T IList.this[int index] + { + get => default!; + set => throw new NotSupportedException(); + } + + bool ICollection.Contains(T item) => default; + void ICollection.CopyTo(T[] array, int arrayIndex) { } + void ICollection.Add(T item) => throw new NotSupportedException(); + bool ICollection.Remove(T item) => throw new NotSupportedException(); + void ICollection.Clear() => throw new NotSupportedException(); + + int IList.IndexOf(T item) => -1; + void IList.Insert(int index, T item) => throw new NotSupportedException(); + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + class Enumerator + : IEnumerator + { + T IEnumerator.Current + => default!; + object? IEnumerator.Current + => default; + + bool IEnumerator.MoveNext() + => false; + + void IEnumerator.Reset() + { } + void IDisposable.Dispose() + { } + } +} + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/ItemTypes.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/ItemTypes.cs new file mode 100644 index 000000000..1249d551d --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/ItemTypes.cs @@ -0,0 +1,7 @@ +public struct TestValueType +{ +} + +public class TestReferenceType +{ +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/ValueEnumerables.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/ValueEnumerables.cs new file mode 100644 index 000000000..0819feb46 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Common/ValueEnumerables.cs @@ -0,0 +1,45 @@ +using NetFabric.Hyperlinq; +using System.Collections; +using System.Collections.Generic; + +public class TestValueEnumerable + : IValueEnumerable.DisposableEnumerator> +{ + public Enumerator GetEnumerator() + => new(); + + DisposableEnumerator IValueEnumerable.GetEnumerator() + => new(); + + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(); + + public readonly struct Enumerator + { + public T Current + => default!; + + public bool MoveNext() + => false; + } + + public readonly struct DisposableEnumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/Count.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Count.Array.cs new file mode 100644 index 000000000..59af328dd --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Count.Array.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Count_ArraySegmentValueEnumerable() + { + _ = Array.Empty() + .AsValueEnumerable() + .Count(_ => true); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/Count.Span.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Count.Span.cs new file mode 100644 index 000000000..fc14b2aab --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Count.Span.cs @@ -0,0 +1,16 @@ +using System; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Count_SpanValueEnumerable() + { +#if !NOT_TESTING + _ = Array.Empty().AsSpan() + .AsValueEnumerable() + .Count(_ => true); +#endif + } +} + + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/Select.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Select.Array.cs new file mode 100644 index 000000000..3fd1cfea8 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Select.Array.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Select_ArraySegmentValueEnumerable() + { + _ = Array.Empty() + .AsValueEnumerable() + .Select(_ => new TestReferenceType()); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/Select.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Select.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..32fd6358f --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Select.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Select_TestEnumerableWithValueTypeEnumerator() + { + _ = new TestEnumerableWithValueTypeEnumerator() + .AsValueEnumerable() + .Select(_ => new TestReferenceType()); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/Skip.Take.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Skip.Take.Array.cs new file mode 100644 index 000000000..346966ae9 --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Skip.Take.Array.cs @@ -0,0 +1,14 @@ +using System; +using System.Linq; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Skip_Take_ArraySegmentValueEnumerable() + { + _ = Array.Empty() + .AsValueEnumerable() + .Skip(1) + .Take(2); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Source/Where.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Where.Array.cs new file mode 100644 index 000000000..3062e609b --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Source/Where.Array.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Where_ArraySegmentValueEnumerable() + { + _ = Array.Empty() + .AsValueEnumerable() + .Where(_ => true); + } +} diff --git a/NetFabric.Hyperlinq.UnitTests/Verifier.cs b/NetFabric.Hyperlinq.UnitTests/Verifier.cs new file mode 100644 index 000000000..102ea391c --- /dev/null +++ b/NetFabric.Hyperlinq.UnitTests/Verifier.cs @@ -0,0 +1,49 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Text; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; +using System.Linq; + +namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests +{ + sealed class Verifier + { + static readonly string defaultFilePathPrefix = "Test"; + static readonly string testProjectName = "TestProject"; + + public static Project CreateProject(IEnumerable sources) + { + var projectId = ProjectId.CreateNewId(debugName: testProjectName); + + var coreLibPath = typeof(object).Assembly.Location; + var coreLibDirectory = Path.GetDirectoryName(coreLibPath)!; + var references = new[] { + MetadataReference.CreateFromFile(coreLibPath), + MetadataReference.CreateFromFile(Path.Combine(coreLibDirectory, "netstandard.dll")), + MetadataReference.CreateFromFile(Path.Combine(coreLibDirectory, "System.Runtime.dll")), + MetadataReference.CreateFromFile(Path.Combine(coreLibDirectory, "System.Collections.dll")), + MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ImmutableArray<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(IValueEnumerable<,>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ValueEnumerableExtensions).Assembly.Location), + }; + var solution = new AdhocWorkspace() + .CurrentSolution + .AddProject(projectId, testProjectName, testProjectName, LanguageNames.CSharp) + .AddMetadataReferences(projectId, references) + .WithProjectCompilationOptions(projectId, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + + var count = 0; + foreach (var source in sources) + { + var newFileName = defaultFilePathPrefix + count + ".cs"; + var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName); + solution = solution.AddDocument(documentId, newFileName, SourceText.From(source)); + count++; + } + return solution.GetProject(projectId)!; + } + } +} diff --git a/NetFabric.Hyperlinq.sln b/NetFabric.Hyperlinq.sln index 77877123b..ee9b89340 100644 --- a/NetFabric.Hyperlinq.sln +++ b/NetFabric.Hyperlinq.sln @@ -1,12 +1,10 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28516.95 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31423.177 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq", "NetFabric.Hyperlinq\NetFabric.Hyperlinq.csproj", "{EEEAA31B-434E-4849-A3E5-FA9664F5CE9B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.UnitTests", "NetFabric.Hyperlinq.UnitTests\NetFabric.Hyperlinq.UnitTests.csproj", "{FE0CFD9E-7685-4595-8691-5364228722E9}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2C452DA5-FE07-451C-BFE1-AD14A57F7B09}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig @@ -24,13 +22,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Benchmarks", "NetFabric.Hyperlinq.Benchmarks\NetFabric.Hyperlinq.Benchmarks.csproj", "{02EE275F-6E2D-444A-AB1F-9BCD02DEA204}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.SourceGenerator", "NetFabric.Hyperlinq.SourceGenerator\NetFabric.Hyperlinq.SourceGenerator.csproj", "{B8C004E3-F59E-4017-8781-C0F99B61BDEF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Abstractions", "NetFabric.Hyperlinq.Abstractions\NetFabric.Hyperlinq.Abstractions.csproj", "{6981E761-E698-437D-AF63-0E80844B7D41}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.SourceGenerator.UnitTests", "NetFabric.Hyperlinq.SourceGenerator.UnitTests\NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj", "{12F96462-A2F8-4FBE-B4F5-29BA6A6DB4D9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Core", "NetFabric.Hyperlinq.Core\NetFabric.Hyperlinq.Core.csproj", "{9EA4EA87-7656-48BA-BE7F-E5CC1B48512D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Abstractions", "NetFabric.Hyperlinq.Abstractions\NetFabric.Hyperlinq.Abstractions.csproj", "{6981E761-E698-437D-AF63-0E80844B7D41}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Core.UnitTests", "NetFabric.Hyperlinq.Core.UnitTests\NetFabric.Hyperlinq.Core.UnitTests.csproj", "{794C4984-BB46-4A50-9BC1-53831B5C8002}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Immutable", "NetFabric.Hyperlinq.Immutable\NetFabric.Hyperlinq.Immutable.csproj", "{6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.UnitTests", "NetFabric.Hyperlinq.UnitTests\NetFabric.Hyperlinq.UnitTests.csproj", "{F0A7B925-30F2-4FAA-97E6-7848B3E104B6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -42,30 +40,26 @@ Global {EEEAA31B-434E-4849-A3E5-FA9664F5CE9B}.Debug|Any CPU.Build.0 = Debug|Any CPU {EEEAA31B-434E-4849-A3E5-FA9664F5CE9B}.Release|Any CPU.ActiveCfg = Release|Any CPU {EEEAA31B-434E-4849-A3E5-FA9664F5CE9B}.Release|Any CPU.Build.0 = Release|Any CPU - {FE0CFD9E-7685-4595-8691-5364228722E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FE0CFD9E-7685-4595-8691-5364228722E9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FE0CFD9E-7685-4595-8691-5364228722E9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FE0CFD9E-7685-4595-8691-5364228722E9}.Release|Any CPU.Build.0 = Release|Any CPU {02EE275F-6E2D-444A-AB1F-9BCD02DEA204}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {02EE275F-6E2D-444A-AB1F-9BCD02DEA204}.Debug|Any CPU.Build.0 = Debug|Any CPU {02EE275F-6E2D-444A-AB1F-9BCD02DEA204}.Release|Any CPU.ActiveCfg = Release|Any CPU {02EE275F-6E2D-444A-AB1F-9BCD02DEA204}.Release|Any CPU.Build.0 = Release|Any CPU - {B8C004E3-F59E-4017-8781-C0F99B61BDEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B8C004E3-F59E-4017-8781-C0F99B61BDEF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B8C004E3-F59E-4017-8781-C0F99B61BDEF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B8C004E3-F59E-4017-8781-C0F99B61BDEF}.Release|Any CPU.Build.0 = Release|Any CPU - {12F96462-A2F8-4FBE-B4F5-29BA6A6DB4D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {12F96462-A2F8-4FBE-B4F5-29BA6A6DB4D9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {12F96462-A2F8-4FBE-B4F5-29BA6A6DB4D9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {12F96462-A2F8-4FBE-B4F5-29BA6A6DB4D9}.Release|Any CPU.Build.0 = Release|Any CPU {6981E761-E698-437D-AF63-0E80844B7D41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6981E761-E698-437D-AF63-0E80844B7D41}.Debug|Any CPU.Build.0 = Debug|Any CPU {6981E761-E698-437D-AF63-0E80844B7D41}.Release|Any CPU.ActiveCfg = Release|Any CPU {6981E761-E698-437D-AF63-0E80844B7D41}.Release|Any CPU.Build.0 = Release|Any CPU - {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Release|Any CPU.Build.0 = Release|Any CPU + {9EA4EA87-7656-48BA-BE7F-E5CC1B48512D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9EA4EA87-7656-48BA-BE7F-E5CC1B48512D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9EA4EA87-7656-48BA-BE7F-E5CC1B48512D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9EA4EA87-7656-48BA-BE7F-E5CC1B48512D}.Release|Any CPU.Build.0 = Release|Any CPU + {794C4984-BB46-4A50-9BC1-53831B5C8002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {794C4984-BB46-4A50-9BC1-53831B5C8002}.Debug|Any CPU.Build.0 = Debug|Any CPU + {794C4984-BB46-4A50-9BC1-53831B5C8002}.Release|Any CPU.ActiveCfg = Release|Any CPU + {794C4984-BB46-4A50-9BC1-53831B5C8002}.Release|Any CPU.Build.0 = Release|Any CPU + {F0A7B925-30F2-4FAA-97E6-7848B3E104B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F0A7B925-30F2-4FAA-97E6-7848B3E104B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F0A7B925-30F2-4FAA-97E6-7848B3E104B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F0A7B925-30F2-4FAA-97E6-7848B3E104B6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorBindingsAttribute.cs b/NetFabric.Hyperlinq/Attributes/GeneratorBindingsAttribute.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorBindingsAttribute.cs rename to NetFabric.Hyperlinq/Attributes/GeneratorBindingsAttribute.cs diff --git a/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorIgnoreAttribute.cs b/NetFabric.Hyperlinq/Attributes/GeneratorIgnoreAttribute.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorIgnoreAttribute.cs rename to NetFabric.Hyperlinq/Attributes/GeneratorIgnoreAttribute.cs diff --git a/NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorMappingAttribute.cs b/NetFabric.Hyperlinq/Attributes/GeneratorMappingAttribute.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Attributes/GeneratorMappingAttribute.cs rename to NetFabric.Hyperlinq/Attributes/GeneratorMappingAttribute.cs diff --git a/NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs b/NetFabric.Hyperlinq/CompilationContext.cs similarity index 98% rename from NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs rename to NetFabric.Hyperlinq/CompilationContext.cs index 7dedf96f5..a2a169618 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs +++ b/NetFabric.Hyperlinq/CompilationContext.cs @@ -1,4 +1,5 @@ using Microsoft.CodeAnalysis; +using NetFabric.CodeAnalysis; using System; namespace NetFabric.Hyperlinq.SourceGenerator diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs deleted file mode 100644 index b9af7e02e..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ /dev/null @@ -1,155 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class EnumerableExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this IEnumerable source) - => new(source); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueEnumerable> - { - readonly IEnumerable source; - - internal ValueEnumerable(IEnumerable source) - => this.source = source; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator GetEnumerator() - => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IEnumerable AsEnumerable() - => source; - - public TSource[] ToArray() - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - if (collection.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(collection.Count); - collection.CopyTo(result, 0); - return result; - } - - using var arrayBuilder = ValueEnumerableExtensions.ToArrayBuilder, ValueEnumerator, TSource>(this, ArrayPool.Shared, false); - return arrayBuilder.ToArray(); - } - - public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - if (collection.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(collection.Count, clearOnDispose); - collection.CopyTo(result.Rented, 0); - return result; - } - - using var arrayBuilder = ValueEnumerableExtensions.ToArrayBuilder, ValueEnumerator, TSource>(this, pool, clearOnDispose); - return arrayBuilder.ToArray(pool, clearOnDispose); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ToArray().AsList(); - - #endregion - - #region Quantifier - - public bool Contains(TSource value, IEqualityComparer? comparer = default) - { - if (comparer.UseDefaultComparer() && source is ICollection collection) - return collection.Contains(value); - - return this.Contains, ValueEnumerator, TSource>(value, comparer); - } - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, nint, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, nint?, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, nuint, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, nuint?, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, decimal?, decimal>(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs deleted file mode 100644 index a8be25625..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ /dev/null @@ -1,214 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ReadOnlyCollectionExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this IReadOnlyCollection source) - => new(source); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueReadOnlyCollection> - , ICollection - { - readonly IReadOnlyCollection source; - - internal ValueEnumerable(IReadOnlyCollection source) - => this.source = source; - - public int Count - => source.Count; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator GetEnumerator() - => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(TSource[] array, int arrayIndex) - { - if (Count is 0) - return; - - if (array.Length - arrayIndex < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - collection.CopyTo(array, arrayIndex); - } - else - { - using var enumerator = GetEnumerator(); - if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination - { - for (var index = 0; index < array.Length; index++) - { - _ = enumerator.MoveNext(); - array[index] = enumerator.Current; - } - } - else - { - checked - { - for (var index = arrayIndex; enumerator.MoveNext(); index++) - array[index] = enumerator.Current; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - bool ICollection.Contains(TSource item) - => Contains(item, default); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IReadOnlyCollection AsEnumerable() - => source; - - public TSource[] ToArray() - { - if (source.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(source.Count); - CopyTo(result, 0); - return result; - } - - public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - if (source.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(source.Count, clearOnDispose); - CopyTo(result.Rented, 0); - return result; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ToArray().AsList(); - - #endregion - #region Quantifier - - public bool Contains(TSource value, IEqualityComparer? comparer = default) - => Count is not 0 && source.Contains(value, comparer); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs deleted file mode 100644 index c6646af20..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ /dev/null @@ -1,320 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ReadOnlyListExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, TSource> AsValueEnumerable(this IReadOnlyList source) - => new(source); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TList source) - where TList : IReadOnlyList - => new(source); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueReadOnlyList> - , IList - where TList : IReadOnlyList - { - readonly TList source; - - internal ValueEnumerable(TList source) - => this.source = source; - - public TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - - TSource IList.this[int index] - { - get => source[index]; - [DoesNotReturn] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - public int Count - => source.Count; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator GetEnumerator() - => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(TSource[] array, int arrayIndex) - { - if (Count is 0) - return; - - if (array.Length - arrayIndex < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - collection.CopyTo(array, arrayIndex); - } - else - { - using var enumerator = GetEnumerator(); - if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination - { - for (var index = 0; index < array.Length; index++) - { - _ = enumerator.MoveNext(); - array[index] = enumerator.Current; - } - } - else - { - checked - { - for (var index = arrayIndex; enumerator.MoveNext(); index++) - array[index] = enumerator.Current; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - bool ICollection.Contains(TSource item) - => Contains(item, default); - - public int IndexOf(TSource item) - { - return source switch - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - IList list => list.IndexOf(item), - - _ => IndexOfEnumerable(this, item), - }; - - static int IndexOfEnumerable(ValueEnumerable source, TSource item) - { - using var enumerator = source.GetEnumerator(); - for (var index = 0; enumerator.MoveNext(); index++) - { - if (EqualityComparer.Default.Equals(enumerator.Current, item)) - return index; - } - return -1; - } - } - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SkipTakeEnumerable, TSource> Skip(int count) - => this.Skip, TSource>(count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SkipTakeEnumerable, TSource> Take(int count) - => this.Take, TSource>(count); - - #endregion - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IReadOnlyCollection AsEnumerable() - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source; - - public TSource[] ToArray() - { - if (source.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(source.Count); - CopyTo(result, 0); - return result; - } - - public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - if (source.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(source.Count, clearOnDispose); - CopyTo(result.Rented, 0); - return result; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ToArray().AsList(); - - #endregion - - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SelectEnumerable, ValueEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) - => ValueReadOnlyListExtensions.Select, ValueEnumerator, TSource, TResult>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SelectEnumerable, ValueEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) - where TSelector : struct, IFunction - => ValueReadOnlyListExtensions.Select, ValueEnumerator, TSource, TResult, TSelector>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SelectAtEnumerable, ValueEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) - => ValueReadOnlyListExtensions.Select, ValueEnumerator, TSource, TResult>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SelectAtEnumerable, ValueEnumerator, TSource, TResult, TSelector> SelectAt(TSelector selector = default) - where TSelector : struct, IFunction - => ValueReadOnlyListExtensions.SelectAt, ValueEnumerator, TSource, TResult, TSelector>(this, selector); - - #endregion - - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer = default) - => Count is not 0 && source.Contains(value); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TList : IReadOnlyList - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TList : IReadOnlyList - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TList : IReadOnlyList - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TList : IReadOnlyList - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs deleted file mode 100644 index ac02b2263..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs +++ /dev/null @@ -1,174 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this IValueEnumerable source) - where TEnumerator : struct, IEnumerator - => new(source); - - [GeneratorBindings(source: "source", sourceImplements: "IValueEnumerable`2", enumerableType: "IValueEnumerable")] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueEnumerable - where TEnumerator : struct, IEnumerator - { - readonly IValueEnumerable source; - - internal ValueEnumerable(IValueEnumerable source) - => this.source = source; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IEnumerable AsEnumerable() - => source; - - public TSource[] ToArray() - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - if (collection.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(collection.Count); - collection.CopyTo(result, 0); - return result; - } - - using var arrayBuilder = ToArrayBuilder, TEnumerator, TSource>(source, ArrayPool.Shared, false); - return arrayBuilder.ToArray(); - } - - public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - if (collection.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(collection.Count, clearOnDispose); - collection.CopyTo(result.Rented, 0); - return result; - } - - using var arrayBuilder = ToArrayBuilder, TEnumerator, TSource>(source, pool, clearOnDispose); - return arrayBuilder.ToArray(pool, clearOnDispose); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ToArray().AsList(); - - #endregion - - #region Quantifier - - public bool Contains(TSource value, IEqualityComparer? comparer = default) - { - if (comparer.UseDefaultComparer() && source is ICollection collection) - return collection.Contains(value); - - return source.Contains, TEnumerator, TSource>(value, comparer); - } - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, nint, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, nint?, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, nuint, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, nuint?, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, decimal?, decimal>(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs deleted file mode 100644 index e3eb7ce64..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ /dev/null @@ -1,246 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyCollectionExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this IValueReadOnlyCollection source) - where TEnumerator : struct, IEnumerator - => new(source); - - [GeneratorBindings(source: "source", sourceImplements: "IValueReadOnlyCollection`2,IValueEnumerable`2", enumerableType: "IValueReadOnlyCollection")] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueReadOnlyCollection - , ICollection - where TEnumerator : struct, IEnumerator - { - readonly IValueReadOnlyCollection source; - - internal ValueEnumerable(IValueReadOnlyCollection source) - => this.source = source; - - public int Count - => source.Count; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(TSource[] array, int arrayIndex) - { - if (Count is 0) - return; - - if (array.Length - arrayIndex < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - collection.CopyTo(array, arrayIndex); - } - else - { - using var enumerator = GetEnumerator(); - if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination - { - for (var index = 0; index < array.Length; index++) - { - _ = enumerator.MoveNext(); - array[index] = enumerator.Current; - } - } - else - { - checked - { - for (var index = arrayIndex; enumerator.MoveNext(); index++) - array[index] = enumerator.Current; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - bool ICollection.Contains(TSource item) - => Contains(item, default); - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IReadOnlyCollection AsEnumerable() - => source; - - public TSource[] ToArray() - { - if (source.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(source.Count); - CopyTo(result, 0); - return result; - } - - public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - if (source.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(source.Count, clearOnDispose); - CopyTo(result.Rented, 0); - return result; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ToArray().AsList(); - - #endregion - - #region Quantifier - - public bool Contains(TSource value, IEqualityComparer? comparer = default) - { - if (Count is 0) - return false; - - if (comparer.UseDefaultComparer() && source is ICollection collection) - return collection.Contains(value); - - return source.Contains, TEnumerator, TSource>(value, comparer); - } - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerator : struct, IEnumerator - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerator : struct, IEnumerator - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs deleted file mode 100644 index f735067c5..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ /dev/null @@ -1,264 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class EnumerableExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueEnumerable - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - readonly TEnumerable source; - TGetEnumerator getEnumerator; - TGetEnumerator2 getEnumerator2; - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - readonly TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - readonly IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerable AsEnumerable() - => source; - - public readonly TSource[] ToArray() - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - if (collection.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(collection.Count); - collection.CopyTo(result, 0); - return result; - } - - using var arrayBuilder = ValueEnumerableExtensions.ToArrayBuilder, TEnumerator, TSource>(this, ArrayPool.Shared, false); - return arrayBuilder.ToArray(); - } - - public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - if (collection.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(collection.Count, clearOnDispose); - collection.CopyTo(result.Rented, 0); - return result; - } - - using var arrayBuilder = ValueEnumerableExtensions.ToArrayBuilder, TEnumerator, TSource>(this, pool, clearOnDispose); - return arrayBuilder.ToArray(pool, clearOnDispose); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly List ToList() - => ToArray().AsList(); - - #endregion - - #region Quantifier - - public bool Contains(TSource value, IEqualityComparer? comparer = default) - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (comparer.UseDefaultComparer() && source is ICollection collection) - return collection.Contains(value); - - return this.Contains, TEnumerator, TSource>(value, comparer); - } - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, nint, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, nint?, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, nuint, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, nuint?, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, decimal?, decimal>(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs deleted file mode 100644 index d3ca7a55c..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ /dev/null @@ -1,348 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ReadOnlyCollectionExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueReadOnlyCollection - , ICollection - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - readonly TEnumerable source; -#pragma warning disable IDE0044 // Add readonly modifier - TGetEnumerator getEnumerator; - TGetEnumerator2 getEnumerator2; -#pragma warning restore IDE0044 // Add readonly modifier - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - public readonly int Count - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - readonly TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - readonly IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public readonly void CopyTo(TSource[] array, int arrayIndex) - { - if (Count is 0) - return; - - if (array.Length - arrayIndex < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - collection.CopyTo(array, arrayIndex); - } - else - { - using var enumerator = getEnumerator.Invoke(source); - if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination - { - for (var index = 0; index < array.Length; index++) - { - _ = enumerator.MoveNext(); - array[index] = enumerator.Current; - } - } - else - { - checked - { - for (var index = arrayIndex; enumerator.MoveNext(); index++) - array[index] = enumerator.Current; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - readonly bool ICollection.Contains(TSource item) - => Contains(item, default); - - [ExcludeFromCodeCoverage] - readonly void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerable AsEnumerable() - => source; - - public readonly TSource[] ToArray() - { - if (source.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(source.Count); - CopyTo(result, 0); - return result; - } - - public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - if (source.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(source.Count, clearOnDispose); - CopyTo(result.Rented, 0); - return result; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly List ToList() - => ToArray().AsList(); - - #endregion - #region Quantifier - - public readonly bool Contains(TSource value, IEqualityComparer? comparer = default) - => Count is not 0 && source.Contains(value, comparer); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs deleted file mode 100644 index a3d066e5e..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs +++ /dev/null @@ -1,266 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [GeneratorBindings(source: "source", sourceImplements: "IValueEnumerable`2")] - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueEnumerable - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - internal readonly TEnumerable source; - internal TGetEnumerator getEnumerator; - internal TGetEnumerator2 getEnumerator2; - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - readonly TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source.GetEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source.GetEnumerator(); - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerable AsEnumerable() - => source; - - public TSource[] ToArray() - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - if (collection.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(collection.Count); - collection.CopyTo(result, 0); - return result; - } - - using var arrayBuilder = ToArrayBuilder(source, ArrayPool.Shared, false); - return arrayBuilder.ToArray(); - } - - public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - if (collection.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(collection.Count, clearOnDispose); - collection.CopyTo(result.Rented, 0); - return result; - } - - using var arrayBuilder = ToArrayBuilder(source, pool, clearOnDispose); - return arrayBuilder.ToArray(pool, clearOnDispose); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ToArray().AsList(); - - #endregion - - #region Quantifier - - public readonly bool Contains(TSource value, IEqualityComparer? comparer = default) - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (comparer.UseDefaultComparer() && source is ICollection collection) - return collection.Contains(value); - - return source.Contains(value, comparer); - } - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - } -} diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs deleted file mode 100644 index b5c96d2b9..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ /dev/null @@ -1,361 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyCollectionExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [GeneratorBindings(source: "source", sourceImplements: "IValueReadOnlyCollection`2,IValueEnumerable`2")] - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueReadOnlyCollection - , ICollection - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - readonly TEnumerable source; -#pragma warning disable IDE0044 // Add readonly modifier - TGetEnumerator getEnumerator; - TGetEnumerator2 getEnumerator2; -#pragma warning restore IDE0044 // Add readonly modifier - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - public readonly int Count - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - readonly TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - - readonly bool ICollection.IsReadOnly - => true; - - public readonly void CopyTo(TSource[] array, int arrayIndex) - { - if (Count is 0) - return; - - if (array.Length - arrayIndex < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - collection.CopyTo(array, arrayIndex); - } - else - { - using var enumerator = getEnumerator.Invoke(source); - if (arrayIndex is 0 && array.Length == Count) - { - for (var index = 0; index < array.Length; index++) // to enable range check elimination - { - _ = enumerator.MoveNext(); - array[index] = enumerator.Current; - } - } - else - { - checked - { - for (var index = arrayIndex; enumerator.MoveNext(); index++) - array[index] = enumerator.Current; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - readonly bool ICollection.Contains(TSource item) - => Contains(item, default); - - [ExcludeFromCodeCoverage] - readonly void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerable AsEnumerable() - => source; - - public readonly TSource[] ToArray() - { - if (source.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(source.Count); - CopyTo(result, 0); - return result; - } - - public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - if (source.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(source.Count, clearOnDispose); - CopyTo(result.Rented, 0); - return result; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly List ToList() - => ToArray().AsList(); - - #endregion - - #region Quantifier - - public readonly bool Contains(TSource value, IEqualityComparer? comparer = default) - { - if (Count is 0) - return false; - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (comparer.UseDefaultComparer() && source is ICollection collection) - return collection.Contains(value); - - return ValueReadOnlyCollectionExtensions.Contains(source, value, comparer); - } - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs deleted file mode 100644 index 50a3711f8..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ /dev/null @@ -1,428 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [GeneratorBindings(source: "source", sourceImplements: "IValueReadOnlyList`2,IValueEnumerable`2")] - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueReadOnlyList - , IList - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - readonly TEnumerable source; -#pragma warning disable IDE0044 // Add readonly modifier - TGetEnumerator getEnumerator; - TGetEnumerator2 getEnumerator2; -#pragma warning restore IDE0044 // Add readonly modifier - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - public readonly TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - readonly TSource IList.this[int index] - { - get => source[index]; - set => Throw.NotSupportedException(); - } - - public readonly int Count - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - readonly TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - readonly IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - - readonly bool ICollection.IsReadOnly - => true; - - public readonly void CopyTo(TSource[] array, int arrayIndex) - { - if (Count is 0) - return; - - if (array.Length - arrayIndex < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array)); - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is ICollection collection) - { - collection.CopyTo(array, arrayIndex); - } - else - { - using var enumerator = getEnumerator.Invoke(source); - if (arrayIndex is 0 && array.Length == Count) // to enable range check elimination - { - for (var index = 0; index < array.Length; index++) - { - _ = enumerator.MoveNext(); - array[index] = enumerator.Current; - } - } - else - { - checked - { - for (var index = arrayIndex; enumerator.MoveNext(); index++) - array[index] = enumerator.Current; - } - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - readonly bool ICollection.Contains(TSource item) - => Contains(item, default); - - public readonly int IndexOf(TSource item) - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is IList list) - return list.IndexOf(item); - - using var enumerator = getEnumerator.Invoke(source); - for (var index = 0; enumerator.MoveNext(); index++) - { - if (EqualityComparer.Default.Equals(enumerator.Current, item)) - return index; - } - return -1; - } - - [ExcludeFromCodeCoverage] - readonly void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - readonly void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SkipTakeEnumerable, TSource> Skip(int count) - => this.Skip, TSource>(count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SkipTakeEnumerable, TSource> Take(int count) - => this.Take, TSource>(count); - - #endregion - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly TEnumerable AsEnumerable() - => source; - - public readonly TSource[] ToArray() - { - if (source.Count is 0) - return Array.Empty(); - - var result = Utils.AllocateUninitializedArray(source.Count); - CopyTo(result, 0); - return result; - } - - public readonly Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - { - if (source.Count is 0) - return Lease.Empty(); - - var result = pool.Lease(source.Count, clearOnDispose); - CopyTo(result.Rented, 0); - return result; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly List ToList() - => ToArray().AsList(); - - #endregion - - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectEnumerable, TEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) - => Select, TEnumerator, TSource, TResult>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectEnumerable, TEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) - where TSelector : struct, IFunction - => Select, TEnumerator, TSource, TResult, TSelector>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectAtEnumerable, TEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) - => Select, TEnumerator, TSource, TResult>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectAtEnumerable, TEnumerator, TSource, TResult, TSelector> SelectAt(TSelector selector = default) - where TSelector : struct, IFunction - => SelectAt, TEnumerator, TSource, TResult, TSelector>(this, selector); - - #endregion - - #region Quantifier - - public readonly bool Contains(TSource value, IEqualityComparer? comparer = default) - { - if (Count is 0) - return false; - - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (comparer.UseDefaultComparer() && source is ICollection collection) - return collection.Contains(value); - - return ValueReadOnlyCollectionExtensions.Contains(source, value, comparer); - } - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs deleted file mode 100644 index fadda85ae..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ /dev/null @@ -1,459 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ArraySegmentValueEnumerable AsValueEnumerable(this ArraySegment source) - => new(source); - - [GeneratorBindings(source: "((ReadOnlySpan)source.AsSpan())", sourceImplements: "ReadOnlySpan`1")] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ArraySegmentValueEnumerable - : IValueReadOnlyList.DisposableEnumerator> - , IList - { - internal readonly ArraySegment source; - - internal ArraySegmentValueEnumerable(ArraySegment source) - => this.source = source; - - public int Count - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source.Count; - } - - public TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - ThrowIfArgument.OutOfRange(index, Count, nameof(index)); - return source.Array![source.Offset + index]; - } - } - - TSource IList.this[int index] - { - get => this[index]; - - [ExcludeFromCodeCoverage] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanEnumerator GetEnumerator() - => new(source); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(source); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(source); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(source); - - - bool ICollection.IsReadOnly - => true; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => source.AsSpan().CopyTo(array.AsSpan(arrayIndex)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => source.Contains(item); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int IndexOf(TSource item) - { - var index = Array.IndexOf(source.Array!, item, source.Offset, source.Count); - return index < 0 - ? -1 - : index - source.Offset; - } - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - [StructLayout(LayoutKind.Auto)] - public struct DisposableEnumerator - : IEnumerator - { - readonly ArraySegment source; - int index; - - internal DisposableEnumerator(ArraySegment source) - { - this.source = source; - index = -1; - } - - public readonly TSource Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source.Array![source.Offset + index]; - } - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => Current; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - { - if (index < source.Count) - { - index++; - return index < source.Count; - } - return false; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [ExcludeFromCodeCoverage] - public void Reset() - => index = -1; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly void Dispose() { } - } - - #region Aggregation - - #endregion - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegment AsEnumerable() - => source; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TSource[] ToArray() - => source.AsSpan().ToArray(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Lease ToArray(ArrayPool pool, bool clearOnDispose = default) - => source.AsSpan().ToArray(pool, clearOnDispose); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToList(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer); - - #endregion - - #region Element - - public Option ElementAt(int index) - => index < 0 || index >= source.Count - ? Option.None - : Option.Some(source.Array![source.Offset + index]); - - public Option First() - => source switch - { - { Count: 0 } => Option.None, - _ => Option.Some(source.Array![source.Offset]) - }; - - public Option Single() - => source switch - { - { Count: 1 } => Option.Some(source.Array![source.Offset]), - _ => Option.None, - }; - - #endregion - - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereEnumerable> Where(Func predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereEnumerable Where(TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereAtEnumerable> Where(Func predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereAtEnumerable WhereAt(TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.WhereAt(predicate); - - #endregion - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerable Skip(int count) - { - var (newOffset, newCount) = Utils.Skip(source.Count, count); - return new ArraySegmentValueEnumerable(new ArraySegment(source.Array!, source.Offset + newOffset, newCount)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerable Take(int count) - => new(new ArraySegment(source.Array!, source.Offset, Utils.Take(source.Count, count))); - - #endregion - - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectEnumerable> Select(Func selector) - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectEnumerable Select(TSelector selector = default) - where TSelector : struct, IFunction - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectAtEnumerable> Select(Func selector) - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectAtEnumerable SelectAt(TSelector selector = default) - where TSelector : struct, IFunction - => source.SelectAt(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectManyEnumerable> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => source.SelectMany(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectManyEnumerable SelectMany(TSelector selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.SelectMany(selector); - - #endregion - - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate predicate) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate predicate) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AllAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => ((ReadOnlySpan)source.AsSpan()).Any(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate predicate) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate predicate) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AnyAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer) - => ((ReadOnlySpan)source.AsSpan()).Contains(value, comparer); - - #endregion - - #region Set - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentDistinctEnumerable Distinct(IEqualityComparer? comparer = default) - => source.Distinct(comparer); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentValueEnumerable source) - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ArraySegmentValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool ContainsVector(this ArraySegmentValueEnumerable source, TSource value) - where TSource : struct - => ((ReadOnlySpan)source.source.AsSpan()).ContainsVector(value); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ArraySegmentValueEnumerable source, Func, Vector> vectorSelector, Func selector) - where TSource : struct - where TResult : struct - => ((ReadOnlySpan)source.source.AsSpan()).SelectVector(vectorSelector, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TSelector selector = default) - where TSelector : struct, IFunction, Vector>, IFunction - where TSource : struct - where TResult : struct - => ((ReadOnlySpan)source.source.AsSpan()).SelectVector(selector, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static SpanSelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TVectorSelector vectorSelector = default, TSelector selector = default) - where TVectorSelector : struct, IFunction, Vector> - where TSelector : struct, IFunction - where TSource : struct - where TResult : struct - => ((ReadOnlySpan)source.source.AsSpan()).SelectVector(vectorSelector, selector); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs deleted file mode 100644 index 404d18218..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class DictionaryExtensions - { - // Dictionary is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - // Same for Dictionary.KeyCollection and Dictionary.ValueCollection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, Dictionary.Enumerator, Dictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this Dictionary source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable, Dictionary.Enumerator, KeyValuePair, GetEnumerator>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.KeyCollection, Dictionary.KeyCollection.Enumerator, Dictionary.KeyCollection.Enumerator, TKey, GetEnumerator, GetEnumerator> AsValueEnumerable(this Dictionary.KeyCollection source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable.KeyCollection, Dictionary.KeyCollection.Enumerator, TKey, GetEnumerator>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.ValueCollection, Dictionary.ValueCollection.Enumerator, Dictionary.ValueCollection.Enumerator, TValue, GetEnumerator, GetEnumerator> AsValueEnumerable(this Dictionary.ValueCollection source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable.ValueCollection, Dictionary.ValueCollection.Enumerator, TValue, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, Dictionary.Enumerator> - , IFunction.KeyCollection, Dictionary.KeyCollection.Enumerator> - , IFunction.ValueCollection, Dictionary.ValueCollection.Enumerator> - where TKey : notnull - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary.Enumerator Invoke(Dictionary source) - => source.GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary.KeyCollection.Enumerator Invoke(Dictionary.KeyCollection source) - => source.GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary.ValueCollection.Enumerator Invoke(Dictionary.ValueCollection source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs deleted file mode 100644 index 369e75988..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class HashSetExtensions - { - // HashSet is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, HashSet.Enumerator, HashSet.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this HashSet source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, HashSet.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, HashSet.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public HashSet.Enumerator Invoke(HashSet source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs deleted file mode 100644 index f14f1d7c7..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class LinkedListExtensions - { - // LinkedList is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, LinkedList.Enumerator, LinkedList.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this LinkedList source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, LinkedList.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, LinkedList.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public LinkedList.Enumerator Invoke(LinkedList source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs deleted file mode 100644 index 292eeb24d..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ -#if NET6_0_OR_GREATER - -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - - public static class PriorityQueueExtensions - { - // PriorityQueue.UnorderedItemsCollection is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.UnorderedItemsCollection, PriorityQueue.UnorderedItemsCollection.Enumerator, PriorityQueue.UnorderedItemsCollection.Enumerator, (TElement Element, TPriority Priority), GetEnumerator, GetEnumerator> AsValueEnumerable(this PriorityQueue.UnorderedItemsCollection source) - => ReadOnlyCollectionExtensions.AsValueEnumerable.UnorderedItemsCollection, PriorityQueue.UnorderedItemsCollection.Enumerator, (TElement Element, TPriority Priority), GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction.UnorderedItemsCollection, PriorityQueue.UnorderedItemsCollection.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public PriorityQueue.UnorderedItemsCollection.Enumerator Invoke(PriorityQueue.UnorderedItemsCollection source) - => source.GetEnumerator(); - } - } -} - -#endif \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs deleted file mode 100644 index 6080caba0..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class QueueExtensions - { - // Queue is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, Queue.Enumerator, Queue.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this Queue source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, Queue.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, Queue.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Queue.Enumerator Invoke(Queue source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs deleted file mode 100644 index ef820ddcc..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class SortedDictionaryExtensions - { - // SortedDictionary is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - // Same for SortedDictionary.KeyCollection and SortedDictionary.ValueCollection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, SortedDictionary.Enumerator, SortedDictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedDictionary source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable, SortedDictionary.Enumerator, KeyValuePair, GetEnumerator>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.KeyCollection, SortedDictionary.KeyCollection.Enumerator, SortedDictionary.KeyCollection.Enumerator, TKey, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedDictionary.KeyCollection source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable.KeyCollection, SortedDictionary.KeyCollection.Enumerator, TKey, GetEnumerator>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.ValueCollection, SortedDictionary.ValueCollection.Enumerator, SortedDictionary.ValueCollection.Enumerator, TValue, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedDictionary.ValueCollection source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable.ValueCollection, SortedDictionary.ValueCollection.Enumerator, TValue, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, SortedDictionary.Enumerator> - , IFunction.KeyCollection, SortedDictionary.KeyCollection.Enumerator> - , IFunction.ValueCollection, SortedDictionary.ValueCollection.Enumerator> - where TKey : notnull - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SortedDictionary.Enumerator Invoke(SortedDictionary source) - => source.GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SortedDictionary.KeyCollection.Enumerator Invoke(SortedDictionary.KeyCollection source) - => source.GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SortedDictionary.ValueCollection.Enumerator Invoke(SortedDictionary.ValueCollection source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs deleted file mode 100644 index c5cedc01b..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class SortedSetExtensions - { - // SortedSet is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, SortedSet.Enumerator, SortedSet.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedSet source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, SortedSet.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, SortedSet.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SortedSet.Enumerator Invoke(SortedSet source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs deleted file mode 100644 index ad56d19c5..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class StackExtensions - { - // Stack is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, Stack.Enumerator, Stack.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this Stack source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, Stack.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, Stack.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Stack.Enumerator Invoke(Stack source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs deleted file mode 100644 index 2a51d9fa9..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableDictionaryExtensions - { - // ImmutableDictionary is reference-type that implements IReadOnlyCollection> and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableDictionary.Enumerator, ImmutableDictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableDictionary source) - where TKey: notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable, ImmutableDictionary.Enumerator, KeyValuePair, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ImmutableDictionary.Enumerator> - where TKey: notnull - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableDictionary.Enumerator Invoke(ImmutableDictionary source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs deleted file mode 100644 index 7f899c11c..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableHashSetExtensions - { - // ImmutableHashSet is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableHashSet.Enumerator, ImmutableHashSet.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableHashSet source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, ImmutableHashSet.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ImmutableHashSet.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableHashSet.Enumerator Invoke(ImmutableHashSet source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs deleted file mode 100644 index f759387ca..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableListExtensions - { - // ImmutableList is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableList.Enumerator, ImmutableList.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableList source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, ImmutableList.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ImmutableList.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableList.Enumerator Invoke(ImmutableList source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs deleted file mode 100644 index e58289c03..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableQueueExtensions - { - // ImmutableQueue is reference-type that implements IEnumerable and has two enumerators: - // One that is a value-type and doesn't implement interfaces. - // Another that is a reference-type and implements IEnumerator. - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EnumerableExtensions.ValueEnumerable, ValueEnumerator, ImmutableQueue.Enumerator, TSource, GetEnumerator, GetEnumerator2> AsValueEnumerable(this ImmutableQueue source) - => source.AsValueEnumerable, ValueEnumerator, ImmutableQueue.Enumerator, TSource, GetEnumerator, GetEnumerator2>(); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ValueEnumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator Invoke(ImmutableQueue source) - => new(((IEnumerable)source).GetEnumerator()); - } - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator2 - : IFunction, ImmutableQueue.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableQueue.Enumerator Invoke(ImmutableQueue source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs deleted file mode 100644 index c336609af..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableSortedDictionaryExtensions - { - // ImmutableSortedDictionary is reference-type that implements IReadOnlyCollection> and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableSortedDictionary.Enumerator, ImmutableSortedDictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableSortedDictionary source) - where TKey: notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable, ImmutableSortedDictionary.Enumerator, KeyValuePair, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ImmutableSortedDictionary.Enumerator> - where TKey: notnull - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableSortedDictionary.Enumerator Invoke(ImmutableSortedDictionary source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs deleted file mode 100644 index a153a1d07..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableStackExtensions - { - // ImmutableStack is reference-type that implements IEnumerable and has two enumerators: - // One that is a value-type and doesn't implement interfaces. - // Another that is a reference-type and implements IEnumerator. - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EnumerableExtensions.ValueEnumerable, ValueEnumerator, ImmutableStack.Enumerator, TSource, GetEnumerator, GetEnumerator2> AsValueEnumerable(this ImmutableStack source) - => source.AsValueEnumerable, ValueEnumerator, ImmutableStack.Enumerator, TSource, GetEnumerator, GetEnumerator2>(); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ValueEnumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator Invoke(ImmutableStack source) - => new(((IEnumerable)source).GetEnumerator()); - } - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator2 - : IFunction, ImmutableStack.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableStack.Enumerator Invoke(ImmutableStack source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs deleted file mode 100644 index 0fbef647e..000000000 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Memory.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Buffers; -using System.Numerics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - static partial class ArrayExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Lease ToArray(this Memory source, ArrayPool pool, bool clearOnDispose = default) - => ((ReadOnlyMemory)source).Span.ToArray(pool, clearOnDispose); - } -} - diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs deleted file mode 100644 index 5b33812c9..000000000 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlyMemory.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Buffers; -using System.Numerics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - static partial class ArrayExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Lease ToArray(this ReadOnlyMemory source, ArrayPool pool, bool clearOnDispose = default) - => source.Span.ToArray(pool, clearOnDispose); - } -} - diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs deleted file mode 100644 index 204ed3e92..000000000 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.Span.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Buffers; -using System.Numerics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - static partial class ArrayExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Lease ToArray(this Span source, ArrayPool pool, bool clearOnDispose = default) - => ((ReadOnlySpan)source).ToArray(pool, clearOnDispose); - } -} - diff --git a/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs b/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs new file mode 100644 index 000000000..eac9f7383 --- /dev/null +++ b/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs @@ -0,0 +1,405 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using NetFabric.CodeAnalysis; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Threading; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + public partial class Generator + { + static ValueEnumerableType? GenerateSourceAsValueEnumerable(Compilation compilation, SemanticModel semanticModel, TypeSymbolsCache typeSymbolsCache, MemberAccessExpressionSyntax expressionSyntax, CodeBuilder builder, Dictionary generatedMethods, CancellationToken cancellationToken) + { + // Check if the method is already defined in the project source + if (semanticModel.GetSymbolInfo(expressionSyntax, cancellationToken).Symbol is IMethodSymbol { } methodSymbol) + return methodSymbol.ReturnType.ToValueEnumerableType(typeSymbolsCache); + + // Get the type this operator is applied to + var receiverTypeSymbol = semanticModel.GetTypeInfo(expressionSyntax.Expression, cancellationToken).Type; + + // Check if NetFabric.Hyperlinq already contains specific overloads for this type + // This is required for when the 'using NetFabric.Hyperlinq;' statement is missing + if (receiverTypeSymbol is null + or { TypeKind: TypeKind.Array } // is array + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(ArraySegment<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(Span<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(ReadOnlySpan<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(Memory<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(ReadOnlyMemory<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(List<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(ImmutableArray<>)]) + ) + return null; // Do generate an implementation. The 'using NetFabric.Hyperlinq;' statement should be added instead. + + // Receiver type implements IValueEnumerable<,> + + var valueEnumerableType = AsValueEnumerable(expressionSyntax, compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken); + if (valueEnumerableType is not null) + { + // Check if the method is already defined by this generator + var methodSignature = new MethodSignature("AsValueEnumerable", valueEnumerableType.Name); + if (generatedMethods.TryGetValue(methodSignature, out var returnType)) + return returnType; + + // Receiver instance returns itself + _ = builder + .AppendLine() + .AppendGeneratedCodeMethodAttributes() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public static {valueEnumerableType.Name} AsValueEnumerable(this {valueEnumerableType.Name} source)") + .AppendIndentation().AppendLine($"=> source;"); + + // A new AsValueEnumerable() method has been generated + generatedMethods.Add(methodSignature, valueEnumerableType); + return valueEnumerableType; + } + + // Receiver type is an enumerable + + if (receiverTypeSymbol.IsEnumerable(compilation, out var enumerableSymbols)) + { + var receiverTypeString = receiverTypeSymbol.ToDisplayString(); + + // Check if the method is already defined by this generator + var methodSignature = new MethodSignature("AsValueEnumerable", receiverTypeString); + if (generatedMethods.TryGetValue(methodSignature, out var returnType)) + return returnType; + + // Use an unique identifier to avoid name clashing + var uniqueIdString = builder.IsUnitTest + ? receiverTypeString.Replace('.', '_').Replace(',', '_').Replace('<', '_').Replace('>', '_').Replace('`', '_') + : Guid.NewGuid().ToString().Replace('-', '_'); // Use a GUID to avoid naming overflow + + var enumerableTypeString = $"AsValueEnumerable_{uniqueIdString}"; + var itemType = enumerableSymbols.EnumeratorSymbols.Current.Type; + var itemTypeString = itemType.ToDisplayString(); + + // Check if the returned type by GetEnumerator() does not require a wrapper + var getEnumeratorReturnType = enumerableSymbols.GetEnumerator.ReturnType; + var getEnumeratorReturnTypeString = getEnumeratorReturnType.ToDisplayString(); + + // Check what interfaces the enumerable implements, minimizing the calls to ImplementsInterface() + var enumerableImplementsIEnumerable = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IEnumerable_T, out _); + var enumerableImplementsICollection = false; + var enumerableImplementsIReadOnlyCollection = false; + var enumerableImplementsIList = false; + var enumerableImplementsIReadOnlyList = false; + if (enumerableImplementsIEnumerable) + { + enumerableImplementsICollection = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_ICollection_T, out _); + if (enumerableImplementsICollection) + enumerableImplementsIList = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IList_T, out _); + + enumerableImplementsIReadOnlyCollection = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IReadOnlyCollection_T, out _); + if (enumerableImplementsIReadOnlyCollection) + enumerableImplementsIReadOnlyList = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IReadOnlyList_T, out _); + } + + // Define what value enumerator type will be used + var enumeratorImplementsIEnumerator = getEnumeratorReturnType.ImplementsInterface(SpecialType.System_Collections_Generic_IEnumerator_T, out _); + var useConstraints = enumerableImplementsIEnumerable; + + var enumeratorTypeString = enumeratorImplementsIEnumerator + ? getEnumeratorReturnType.IsValueType + ? getEnumeratorReturnTypeString + : $"ValueEnumerator<{itemTypeString}>" + : useConstraints + ? $"{enumerableTypeString}.Enumerator" + : $"{enumerableTypeString}.Enumerator"; + + // Generate the method + _ = useConstraints + ? builder + .AppendLine() + .AppendGeneratedCodeMethodAttributes() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public static {enumerableTypeString}<{receiverTypeString}> AsValueEnumerable(this {receiverTypeString} source)") + .AppendIndentation().AppendLine($"=> new(source, source);") + : builder + .AppendLine() + .AppendGeneratedCodeMethodAttributes() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public static {enumerableTypeString} AsValueEnumerable(this {receiverTypeString} source)") + .AppendIndentation().AppendLine($"=> new(source);"); + + // Generate the value enumerable wrapper + string valueEnumerableTypeName; + valueEnumerableTypeName = useConstraints + ? $"{enumerableTypeString}" + : enumerableTypeString; + + _ = builder + .AppendLine() + .AppendLine($"public readonly struct {valueEnumerableTypeName}"); + + // Define what interfaces the wrapper implements + if (enumerableImplementsIList || enumerableImplementsIReadOnlyList) + _ = builder.AppendIndentation().AppendLine($": IValueReadOnlyList<{itemTypeString}, {enumeratorTypeString}>, IList<{itemTypeString}>"); + else if (enumerableImplementsICollection || enumerableImplementsIReadOnlyCollection) + _ = builder.AppendIndentation().AppendLine($": IValueReadOnlyCollection<{itemTypeString}, {enumeratorTypeString}>, ICollection<{itemTypeString}>"); + else + _ = builder.AppendIndentation().AppendLine($": IValueEnumerable<{itemTypeString}, {enumeratorTypeString}>"); + + if (useConstraints) + { + if (enumerableImplementsIList) + _ = builder.AppendIndentation().AppendLine($"where TEnumerable : IList"); + else if (enumerableImplementsIReadOnlyList) + _ = builder.AppendIndentation().AppendLine($"where TEnumerable : IReadOnlyList"); + else if (enumerableImplementsICollection) + _ = builder.AppendIndentation().AppendLine($"where TEnumerable : ICollection"); + else if (enumerableImplementsIReadOnlyCollection) + _ = builder.AppendIndentation().AppendLine($"where TEnumerable : IReadOnlyCollection"); + else if (enumerableImplementsIEnumerable) + _ = builder.AppendIndentation().AppendLine($"where TEnumerable : IEnumerable"); + } + + using (builder.AppendBlock()) + { + // Define fields + _ = builder.AppendLine($"readonly {receiverTypeString} source;"); + if (useConstraints) + _ = builder.AppendLine($"readonly TEnumerable source2;"); + + // Define constructor + _ = useConstraints + ? builder + .AppendLine() + .AppendLine($"internal {enumerableTypeString}({receiverTypeString} source, TEnumerable source2)") + .AppendIndentation().AppendLine($"=> (this.source, this.source2) = (source, source2);") + : builder + .AppendLine() + .AppendLine($"internal {enumerableTypeString}({receiverTypeString} source)") + .AppendIndentation().AppendLine($"=> this.source = source;"); + + // Implement IValueEnumerable<,> + + _ = builder + .AppendLine() + .AppendLine($"// Implement IValueEnumerable<{itemTypeString}, {enumeratorTypeString}>") + .AppendLine(); + + if (enumeratorImplementsIEnumerator) + { + if (getEnumeratorReturnType.IsValueType) + { + // No enumerator wrapper required + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public {enumeratorTypeString} GetEnumerator() => source.GetEnumerator();") + .AppendLine() + .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source2.GetEnumerator();") + .AppendLine() + .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator();"); + } + else if (enumerableSymbols.GetEnumerator.ContainingType.IsInterface()) + { + // Use the ValueEnumerator<> enumerator wrapper + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public ValueEnumerator<{itemTypeString}> GetEnumerator() => new(source2.GetEnumerator());") + .AppendLine() + .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source2.GetEnumerator();") + .AppendLine() + .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator();"); + } + else + { + // Use the ValueEnumerator<> enumerator wrapper + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public ValueEnumerator<{itemTypeString}> GetEnumerator() => new(source.GetEnumerator());") + .AppendLine() + .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source2.GetEnumerator();") + .AppendLine() + .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator();"); + } + } + else + { + // A custom enumerator wrapper is required + + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public Enumerator GetEnumerator() => new(source.GetEnumerator());") + .AppendLine() + .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => new Enumerator(source.GetEnumerator());") + .AppendLine() + .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator());") + .AppendLine(); + + using (builder.AppendBlock($"public struct Enumerator : IEnumerator<{itemTypeString}>")) + { + _ = builder + .AppendLine($"readonly {getEnumeratorReturnTypeString} source;") + .AppendLine() + .AppendLine($"internal Enumerator({getEnumeratorReturnTypeString} source)") + .AppendIndentation().AppendLine("=> this.source = source;") + .AppendLine() + .AppendLine($"public {itemTypeString} Current => source.Current;") + .AppendLine() + .AppendLine("object? IEnumerator.Current => source.Current;") + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine("public bool MoveNext() => source.MoveNext();") + .AppendLine(); + + _ = enumerableSymbols.EnumeratorSymbols.Reset is null + ? builder + .AppendLine("public void Reset() => throw new NotSupportedException();") + : builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine("public void Reset() => source.Reset();"); + + _ = enumerableSymbols.EnumeratorSymbols.Dispose is null + ? builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine("public void Dispose() { }") + : builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine("public void Dispose() => source.Dispose();"); + } + } + + // Implement ICollection<> + + if (enumerableImplementsICollection || enumerableImplementsIReadOnlyCollection) + { + _ = builder + .AppendLine() + .AppendLine($"// Implement ICollection<{itemTypeString}>") + .AppendLine() + .AppendLine("public int Count => source2.Count;") + .AppendLine() + .AppendLine("public bool IsReadOnly => true;") + .AppendLine() + .AppendLine($"void ICollection<{itemTypeString}>.Add({itemTypeString} item) => throw new NotSupportedException();") + .AppendLine() + .AppendLine($"bool ICollection<{itemTypeString}>.Remove({itemTypeString} item) => throw new NotSupportedException();") + .AppendLine() + .AppendLine($"void ICollection<{itemTypeString}>.Clear() => throw new NotSupportedException();") + .AppendLine(); + + // Add a CopyTo() that takes a Span<> as parameter + using (builder.AppendBlock($"public void CopyTo(Span<{itemTypeString}> span)")) + { + _ = builder + .AppendLine("if (Count is 0) return;") + .AppendLine("if (span.Length < Count) throw new ArgumentException(\"Destination span was not long enough.\", nameof(span));") + .AppendLine(); + + _ = builder.AppendLine("var index = 0;"); + using (builder.AppendBlock("foreach (var current in this)")) + { + _ = builder + .AppendLine("span[index] = current;") + .AppendLine("checked { index++; }"); + } + } + + if (enumerableImplementsICollection) + { + // Call the methods implemented by the source + _ = builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public bool Contains({itemTypeString} item) => source2.Contains(item);") + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public void CopyTo({itemTypeString}[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex);"); + } + else + { + // The source does not implement these methods so we have to add an implementation + _ = builder.AppendLine(); + + using (builder.AppendBlock($"public bool Contains({itemTypeString} item)")) + { + using (builder.AppendBlock($"foreach (var current in this)")) + { + _ = builder.AppendLine($"if (EqualityComparer<{itemTypeString}>.Default.Equals(current, item)) return true;"); + } + _ = builder.AppendLine("return true;"); + } + + _ = builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public void CopyTo({itemTypeString}[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex));"); + } + + // Implement ICollection<> + + if (enumerableImplementsIList || enumerableImplementsIReadOnlyList) + { + _ = builder + .AppendLine() + .AppendLine($"// Implement IList<{itemTypeString}>") + .AppendLine() + .AppendLine($"public {itemTypeString} this[int index] => source2[index];") + .AppendLine(); + + using (builder.AppendBlock($"{itemTypeString} IList<{itemTypeString}>.this[int index]")) + { + _ = builder + .AppendLine("get => source2[index];") + .AppendLine("set => throw new NotSupportedException();"); + } + + _ = builder + .AppendLine() + .AppendLine($"void IList<{itemTypeString}>.Insert(int index, {itemTypeString} item) => throw new NotSupportedException();") + .AppendLine() + .AppendLine($"void IList<{itemTypeString}>.RemoveAt(int index) => throw new NotSupportedException();") + .AppendLine(); + + if (enumerableImplementsIList) + { + // Call the methods implemented by the source + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public int IndexOf({itemTypeString} item) => source2.IndexOf(item);"); + } + else + { + // The source does not implement these methods so we have to add an implementation + using (builder.AppendBlock($"public int IndexOf({itemTypeString} item)")) + { + using (builder.AppendBlock($"if (Count is not 0)")) + { + _ = builder.AppendLine("var index = 0;"); + using (builder.AppendBlock($"foreach (var current in this)")) + { + _ = builder + .AppendLine($"if (EqualityComparer<{itemTypeString}>.Default.Equals(current, item)) return index;") + .AppendLine() + .AppendLine("checked { index++; }"); + } + } + _ = builder.AppendLine("return -1;"); + } + } + } + } + + // A new AsValueEnumerable() method has been generated + valueEnumerableType = new ValueEnumerableType( + Name: valueEnumerableTypeName, + EnumeratorType: enumeratorTypeString, + ItemType: itemTypeString, + IsCollection: enumerableImplementsICollection || enumerableImplementsIReadOnlyCollection, + IsList: enumerableImplementsIList || enumerableImplementsIReadOnlyList); + generatedMethods.Add(methodSignature, valueEnumerableType); + return valueEnumerableType; + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Generator.cs b/NetFabric.Hyperlinq/Generator.cs new file mode 100644 index 000000000..597b81e64 --- /dev/null +++ b/NetFabric.Hyperlinq/Generator.cs @@ -0,0 +1,348 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; +using NetFabric.CodeAnalysis; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Reflection.Metadata; +using System.Text; +using System.Threading; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + [Generator] + public partial class Generator + : ISourceGenerator + { + static readonly string assemblyName = typeof(CodeBuilder).Assembly.GetName().Name; + static readonly string assemblyVersion = typeof(CodeBuilder).Assembly.GetCustomAttribute()?.InformationalVersion ?? string.Empty; + + static readonly DiagnosticDescriptor unhandledExceptionError = new( + id: "HPLG001", + title: "Unhandled exception while generating overloads", + messageFormat: "Unhandled exception while generating overloads: {0}", + category: "OverloadsGenerator", + DiagnosticSeverity.Error, + isEnabledByDefault: true); + + internal static readonly ImmutableHashSet methods = ImmutableHashSet.Create(new[] + { + // aggregation + "Count", + "CountAsync", + "Sum", + "SumVector", + "SumAsync", + + // conversion + "AsEnumerable", + "AsAsyncEnumerable", + "AsValueEnumerable", + "AsAsyncValueEnumerable", + "ToArray", + "ToArrayVector", + "ToArrayAsync", + "ToDictionary", + "ToDictionaryAsync", + "ToList", + "ToListVector", + "ToListAsync", + + // element + "ElementAt", + "ElementAtAsync", + "First", + "FirstAsync", + "Single", + "SingleAsync", + + // filtering + "Where", + "WhereAsync", + + // partitioning + "Skip", + "SkipAsync", + "Take", + "TakeAsync", + + // projection + "Select", + "SelectVector", + "SelectAsync", + "SelectMany", + "SelectManyAsync", + + // quantifier + "All", + "AllAsync", + "Any", + "AnyAsync", + "Contains", + "ContainsVector", + "ContainsAsync", + + // quantifier + "Distinct", + "DistinctAsync", + }); + + static readonly ImmutableHashSet sumTypes = ImmutableHashSet.Create(new[] + { + "int", + "int?", + "nint", + "nint?", + "nuint", + "nuint?", + "long", + "long?", + "float", + "float?", + "double", + "double?", + "decimal", + "decimal?", + }); + + public void Initialize(GeneratorInitializationContext context) + { +#if DEBUG + if (!Debugger.IsAttached) + _ = Debugger.Launch(); +#endif + + context.RegisterForSyntaxNotifications(() => new SyntaxReceiver(methods)); + } + + public void Execute(GeneratorExecutionContext context) + { + var typeSymbolsCache = new TypeSymbolsCache(context.Compilation); + + // Check if NetFabric.Hyperlinq.Abstractions and NetFabric.Hyperlinq.Abstractions are referenced + if (typeSymbolsCache[typeof(IValueEnumerable<,>)] is null + || typeSymbolsCache[typeof(ValueEnumerableExtensions)] is null) + return; // TODO: return a Diagnostic? + + if (context.SyntaxReceiver is not SyntaxReceiver receiver) + return; + + try + { + var builder = new CodeBuilder(); + GenerateSource(context.Compilation, typeSymbolsCache, receiver.MemberAccessExpressions, builder, context.CancellationToken); + context.AddSource("ExtensionMethods.g.cs", SourceText.From(builder.ToString(), Encoding.UTF8)); + } + catch (OperationCanceledException) + { + throw; + } + catch (Exception ex) + { + context.ReportDiagnostic(Diagnostic.Create(unhandledExceptionError, Location.None, ex.Message)); + } + } + + internal static void GenerateSource(Compilation compilation, TypeSymbolsCache typeSymbolsCache, List memberAccessExpressions, CodeBuilder builder, CancellationToken cancellationToken) + { + var generatedMethods = new Dictionary(); + + _ = builder + .AppendLine("#nullable enable") + .AppendLine() + .AppendLine("using System;") + .AppendLine("using System.CodeDom.Compiler;") + .AppendLine("using System.Collections;") + .AppendLine("using System.Collections.Generic;") + .AppendLine("using System.ComponentModel;") + .AppendLine("using System.Diagnostics;") + .AppendLine("using System.Diagnostics.CodeAnalysis;") + .AppendLine("using System.Runtime.CompilerServices;") + .AppendLine(); + + using (builder.AppendBlock("namespace NetFabric.Hyperlinq")) + using (builder.AppendBlock("static partial class GeneratedExtensionMethods")) + { + foreach (var expressionSyntax in memberAccessExpressions) + { + cancellationToken.ThrowIfCancellationRequested(); + + var semanticModel = compilation.GetSemanticModel(expressionSyntax.SyntaxTree); + + _ = GenerateSource(compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken); + } + } + } + + static ValueEnumerableType? AsValueEnumerable(MemberAccessExpressionSyntax memberAccessExpressionSyntax, Compilation compilation, SemanticModel semanticModel, TypeSymbolsCache typeSymbolsCache, MemberAccessExpressionSyntax expressionSyntax, CodeBuilder builder, Dictionary generatedMethods, CancellationToken cancellationToken) + { + var typeSymbol = semanticModel.GetTypeInfo(memberAccessExpressionSyntax.Expression, cancellationToken).Type; + if (typeSymbol is null) + return null; + + // Check if the receiver type implements IValueEnumerable<,> + var valueEnumerableType = typeSymbol.ToValueEnumerableType(typeSymbolsCache); + if (valueEnumerableType is not null) + return valueEnumerableType; + + // Go up one layer. Generate method if required. + if (expressionSyntax.Expression is InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax receiverSyntax }) + { + valueEnumerableType = GenerateSource(compilation, semanticModel, typeSymbolsCache, receiverSyntax, builder, generatedMethods, cancellationToken); + if (valueEnumerableType is not null) + return valueEnumerableType; + } + + // Receiver type does not implement IValueEnumerable<,> so nothing else needs to be done + return null; + } + + static ValueEnumerableType? GenerateSource(Compilation compilation, SemanticModel semanticModel, TypeSymbolsCache typeSymbolsCache, MemberAccessExpressionSyntax expressionSyntax, CodeBuilder builder, Dictionary generatedMethods, CancellationToken cancellationToken) + => expressionSyntax.Name.ToString() switch + { + "AsValueEnumerable" => GenerateSourceAsValueEnumerable(compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken), + _ => GenerateSourceDefault(compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken), + }; + + static ValueEnumerableType? GenerateSourceDefault(Compilation compilation, SemanticModel semanticModel, TypeSymbolsCache typeSymbolsCache, MemberAccessExpressionSyntax expressionSyntax, CodeBuilder builder, Dictionary generatedMethods, CancellationToken cancellationToken) + { + // Find the receiver type + var receiverType = AsValueEnumerable(expressionSyntax, compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken); + if (receiverType is null) + return null; + + var methodName = expressionSyntax.Name.ToString(); + if (methodName == "Sum" && !sumTypes.Contains(receiverType.ItemType)) + return null; + + var containingClass = receiverType.IsList + ? typeSymbolsCache[typeof(ValueReadOnlyListExtensions)]! + : receiverType.IsCollection + ? typeSymbolsCache[typeof(ValueReadOnlyCollectionExtensions)]! + : typeSymbolsCache[typeof(ValueEnumerableExtensions)]!; + var containingClassString = containingClass.ToDisplayString(); + + // Check if the method is already defined + var symbol = semanticModel.GetSymbolInfo(expressionSyntax, cancellationToken).Symbol; + if (symbol is IMethodSymbol methodSymbol) + { + // If it's an instance method of a type that implements IValueEnumerable<,> then it's already optimized. + if (methodSymbol.ReceiverType is not null && methodSymbol.ReceiverType.ImplementsInterface(typeSymbolsCache[typeof(IValueEnumerable<,>)]!, out _)) + return methodSymbol.ReturnType.ToValueEnumerableType(typeSymbolsCache); // return the returned type + + // Check if the generator already generated the extension method + var parameters = methodSymbol.Parameters.Select(parameter => parameter.Type.ToDisplayString()) + .ToArray(); + var methodSignature = + new MethodSignature(expressionSyntax.Name.ToString(), receiverType.Name, parameters); + if (generatedMethods.TryGetValue(methodSignature, out var returnType)) + return returnType; + + // Generate the extension method + var comparer = new TypeSymbolConversionComparer(compilation); + var parametersTypes = methodSymbol.Parameters.Select(parameter => parameter.Type).ToArray(); + var hyperlinqMethods = containingClass + .GetMembers() + .OfType() + .Where(method => + method.IsPublic() + && method.Name == methodName + && method.Parameters.Skip(1).Select(parameter => parameter.Type).SequenceEqual(parametersTypes, comparer)) + .ToArray(); + var hyperlinqMethod = hyperlinqMethods.FirstOrDefault(); + if (hyperlinqMethod is null) + return null; + + var parametersString = string.Join(", ", + new[] { $"{receiverType.Name} source" } + .Concat(methodSymbol.Parameters.Select(static parameter => $"{parameter.Type.ToDisplayString()} {parameter.Name}"))); + var argumentsString = string.Join(", ", + new[] { "source" } + .Concat(methodSymbol.Parameters.Select(parameter => MapArgument(parameter, typeSymbolsCache)))); + var typeArgumentsString = string.Join(", ", + new[] { receiverType.Name, receiverType.EnumeratorType } + .Concat(methodSymbol.TypeArguments.Select(argument => MapTypeArgument(argument, typeSymbolsCache)))); + var returnTypeString = hyperlinqMethod.ReturnType is INamedTypeSymbol { IsGenericType: true } + ? $"{hyperlinqMethod.ReturnType.ContainingType}.{hyperlinqMethod.ReturnType.Name}<{typeArgumentsString}>" + : hyperlinqMethod.ReturnType.ToDisplayString(); + _ = builder + .AppendLine() + .AppendGeneratedCodeMethodAttributes() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public static {returnTypeString} {methodSymbol.Name}(this {parametersString})") + .AppendIndentation() + .AppendLine($"=> {containingClassString}.{methodSymbol.Name}<{typeArgumentsString}>({argumentsString});"); + } + + // The method is not yet defined + if (expressionSyntax.Parent is InvocationExpressionSyntax invocation) + { + var a = invocation.ArgumentList.Arguments + .Select(argument => semanticModel.GetTypeInfo(argument.Expression).Type) + .ToArray(); + // Check if the generator already generated the extension method + //var parameters = new string[] { receiverType.Name }.Concat(invocation.ArgumentList.Arguments.Select(argument => argument.ToDisplayString())).ToArray(); + //var methodSignature = new MethodSignature(expressionSyntax.Name.ToString(), parameters); + //if (generatedMethods.TryGetValue(methodSignature, out var returnType)) + // return returnType; + + //// Generate the extension method + //var hyperlinqMethod = hyperlinqMethods.FirstOrDefault(); + + //var parametersString = string.Join(", ", + // new string[] { $"{receiverType.Name} source" } + // .Concat(methodSymbol.Parameters.Select(parameter => $"{parameter.Type.ToDisplayString()} {parameter.Name}"))); + //var argumentsString = string.Join(", ", + // new string[] { "source" } + // .Concat(methodSymbol.Parameters.Select(parameter => parameter.Name))); + //_ = builder + // .AppendLine() + // .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + // .AppendLine($"public static {hyperlinqMethod.ReturnType.ToDisplayString()} {methodSymbol.Name}(this {parametersString})") + // .AppendIndentation().AppendLine($"=> {containingClassString}.{methodSymbol.Name}<{receiverType.Name}, {receiverType.EnumeratorType}, {receiverType.ItemType}>({argumentsString});"); + + //generatedMethods.Add(methodSignature, returnType); + //return returnType; + } + + return null; + + static string MapArgument(IParameterSymbol parameter, TypeSymbolsCache typeSymbolsCache) + { + if (parameter.Type is INamedTypeSymbol { IsGenericType: true } namedTypeSymbol) + { + // Convert Func<> to FunctionWrapper<> + if (SymbolEqualityComparer.Default.Equals(parameter.Type.OriginalDefinition, typeSymbolsCache[typeof(Func<,>)])) + { + var typeArguments = string.Join(", ", + namedTypeSymbol.TypeArguments.Select(argument => argument.ToDisplayString())); + return $"new NetFabric.Hyperlinq.FunctionWrapper<{typeArguments}>({parameter.Name})"; + } + } + + return parameter.Name; + } + + static string MapTypeArgument(ITypeSymbol argument, TypeSymbolsCache typeSymbolsCache) + { + if (argument is INamedTypeSymbol { IsGenericType: true } namedTypeSymbol) + { + // Convert Func<> to FunctionWrapper<> + if (SymbolEqualityComparer.Default.Equals(argument.OriginalDefinition, typeSymbolsCache[typeof(Func<,>)])) + { + var typeArguments = string.Join(", ", + namedTypeSymbol.TypeArguments.Select(argument => argument.ToDisplayString())); + return $"NetFabric.Hyperlinq.FunctionWrapper<{typeArguments}>"; + } + } + + return argument.ToDisplayString(); + } + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/ITypeSymbolExtensions.cs b/NetFabric.Hyperlinq/ITypeSymbolExtensions.cs new file mode 100644 index 000000000..596bdd104 --- /dev/null +++ b/NetFabric.Hyperlinq/ITypeSymbolExtensions.cs @@ -0,0 +1,53 @@ +using Microsoft.CodeAnalysis; +using NetFabric.CodeAnalysis; +using System.Collections.Immutable; +using System.Runtime.CompilerServices; + +// ReSharper disable LoopCanBeConvertedToQuery + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + static class ITypeSymbolExtensions + { + public static bool ImplementsAnyInterface(this ITypeSymbol typeSymbol, INamedTypeSymbol[] interfaceTypes, out ImmutableArray genericArguments) + { + if (typeSymbol is INamedTypeSymbol namedTypeSymbol) + { + foreach (var interfaceType in interfaceTypes) + { + if (SymbolEqualityComparer.Default.Equals(namedTypeSymbol.OriginalDefinition, interfaceType)) + { + genericArguments = namedTypeSymbol.TypeArguments; + return true; + } + } + } + + // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator + foreach (var @interface in typeSymbol.AllInterfaces) + { + foreach (var interfaceType in interfaceTypes) + { + if (SymbolEqualityComparer.Default.Equals(@interface.OriginalDefinition, interfaceType)) + { + genericArguments = @interface.TypeArguments; + return true; + } + } + } + + Unsafe.SkipInit(out genericArguments); + return false; + } + + public static ValueEnumerableType? ToValueEnumerableType(this ITypeSymbol typeSymbol, TypeSymbolsCache typeSymbolsCache) + => !typeSymbol.ImplementsInterface(typeSymbolsCache[typeof(IValueEnumerable<,>)]!, out var genericArguments) + ? null + : new ValueEnumerableType( + Name: typeSymbol.ToDisplayString(), + EnumeratorType: genericArguments[1].ToDisplayString(), + ItemType: genericArguments[0].ToDisplayString(), + IsCollection: typeSymbol.ImplementsInterface(typeSymbolsCache[typeof(IValueReadOnlyCollection<,>)]!, out _), + IsList: typeSymbol.ImplementsInterface(typeSymbolsCache[typeof(IValueReadOnlyList<,>)]!, out _)); + } +} diff --git a/NetFabric.Hyperlinq/MethodSignature.cs b/NetFabric.Hyperlinq/MethodSignature.cs new file mode 100644 index 000000000..cdd27a357 --- /dev/null +++ b/NetFabric.Hyperlinq/MethodSignature.cs @@ -0,0 +1,41 @@ +using Microsoft.CodeAnalysis; +using System; +using System.Collections.Immutable; +using System.Linq; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + readonly struct MethodSignature + : IEquatable + { + public MethodSignature(string name, string receiverType, params string[] parameters) + => (Name, ReceiverType, Parameters) = (name, receiverType, ImmutableArray.Create(parameters)); + + string Name { get; } + string ReceiverType { get; } + ImmutableArray Parameters { get; } + + public bool Equals(MethodSignature other) + => Name == other.Name && ReceiverType == other.ReceiverType && Parameters.SequenceEqual(other.Parameters); + + public override bool Equals(object other) + => other is MethodSignature signature && Equals(signature); + + public override int GetHashCode() + { + unchecked + { + const int hashingBase = (int)2166136261; + const int hashingMultiplier = 16777619; + + var hash = hashingBase; + hash = (hash * hashingMultiplier) ^ Name.GetHashCode(); + hash = (hash * hashingMultiplier) ^ ReceiverType.GetHashCode(); + // ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator + foreach(var parameter in Parameters) + hash = (hash * hashingMultiplier) ^ parameter.GetHashCode(); + return hash; + } + } + } +} diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 1b7b2c4eb..fd7fdc48b 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -1,60 +1,55 @@  - netstandard2.0;netcoreapp3.1;net5.0;net6.0 - NetFabric.Hyperlinq - NetFabric.Hyperlinq + netstandard2.0 + NetFabric.Hyperlinq.SourceGenerator + NetFabric.Hyperlinq.SourceGenerator High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, Memory, and Span. 3.0.0-beta48 Icon.png LICENSE netfabric, hyperlinq, linq, enumeration, extensions, performance true - true - true - snupkg - true - - - - - - $(NoWarn);8600;8601;8602;8603;8604 + true + false - + + + true + + + + true + - - - - - - - + + - + - - - + + + + + - - - + + + + + + - - - - - - + - - - + + all runtime; build; native; contentfiles; analyzers @@ -62,33 +57,14 @@ all runtime; build; native; contentfiles; analyzers - - all - runtime; build; native; contentfiles; analyzers - - + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers - - - True - True - Resource.resx - - - - - - ResXFileCodeGenerator - Resource.Designer.cs - - - - - - - diff --git a/NetFabric.Hyperlinq/Properties/AssemblyInfo.cs b/NetFabric.Hyperlinq/Properties/AssemblyInfo.cs index 718964469..a48e711f2 100644 --- a/NetFabric.Hyperlinq/Properties/AssemblyInfo.cs +++ b/NetFabric.Hyperlinq/Properties/AssemblyInfo.cs @@ -1,3 +1,3 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; -[assembly:InternalsVisibleTo("NetFabric.Hyperlinq.UnitTests")] \ No newline at end of file +[assembly: InternalsVisibleTo("NetFabric.Hyperlinq.UnitTests")] \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyCollection.cs deleted file mode 100644 index b1712c02e..000000000 --- a/NetFabric.Hyperlinq/Quantifier/Any/Any.ValueReadOnlyCollection.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyCollectionExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => source.Count is not 0; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => Any>(source, new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.Count is not 0 && ValueEnumerableExtensions.Any(source, predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => AnyAt>(source, new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool AnyAt(this TEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.Count is not 0 && ValueEnumerableExtensions.AnyAt(source, predicate); - } -} - diff --git a/NetFabric.Hyperlinq/SyntaxReceiver.cs b/NetFabric.Hyperlinq/SyntaxReceiver.cs new file mode 100644 index 000000000..56fd3dd59 --- /dev/null +++ b/NetFabric.Hyperlinq/SyntaxReceiver.cs @@ -0,0 +1,33 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + class SyntaxReceiver : ISyntaxReceiver + { + readonly ImmutableHashSet memberAccessNames; + + public SyntaxReceiver(ImmutableHashSet memberAccessNames) + => this.memberAccessNames = memberAccessNames; + + public List MemberAccessExpressions { get; } = new(); + + public void OnVisitSyntaxNode(SyntaxNode syntaxNode) + { + switch (syntaxNode) + { + case MemberAccessExpressionSyntax { Name: var memberName } memberAccessExpression: + if (memberAccessExpression.Kind() == SyntaxKind.SimpleMemberAccessExpression + && memberAccessNames.Contains(memberName.Identifier.ValueText)) + { + // It's a SimpleMemberAccessExpression and its name is in memberAccessNames collection + MemberAccessExpressions.Add(memberAccessExpression); + } + break; + } + } + } +} diff --git a/NetFabric.Hyperlinq/TypeSymbolsCache.cs b/NetFabric.Hyperlinq/TypeSymbolsCache.cs new file mode 100644 index 000000000..f3694a1e6 --- /dev/null +++ b/NetFabric.Hyperlinq/TypeSymbolsCache.cs @@ -0,0 +1,28 @@ +using Ben.Collections; +using Microsoft.CodeAnalysis; +using System; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + class TypeSymbolsCache + { + readonly Compilation compilation; + readonly TypeDictionary cacheByType = new(); + + public TypeSymbolsCache(Compilation compilation) + => this.compilation = compilation; + + public INamedTypeSymbol? this[Type type] + { + get + { + if (cacheByType.TryGetValue(type, out var symbol)) + return symbol; + + symbol = compilation.GetTypeByMetadataName(type.FullName); + cacheByType[type] = symbol; + return symbol; + } + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/AttributeExtensions.cs b/NetFabric.Hyperlinq/Utils/AttributeExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Utils/AttributeExtensions.cs rename to NetFabric.Hyperlinq/Utils/AttributeExtensions.cs diff --git a/NetFabric.Hyperlinq/Utils/CodeBuilder.cs b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs new file mode 100644 index 000000000..e04962173 --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs @@ -0,0 +1,98 @@ +using System; +using System.IO; +using System.Reflection; +using System.Text; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + class CodeBuilder + { + static readonly string indentation = " "; + + static readonly string assemblyName = typeof(CodeBuilder).Assembly.GetName().Name; + static readonly string assemblyVersion = typeof(CodeBuilder).Assembly.GetCustomAttribute()?.InformationalVersion ?? string.Empty; + + readonly StringBuilder builder = new(); + int currentLevel = 0; + + public CodeBuilder(bool isUnitTest = false) + => IsUnitTest = isUnitTest; + + public bool IsUnitTest { get; } + + StringBuilder Indent() + { + for (var level = 0; level < currentLevel; level++) + _ = builder.Append(indentation); + + return builder; + } + + public CodeBuilder AppendIndentation() + { + _ = builder.Append(indentation); + return this; + } + + public CodeBuilder AppendLine() + { + _ = builder.AppendLine(); + return this; + } + + public CodeBuilder AppendLine(char text) + { + _ = Indent().Append(text).AppendLine(); + return this; + } + + public CodeBuilder AppendLine(string text) + { + _ = Indent().AppendLine(text); + return this; + } + + public CodeBuilder AppendLine(Action line) + { + _ = Indent(); + line(builder); + _ = AppendLine(); + return this; + } + + public IDisposable AppendBlock() + { + _ = AppendLine('{'); + currentLevel++; + // ReSharper disable once HeapView.ObjectAllocation.Evident + return new CloseBlock(this); + } + + public IDisposable AppendBlock(string text) + => AppendLine(text).AppendBlock(); + + class CloseBlock : IDisposable + { + readonly CodeBuilder builder; + + public CloseBlock(CodeBuilder builder) + => this.builder = builder; + + public void Dispose() + { + builder.currentLevel--; + _ = builder.AppendLine('}'); + } + } + + public CodeBuilder AppendGeneratedCodeMethodAttributes() + => AppendLine($"[GeneratedCode(\"{assemblyName}\", \"{(IsUnitTest ? "0.0.0" : assemblyVersion)}\")]") + .AppendLine("[DebuggerNonUserCode]") + .AppendLine("[ExcludeFromCodeCoverage]") + .AppendLine("[EditorBrowsable(EditorBrowsableState.Never)]") + .AppendLine("[Obsolete(\"This method is not intended to be used directly by user code\")]"); + + public override string ToString() + => builder.ToString(); + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/DictionarySet.cs b/NetFabric.Hyperlinq/Utils/DictionarySet.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Utils/DictionarySet.cs rename to NetFabric.Hyperlinq/Utils/DictionarySet.cs diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs b/NetFabric.Hyperlinq/Utils/MethodSymbolExtensions.cs similarity index 98% rename from NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs rename to NetFabric.Hyperlinq/Utils/MethodSymbolExtensions.cs index 8b92294ce..a04fe3d7e 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/MethodSymbolExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/MethodSymbolExtensions.cs @@ -54,7 +54,7 @@ public static MethodInfo GetInfo(this IMethodSymbol method, CompilationContext c throw; } - string ToDisplayString(object? obj) + static string ToDisplayString(object? obj) => obj switch { null => "", diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/NamespaceSymbolExtensions.cs b/NetFabric.Hyperlinq/Utils/NamespaceSymbolExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Utils/NamespaceSymbolExtensions.cs rename to NetFabric.Hyperlinq/Utils/NamespaceSymbolExtensions.cs diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs b/NetFabric.Hyperlinq/Utils/StringExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Utils/StringExtensions.cs rename to NetFabric.Hyperlinq/Utils/StringExtensions.cs diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs b/NetFabric.Hyperlinq/Utils/SymbolExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Utils/SymbolExtensions.cs rename to NetFabric.Hyperlinq/Utils/SymbolExtensions.cs diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeParameterSymbolExtensions.cs b/NetFabric.Hyperlinq/Utils/TypeParameterSymbolExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Utils/TypeParameterSymbolExtensions.cs rename to NetFabric.Hyperlinq/Utils/TypeParameterSymbolExtensions.cs diff --git a/NetFabric.Hyperlinq/Utils/TypeSymbolConversionComparer.cs b/NetFabric.Hyperlinq/Utils/TypeSymbolConversionComparer.cs new file mode 100644 index 000000000..f151d8a02 --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/TypeSymbolConversionComparer.cs @@ -0,0 +1,24 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using System.Collections.Generic; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + public class TypeSymbolConversionComparer + : IEqualityComparer + { + readonly Compilation compilation; + + public TypeSymbolConversionComparer(Compilation compilation) + => this.compilation = compilation; + + public bool Equals(ITypeSymbol x, ITypeSymbol y) + => (x is INamedTypeSymbol { IsGenericType: true } + && y is INamedTypeSymbol { IsGenericType: true } + && compilation.ClassifyConversion(x.OriginalDefinition, y.OriginalDefinition).Exists) + || compilation.ClassifyConversion(x, y).Exists; + + public int GetHashCode(ITypeSymbol obj) + => SymbolEqualityComparer.Default.GetHashCode(obj); + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs b/NetFabric.Hyperlinq/Utils/TypeSymbolExtensions.cs similarity index 100% rename from NetFabric.Hyperlinq.SourceGenerator/Utils/TypeSymbolExtensions.cs rename to NetFabric.Hyperlinq/Utils/TypeSymbolExtensions.cs diff --git a/NetFabric.Hyperlinq/ValueEnumerableType.cs b/NetFabric.Hyperlinq/ValueEnumerableType.cs new file mode 100644 index 000000000..28b79c1f2 --- /dev/null +++ b/NetFabric.Hyperlinq/ValueEnumerableType.cs @@ -0,0 +1,6 @@ +using System; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + record ValueEnumerableType(string Name, string EnumeratorType, string ItemType, bool IsCollection, bool IsList); +} diff --git a/README.md b/README.md index 0709d4fb2..ed0625676 100644 --- a/README.md +++ b/README.md @@ -426,6 +426,7 @@ The following open-source projects are used to build and test this project: - [.NET](https://github.com/dotnet) - [BenchmarkDotNet](https://benchmarkdotnet.org/) +- [Ben.TypeDictionary](https://github.com/benaadams/Ben.TypeDictionary) - [coveralls](https://coveralls.io) - [coverlet](https://github.com/tonerdo/coverlet) - [ILRepack](https://github.com/gluck/il-repack) @@ -434,6 +435,7 @@ The following open-source projects are used to build and test this project: - [NetFabric.Hyperlinq.Analyzer](https://github.com/NetFabric/NetFabric.Hyperlinq.Analyzer) - [Nullable](https://github.com/manuelroemer/Nullable) - [Source Link](https://github.com/dotnet/sourcelink) +- [UnoptimizedAssemblyDetector](https://github.com/bruno-garcia/unoptimized-assembly-detector) - [xUnit.net](https://xunit.net/) ## License From 2c13b9b12616f6f7d3cfb979bf15dd7e655cc350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anta=CC=83o=20Almada?= Date: Thu, 23 Sep 2021 09:01:05 +0100 Subject: [PATCH 56/61] Remove Obsolete --- ...umerable.TestEnumerableWithValueTypeEnumerator.cs | 6 ------ .../Results/AsValueEnumerable.IReadOnlyList.cs | 6 ------ .../TestData/Results/AsValueEnumerable.Repeat.cs | 6 ------ .../Results/AsValueEnumerable.TestCollection.cs | 6 ------ ...estEnumerableWithInterfacelessPublicEnumerator.cs | 6 ------ ...ValueEnumerable.TestEnumerableWithNoInterfaces.cs | 6 ------ ...thNoInterfacesButEnumeratorWithResetAndDispose.cs | 6 ------ ...able.TestEnumerableWithReferenceTypeEnumerator.cs | 6 ------ ...umerable.TestEnumerableWithValueTypeEnumerator.cs | 6 ------ .../TestData/Results/AsValueEnumerable.TestList.cs | 6 ------ ...ValueEnumerable.TestListWithExplicitInterfaces.cs | 6 ------ .../AsValueEnumerable.TestReadOnlyCollection.cs | 6 ------ .../Results/AsValueEnumerable.TestReadOnlyList.cs | 6 ------ .../Results/AsValueEnumerable.TestValueEnumerable.cs | 6 ------ .../TestData/Results/Count.Array.cs | 6 ------ .../TestData/Results/Count.Span.cs | 6 ------ .../TestData/Results/Select.Array.cs | 6 ------ .../Select.TestEnumerableWithValueTypeEnumerator.cs | 12 ------------ .../TestData/Results/Skip.Take.Array.cs | 12 ------------ .../TestData/Results/Where.Array.cs | 6 ------ NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj | 4 ++-- NetFabric.Hyperlinq/Utils/CodeBuilder.cs | 11 ++++++----- 22 files changed, 8 insertions(+), 139 deletions(-) diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs index 3d9b3be63..1e4cfa4c6 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -38,12 +38,6 @@ static partial class GeneratedExtensionMethods // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); //} - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsEnumerable(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source) => NetFabric.Hyperlinq.ValueEnumerableExtensions.AsEnumerable>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType>(source); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs index 3c797fc8b..1de5fbe6c 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_> AsValueEnumerable(this System.Collections.Generic.IReadOnlyList source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs index 0542b8e23..b734c007a 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable AsValueEnumerable(this NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable source) => source; } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs index 3ba688a87..2af22b81d 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestCollection_TestValueType_> AsValueEnumerable(this TestCollection source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs index c701217ff..b4ea64e49 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithInterfacelessPublicEnumerator source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs index 5d9a02f2a..f1fc298d8 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfaces source) => new(source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs index 5b2664cdf..504975b10 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) => new(source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs index 0f37dc567..883756a3f 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithReferenceTypeEnumerator source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs index 8157ae353..3175f488f 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs index 03212937a..f6bcd4ac3 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestList_TestValueType_> AsValueEnumerable(this TestList source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs index 3c1ec6b62..985f20fd4 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_> AsValueEnumerable(this TestListWithExplicitInterfaces source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs index 83c1c9336..b39936cae 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestReadOnlyCollection_TestValueType_> AsValueEnumerable(this TestReadOnlyCollection source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs index 4875c6a3b..499a5f57a 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestReadOnlyList_TestValueType_> AsValueEnumerable(this TestReadOnlyList source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs index 94f110fde..083a70190 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TestValueEnumerable AsValueEnumerable(this TestValueEnumerable source) => source; } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs index dc87a08ad..d72bdcc0c 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func predicate) => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, predicate); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs index d968d7718..c72d3e402 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.SpanValueEnumerable source, Func predicate) => NetFabric.Hyperlinq.ArrayExtensions.Count(source.Span, predicate); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs index 81acc3241..309fd6768 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueReadOnlyListExtensions.SelectEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper> Select(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Select, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType>(source, selector); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs index 744875c7b..589a306d7 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - //[GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - //[DebuggerNonUserCode] - //[ExcludeFromCodeCoverage] - //[EditorBrowsable(EditorBrowsableState.Never)] - //[Obsolete("This method is not intended to be used directly by user code")] - //[MethodImpl(MethodImplOptions.AggressiveInlining)] //public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) // => new(source, source); @@ -44,12 +38,6 @@ static partial class GeneratedExtensionMethods //} - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueEnumerableExtensions.SelectEnumerable>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType, FunctionWrapper> Select(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source, System.Func selector) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType>(source, selector); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs index 4351753f4..f5ae5f112 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs @@ -14,21 +14,9 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Skip(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Skip, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Take(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) => NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.Take, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs index 6f0f0469b..1fc12462f 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs @@ -14,12 +14,6 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { - [GeneratedCode("NetFabric.Hyperlinq", "0.0.0")] - [DebuggerNonUserCode] - [ExcludeFromCodeCoverage] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.WhereEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper> Where(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Where, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, selector); } diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index fd7fdc48b..0346fa493 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -48,8 +48,8 @@ - - + + all runtime; build; native; contentfiles; analyzers diff --git a/NetFabric.Hyperlinq/Utils/CodeBuilder.cs b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs index e04962173..0f87738f8 100644 --- a/NetFabric.Hyperlinq/Utils/CodeBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs @@ -86,11 +86,12 @@ public void Dispose() } public CodeBuilder AppendGeneratedCodeMethodAttributes() - => AppendLine($"[GeneratedCode(\"{assemblyName}\", \"{(IsUnitTest ? "0.0.0" : assemblyVersion)}\")]") - .AppendLine("[DebuggerNonUserCode]") - .AppendLine("[ExcludeFromCodeCoverage]") - .AppendLine("[EditorBrowsable(EditorBrowsableState.Never)]") - .AppendLine("[Obsolete(\"This method is not intended to be used directly by user code\")]"); + => IsUnitTest + ? this // do nothing + : AppendLine($"[GeneratedCode(\"{assemblyName}\", \"{(IsUnitTest ? "0.0.0" : assemblyVersion)}\")]") + .AppendLine("[DebuggerNonUserCode]") + .AppendLine("[ExcludeFromCodeCoverage]") + .AppendLine("[EditorBrowsable(EditorBrowsableState.Never)]"); public override string ToString() => builder.ToString(); From 013b6e6e6ddd04fa407d4c9e1a0a589d2a58c929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anta=CC=83o=20Almada?= Date: Fri, 24 Sep 2021 08:49:51 +0100 Subject: [PATCH 57/61] Fix build --- .../NetFabric.Hyperlinq.UnitTests.csproj | 2 +- NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs | 2 +- .../Results/Select.TestEnumerableWithValueTypeEnumerator.cs | 4 ++-- NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj index 6e7e4b860..3f237d28f 100644 --- a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj +++ b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj @@ -13,7 +13,7 @@ - + diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs index d72bdcc0c..9baba921e 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs @@ -15,6 +15,6 @@ static partial class GeneratedExtensionMethods { public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func predicate) - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, predicate); + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper>(source, predicate); } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs index 589a306d7..da36201c7 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs @@ -38,7 +38,7 @@ static partial class GeneratedExtensionMethods //} - public static ValueEnumerableExtensions.SelectEnumerable>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType, FunctionWrapper> Select(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source, System.Func selector) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType>(source, selector); + public static ValueEnumerableExtensions.SelectEnumerable>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper> Select(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source, System.Func selector) + => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper>(source, selector); } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs index 1fc12462f..23fd4ccbf 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs @@ -15,6 +15,6 @@ static partial class GeneratedExtensionMethods { public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.WhereEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper> Where(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Where, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, selector); + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Where, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper>(source, selector); } } From 868abd6e45a0f681d0bdb481df51e924124e1490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anta=CC=83o=20Almada?= Date: Wed, 29 Sep 2021 23:38:39 +0100 Subject: [PATCH 58/61] Refactor CodeBuilder --- .../GenerateSourceTests.cs | 7 +++++- .../NetFabric.Hyperlinq.UnitTests.csproj | 1 + .../NetFabric.Hyperlinq.csproj | 2 +- NetFabric.Hyperlinq/Utils/CodeBuilder.cs | 18 ++------------- .../Utils/CodeBuilderExtensions.cs | 22 +++++++++++++++++++ 5 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 NetFabric.Hyperlinq/Utils/CodeBuilderExtensions.cs diff --git a/NetFabric.Hyperlinq.UnitTests/GenerateSourceTests.cs b/NetFabric.Hyperlinq.UnitTests/GenerateSourceTests.cs index 45984f065..5d0ee0543 100644 --- a/NetFabric.Hyperlinq.UnitTests/GenerateSourceTests.cs +++ b/NetFabric.Hyperlinq.UnitTests/GenerateSourceTests.cs @@ -131,13 +131,18 @@ public async Task GenerateSourceShouldGenerate(string[] paths, string expected) .ToList(); // Act - var builder = new CodeBuilder(isUnitTest: true); + var builder = new CodeBuilder { IsUnitTest = true }; Generator.GenerateSource(compilation, typeSymbolsCache, memberAccessExpressions, builder, CancellationToken.None); var result = builder.ToString(); // Assert +#if NET5_0_OR_GREATER + _ = result.Must() + .BeEqualTo(await File.ReadAllTextAsync(expected)); +#else _ = result.Must() .BeEqualTo(File.ReadAllText(expected)); +#endif } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj index 3f237d28f..39ba44d1e 100644 --- a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj +++ b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj @@ -13,6 +13,7 @@ + diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 0346fa493..90454e7e8 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -48,7 +48,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/NetFabric.Hyperlinq/Utils/CodeBuilder.cs b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs index 0f87738f8..6a5980ff6 100644 --- a/NetFabric.Hyperlinq/Utils/CodeBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs @@ -7,18 +7,12 @@ namespace NetFabric.Hyperlinq.SourceGenerator { class CodeBuilder { - static readonly string indentation = " "; - - static readonly string assemblyName = typeof(CodeBuilder).Assembly.GetName().Name; - static readonly string assemblyVersion = typeof(CodeBuilder).Assembly.GetCustomAttribute()?.InformationalVersion ?? string.Empty; + const string indentation = " "; readonly StringBuilder builder = new(); int currentLevel = 0; - public CodeBuilder(bool isUnitTest = false) - => IsUnitTest = isUnitTest; - - public bool IsUnitTest { get; } + public bool IsUnitTest { get; init; } = false; StringBuilder Indent() { @@ -85,14 +79,6 @@ public void Dispose() } } - public CodeBuilder AppendGeneratedCodeMethodAttributes() - => IsUnitTest - ? this // do nothing - : AppendLine($"[GeneratedCode(\"{assemblyName}\", \"{(IsUnitTest ? "0.0.0" : assemblyVersion)}\")]") - .AppendLine("[DebuggerNonUserCode]") - .AppendLine("[ExcludeFromCodeCoverage]") - .AppendLine("[EditorBrowsable(EditorBrowsableState.Never)]"); - public override string ToString() => builder.ToString(); } diff --git a/NetFabric.Hyperlinq/Utils/CodeBuilderExtensions.cs b/NetFabric.Hyperlinq/Utils/CodeBuilderExtensions.cs new file mode 100644 index 000000000..7eb27b89c --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/CodeBuilderExtensions.cs @@ -0,0 +1,22 @@ +using System; +using System.Reflection; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + static class CodeBuilderExtensions + { + static readonly string assemblyName = typeof(CodeBuilder).Assembly + .GetName().Name; + static readonly string assemblyVersion = typeof(CodeBuilder).Assembly + .GetCustomAttribute()?.InformationalVersion + ?? string.Empty; + + public static CodeBuilder AppendGeneratedCodeMethodAttributes(this CodeBuilder builder) + => builder.IsUnitTest + ? builder // do nothing + : builder.AppendLine($"[GeneratedCode(\"{assemblyName}\", \"{assemblyVersion}\")]") + .AppendLine("[DebuggerNonUserCode]") + .AppendLine("[ExcludeFromCodeCoverage]") + .AppendLine("[EditorBrowsable(EditorBrowsableState.Never)]"); + } +} From e02c80f3f4acae195f4b5297187d4aeb8fb85d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anta=CC=83o=20Almada?= Date: Mon, 4 Oct 2021 21:50:58 +0100 Subject: [PATCH 59/61] Fix build --- .github/workflows/dotnetcore.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index f8ebf0884..74c171c6f 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -15,16 +15,16 @@ jobs: dotnet-version: '6.0.x' include-prerelease: true - name: Test source generator - run: dotnet test ./NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj + run: dotnet test ./NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj - name: Build solution run: dotnet build - name: Tests and coverage - run: dotnet test ./NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj -f:net6.0 -p:CollectCoverage=true -p:CoverletOutputFormat=lcov -p:CoverletOutput=TestResults/ + run: dotnet test ./NetFabric.Hyperlinq.Core.UnitTests/NetFabric.Hyperlinq.Core.UnitTests.csproj -f:net6.0 -p:CollectCoverage=true -p:CoverletOutputFormat=lcov -p:CoverletOutput=TestResults/ - name: Publish coverage report to coveralls.io uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./NetFabric.Hyperlinq.UnitTests/TestResults/coverage.net6.0.info + path-to-lcov: ./NetFabric.Hyperlinq.Core.UnitTests/TestResults/coverage.net6.0.info From dc1c0087c0e690abfce416eeafd6a54f8be8c448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anta=CC=83o=20Almada?= Date: Thu, 7 Oct 2021 00:06:46 +0100 Subject: [PATCH 60/61] Refactor CodeBuilder --- .gitattributes | 2 +- Icon.png | Bin 33189 -> 33188 bytes .../AsValueEnumerable.IReadOnlyList.cs | 1 + .../Results/AsValueEnumerable.Repeat.cs | 1 + .../AsValueEnumerable.TestCollection.cs | 1 + ...erableWithInterfacelessPublicEnumerator.cs | 1 + ...umerable.TestEnumerableWithNoInterfaces.cs | 1 + ...erfacesButEnumeratorWithResetAndDispose.cs | 1 + ...stEnumerableWithReferenceTypeEnumerator.cs | 1 + ...e.TestEnumerableWithValueTypeEnumerator.cs | 1 + .../Results/AsValueEnumerable.TestList.cs | 1 + ...umerable.TestListWithExplicitInterfaces.cs | 1 + ...sValueEnumerable.TestReadOnlyCollection.cs | 1 + .../AsValueEnumerable.TestReadOnlyList.cs | 1 + .../AsValueEnumerable.TestValueEnumerable.cs | 1 + .../TestData/Results/Count.Array.cs | 1 + .../TestData/Results/Count.Span.cs | 1 + .../TestData/Results/Select.Array.cs | 1 + ...t.TestEnumerableWithValueTypeEnumerator.cs | 2 + .../TestData/Results/Skip.Take.Array.cs | 2 + .../TestData/Results/Where.Array.cs | 1 + .../Generator.AsValueEnumerable.cs | 631 ++++++++++-------- NetFabric.Hyperlinq/Generator.cs | 48 +- NetFabric.Hyperlinq/Utils/CodeBuilder.cs | 97 ++- .../Utils/CodeBuilderExtensions.cs | 13 +- 25 files changed, 501 insertions(+), 311 deletions(-) diff --git a/.gitattributes b/.gitattributes index 1ff0c4230..b72c2c601 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,7 @@ ############################################################################### # Set default behavior to automatically normalize line endings. ############################################################################### -* text=auto +* text eol=lf ############################################################################### # Set default behavior for command prompt diff. diff --git a/Icon.png b/Icon.png index 278ddc6712e97f9c6facb9bf5b1766865f54b81f..baf66818cf3d8415fa696215a3bae01a818822e8 100644 GIT binary patch delta 15 WcmZ45%(SGLiKR2Z&wV57f<^!=$_1SO delta 16 XcmZ3|%(S$biM2Dp&z*N8%YsG#Fx3UB diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs index 1de5fbe6c..1929432ec 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_> AsValueEnumerable(this System.Collections.Generic.IReadOnlyList source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs index b734c007a..a365ec5c8 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable AsValueEnumerable(this NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable source) => source; } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs index 2af22b81d..83d7baae0 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestCollection_TestValueType_> AsValueEnumerable(this TestCollection source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs index b4ea64e49..558336e44 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithInterfacelessPublicEnumerator source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs index f1fc298d8..44402293e 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfaces source) => new(source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs index 504975b10..08756161f 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) => new(source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs index 883756a3f..272d6366d 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithReferenceTypeEnumerator source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs index 3175f488f..cfd783034 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs index f6bcd4ac3..e4911478e 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestList_TestValueType_> AsValueEnumerable(this TestList source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs index 985f20fd4..be6765b3b 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_> AsValueEnumerable(this TestListWithExplicitInterfaces source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs index b39936cae..3e8a3356f 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestReadOnlyCollection_TestValueType_> AsValueEnumerable(this TestReadOnlyCollection source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs index 499a5f57a..b542189f3 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsValueEnumerable_TestReadOnlyList_TestValueType_> AsValueEnumerable(this TestReadOnlyList source) => new(source, source); diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs index 083a70190..8dca1ed6c 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TestValueEnumerable AsValueEnumerable(this TestValueEnumerable source) => source; } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs index 9baba921e..b29d02dd2 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func predicate) => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper>(source, predicate); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs index c72d3e402..e398ee800 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.SpanValueEnumerable source, Func predicate) => NetFabric.Hyperlinq.ArrayExtensions.Count(source.Span, predicate); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs index 309fd6768..2c0e61834 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueReadOnlyListExtensions.SelectEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper> Select(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Select, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType>(source, selector); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs index da36201c7..4bdc3cdff 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + //[MethodImpl(MethodImplOptions.AggressiveInlining)] //public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) // => new(source, source); @@ -38,6 +39,7 @@ static partial class GeneratedExtensionMethods //} + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ValueEnumerableExtensions.SelectEnumerable>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper> Select(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source, System.Func selector) => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper>(source, selector); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs index f5ae5f112..fc5247cdd 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs @@ -14,9 +14,11 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Skip(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Skip, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Take(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) => NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.Take, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs index 23fd4ccbf..ddc70003c 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs @@ -14,6 +14,7 @@ namespace NetFabric.Hyperlinq static partial class GeneratedExtensionMethods { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.WhereEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper> Where(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Where, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper>(source, selector); } diff --git a/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs b/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs index eac9f7383..8624452ba 100644 --- a/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs @@ -46,11 +46,11 @@ public partial class Generator // Receiver instance returns itself _ = builder - .AppendLine() - .AppendGeneratedCodeMethodAttributes() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public static {valueEnumerableType.Name} AsValueEnumerable(this {valueEnumerableType.Name} source)") - .AppendIndentation().AppendLine($"=> source;"); + .Line() + .GeneratedCodeMethodAttributes() + .AggressiveInliningAttribute() + .Line($"public static {valueEnumerableType.Name} AsValueEnumerable(this {valueEnumerableType.Name} source)") + .Indent().Line($"=> source;"); // A new AsValueEnumerable() method has been generated generatedMethods.Add(methodSignature, valueEnumerableType); @@ -82,27 +82,27 @@ public partial class Generator var getEnumeratorReturnTypeString = getEnumeratorReturnType.ToDisplayString(); // Check what interfaces the enumerable implements, minimizing the calls to ImplementsInterface() - var enumerableImplementsIEnumerable = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IEnumerable_T, out _); - var enumerableImplementsICollection = false; - var enumerableImplementsIReadOnlyCollection = false; - var enumerableImplementsIList = false; - var enumerableImplementsIReadOnlyList = false; - if (enumerableImplementsIEnumerable) + var enumerableIsIEnumerable = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IEnumerable_T, out _); + var enumerableIsICollection = false; + var enumerableIsIReadOnlyCollection = false; + var enumerableIsIList = false; + var enumerableIsIReadOnlyList = false; + if (enumerableIsIEnumerable) { - enumerableImplementsICollection = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_ICollection_T, out _); - if (enumerableImplementsICollection) - enumerableImplementsIList = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IList_T, out _); + enumerableIsICollection = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_ICollection_T, out _); + if (enumerableIsICollection) + enumerableIsIList = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IList_T, out _); - enumerableImplementsIReadOnlyCollection = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IReadOnlyCollection_T, out _); - if (enumerableImplementsIReadOnlyCollection) - enumerableImplementsIReadOnlyList = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IReadOnlyList_T, out _); + enumerableIsIReadOnlyCollection = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IReadOnlyCollection_T, out _); + if (enumerableIsIReadOnlyCollection) + enumerableIsIReadOnlyList = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IReadOnlyList_T, out _); } // Define what value enumerator type will be used - var enumeratorImplementsIEnumerator = getEnumeratorReturnType.ImplementsInterface(SpecialType.System_Collections_Generic_IEnumerator_T, out _); - var useConstraints = enumerableImplementsIEnumerable; + var enumeratorIsIEnumerator = getEnumeratorReturnType.ImplementsInterface(SpecialType.System_Collections_Generic_IEnumerator_T, out _); + var useConstraints = enumerableIsIEnumerable; - var enumeratorTypeString = enumeratorImplementsIEnumerator + var enumeratorTypeString = enumeratorIsIEnumerator ? getEnumeratorReturnType.IsValueType ? getEnumeratorReturnTypeString : $"ValueEnumerator<{itemTypeString}>" @@ -113,17 +113,17 @@ public partial class Generator // Generate the method _ = useConstraints ? builder - .AppendLine() - .AppendGeneratedCodeMethodAttributes() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public static {enumerableTypeString}<{receiverTypeString}> AsValueEnumerable(this {receiverTypeString} source)") - .AppendIndentation().AppendLine($"=> new(source, source);") + .Line() + .GeneratedCodeMethodAttributes() + .AggressiveInliningAttribute() + .Line($"public static {enumerableTypeString}<{receiverTypeString}> AsValueEnumerable(this {receiverTypeString} source)") + .Indent().Line($"=> new(source, source);") : builder - .AppendLine() - .AppendGeneratedCodeMethodAttributes() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public static {enumerableTypeString} AsValueEnumerable(this {receiverTypeString} source)") - .AppendIndentation().AppendLine($"=> new(source);"); + .Line() + .GeneratedCodeMethodAttributes() + .AggressiveInliningAttribute() + .Line($"public static {enumerableTypeString} AsValueEnumerable(this {receiverTypeString} source)") + .Indent().Line($"=> new(source);"); // Generate the value enumerable wrapper string valueEnumerableTypeName; @@ -132,259 +132,58 @@ public partial class Generator : enumerableTypeString; _ = builder - .AppendLine() - .AppendLine($"public readonly struct {valueEnumerableTypeName}"); + .Line() + .Line($"public readonly struct {valueEnumerableTypeName}"); // Define what interfaces the wrapper implements - if (enumerableImplementsIList || enumerableImplementsIReadOnlyList) - _ = builder.AppendIndentation().AppendLine($": IValueReadOnlyList<{itemTypeString}, {enumeratorTypeString}>, IList<{itemTypeString}>"); - else if (enumerableImplementsICollection || enumerableImplementsIReadOnlyCollection) - _ = builder.AppendIndentation().AppendLine($": IValueReadOnlyCollection<{itemTypeString}, {enumeratorTypeString}>, ICollection<{itemTypeString}>"); + if (enumerableIsIList || enumerableIsIReadOnlyList) + _ = builder.Indent().Line($": IValueReadOnlyList<{itemTypeString}, {enumeratorTypeString}>, IList<{itemTypeString}>"); + else if (enumerableIsICollection || enumerableIsIReadOnlyCollection) + _ = builder.Indent().Line($": IValueReadOnlyCollection<{itemTypeString}, {enumeratorTypeString}>, ICollection<{itemTypeString}>"); else - _ = builder.AppendIndentation().AppendLine($": IValueEnumerable<{itemTypeString}, {enumeratorTypeString}>"); + _ = builder.Indent().Line($": IValueEnumerable<{itemTypeString}, {enumeratorTypeString}>"); if (useConstraints) { - if (enumerableImplementsIList) - _ = builder.AppendIndentation().AppendLine($"where TEnumerable : IList"); - else if (enumerableImplementsIReadOnlyList) - _ = builder.AppendIndentation().AppendLine($"where TEnumerable : IReadOnlyList"); - else if (enumerableImplementsICollection) - _ = builder.AppendIndentation().AppendLine($"where TEnumerable : ICollection"); - else if (enumerableImplementsIReadOnlyCollection) - _ = builder.AppendIndentation().AppendLine($"where TEnumerable : IReadOnlyCollection"); - else if (enumerableImplementsIEnumerable) - _ = builder.AppendIndentation().AppendLine($"where TEnumerable : IEnumerable"); + if (enumerableIsIList) + _ = builder.Indent().Line($"where TEnumerable : IList"); + else if (enumerableIsIReadOnlyList) + _ = builder.Indent().Line($"where TEnumerable : IReadOnlyList"); + else if (enumerableIsICollection) + _ = builder.Indent().Line($"where TEnumerable : ICollection"); + else if (enumerableIsIReadOnlyCollection) + _ = builder.Indent().Line($"where TEnumerable : IReadOnlyCollection"); + else if (enumerableIsIEnumerable) + _ = builder.Indent().Line($"where TEnumerable : IEnumerable"); } - using (builder.AppendBlock()) + using (builder.Block()) { // Define fields - _ = builder.AppendLine($"readonly {receiverTypeString} source;"); + _ = builder.Line($"readonly {receiverTypeString} source;"); if (useConstraints) - _ = builder.AppendLine($"readonly TEnumerable source2;"); + _ = builder.Line($"readonly TEnumerable source2;"); // Define constructor _ = useConstraints ? builder - .AppendLine() - .AppendLine($"internal {enumerableTypeString}({receiverTypeString} source, TEnumerable source2)") - .AppendIndentation().AppendLine($"=> (this.source, this.source2) = (source, source2);") + .Line() + .Line($"internal {enumerableTypeString}({receiverTypeString} source, TEnumerable source2)") + .Indent().Line($"=> (this.source, this.source2) = (source, source2);") : builder - .AppendLine() - .AppendLine($"internal {enumerableTypeString}({receiverTypeString} source)") - .AppendIndentation().AppendLine($"=> this.source = source;"); + .Line() + .Line($"internal {enumerableTypeString}({receiverTypeString} source)") + .Indent().Line($"=> this.source = source;"); - // Implement IValueEnumerable<,> - - _ = builder - .AppendLine() - .AppendLine($"// Implement IValueEnumerable<{itemTypeString}, {enumeratorTypeString}>") - .AppendLine(); - - if (enumeratorImplementsIEnumerator) + // Implement interfaces + ImplementIValueEnumerable(builder, enumerableSymbols, enumeratorTypeString, itemTypeString, enumeratorIsIEnumerator); + if (enumerableIsICollection || enumerableIsIReadOnlyCollection) { - if (getEnumeratorReturnType.IsValueType) - { - // No enumerator wrapper required - _ = builder - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public {enumeratorTypeString} GetEnumerator() => source.GetEnumerator();") - .AppendLine() - .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source2.GetEnumerator();") - .AppendLine() - .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator();"); - } - else if (enumerableSymbols.GetEnumerator.ContainingType.IsInterface()) - { - // Use the ValueEnumerator<> enumerator wrapper - _ = builder - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public ValueEnumerator<{itemTypeString}> GetEnumerator() => new(source2.GetEnumerator());") - .AppendLine() - .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source2.GetEnumerator();") - .AppendLine() - .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator();"); - } - else - { - // Use the ValueEnumerator<> enumerator wrapper - _ = builder - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public ValueEnumerator<{itemTypeString}> GetEnumerator() => new(source.GetEnumerator());") - .AppendLine() - .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source2.GetEnumerator();") - .AppendLine() - .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator();"); - } - } - else - { - // A custom enumerator wrapper is required - - _ = builder - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public Enumerator GetEnumerator() => new(source.GetEnumerator());") - .AppendLine() - .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => new Enumerator(source.GetEnumerator());") - .AppendLine() - .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator());") - .AppendLine(); - - using (builder.AppendBlock($"public struct Enumerator : IEnumerator<{itemTypeString}>")) - { - _ = builder - .AppendLine($"readonly {getEnumeratorReturnTypeString} source;") - .AppendLine() - .AppendLine($"internal Enumerator({getEnumeratorReturnTypeString} source)") - .AppendIndentation().AppendLine("=> this.source = source;") - .AppendLine() - .AppendLine($"public {itemTypeString} Current => source.Current;") - .AppendLine() - .AppendLine("object? IEnumerator.Current => source.Current;") - .AppendLine() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine("public bool MoveNext() => source.MoveNext();") - .AppendLine(); - - _ = enumerableSymbols.EnumeratorSymbols.Reset is null - ? builder - .AppendLine("public void Reset() => throw new NotSupportedException();") - : builder - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine("public void Reset() => source.Reset();"); - - _ = enumerableSymbols.EnumeratorSymbols.Dispose is null - ? builder - .AppendLine() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine("public void Dispose() { }") - : builder - .AppendLine() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine("public void Dispose() => source.Dispose();"); - } - } + var isValueType = itemType.IsValueType; + ImplementICollection(builder, itemTypeString, isValueType, enumerableIsICollection); - // Implement ICollection<> - - if (enumerableImplementsICollection || enumerableImplementsIReadOnlyCollection) - { - _ = builder - .AppendLine() - .AppendLine($"// Implement ICollection<{itemTypeString}>") - .AppendLine() - .AppendLine("public int Count => source2.Count;") - .AppendLine() - .AppendLine("public bool IsReadOnly => true;") - .AppendLine() - .AppendLine($"void ICollection<{itemTypeString}>.Add({itemTypeString} item) => throw new NotSupportedException();") - .AppendLine() - .AppendLine($"bool ICollection<{itemTypeString}>.Remove({itemTypeString} item) => throw new NotSupportedException();") - .AppendLine() - .AppendLine($"void ICollection<{itemTypeString}>.Clear() => throw new NotSupportedException();") - .AppendLine(); - - // Add a CopyTo() that takes a Span<> as parameter - using (builder.AppendBlock($"public void CopyTo(Span<{itemTypeString}> span)")) - { - _ = builder - .AppendLine("if (Count is 0) return;") - .AppendLine("if (span.Length < Count) throw new ArgumentException(\"Destination span was not long enough.\", nameof(span));") - .AppendLine(); - - _ = builder.AppendLine("var index = 0;"); - using (builder.AppendBlock("foreach (var current in this)")) - { - _ = builder - .AppendLine("span[index] = current;") - .AppendLine("checked { index++; }"); - } - } - - if (enumerableImplementsICollection) - { - // Call the methods implemented by the source - _ = builder - .AppendLine() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public bool Contains({itemTypeString} item) => source2.Contains(item);") - .AppendLine() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public void CopyTo({itemTypeString}[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex);"); - } - else - { - // The source does not implement these methods so we have to add an implementation - _ = builder.AppendLine(); - - using (builder.AppendBlock($"public bool Contains({itemTypeString} item)")) - { - using (builder.AppendBlock($"foreach (var current in this)")) - { - _ = builder.AppendLine($"if (EqualityComparer<{itemTypeString}>.Default.Equals(current, item)) return true;"); - } - _ = builder.AppendLine("return true;"); - } - - _ = builder - .AppendLine() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public void CopyTo({itemTypeString}[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex));"); - } - - // Implement ICollection<> - - if (enumerableImplementsIList || enumerableImplementsIReadOnlyList) - { - _ = builder - .AppendLine() - .AppendLine($"// Implement IList<{itemTypeString}>") - .AppendLine() - .AppendLine($"public {itemTypeString} this[int index] => source2[index];") - .AppendLine(); - - using (builder.AppendBlock($"{itemTypeString} IList<{itemTypeString}>.this[int index]")) - { - _ = builder - .AppendLine("get => source2[index];") - .AppendLine("set => throw new NotSupportedException();"); - } - - _ = builder - .AppendLine() - .AppendLine($"void IList<{itemTypeString}>.Insert(int index, {itemTypeString} item) => throw new NotSupportedException();") - .AppendLine() - .AppendLine($"void IList<{itemTypeString}>.RemoveAt(int index) => throw new NotSupportedException();") - .AppendLine(); - - if (enumerableImplementsIList) - { - // Call the methods implemented by the source - _ = builder - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public int IndexOf({itemTypeString} item) => source2.IndexOf(item);"); - } - else - { - // The source does not implement these methods so we have to add an implementation - using (builder.AppendBlock($"public int IndexOf({itemTypeString} item)")) - { - using (builder.AppendBlock($"if (Count is not 0)")) - { - _ = builder.AppendLine("var index = 0;"); - using (builder.AppendBlock($"foreach (var current in this)")) - { - _ = builder - .AppendLine($"if (EqualityComparer<{itemTypeString}>.Default.Equals(current, item)) return index;") - .AppendLine() - .AppendLine("checked { index++; }"); - } - } - _ = builder.AppendLine("return -1;"); - } - } - } + if (enumerableIsIList || enumerableIsIReadOnlyList) + ImplementIList(builder, itemTypeString, isValueType, enumerableIsIList); } // A new AsValueEnumerable() method has been generated @@ -392,8 +191,8 @@ public partial class Generator Name: valueEnumerableTypeName, EnumeratorType: enumeratorTypeString, ItemType: itemTypeString, - IsCollection: enumerableImplementsICollection || enumerableImplementsIReadOnlyCollection, - IsList: enumerableImplementsIList || enumerableImplementsIReadOnlyList); + IsCollection: enumerableIsICollection || enumerableIsIReadOnlyCollection, + IsList: enumerableIsIList || enumerableIsIReadOnlyList); generatedMethods.Add(methodSignature, valueEnumerableType); return valueEnumerableType; } @@ -401,5 +200,305 @@ public partial class Generator return null; } + + static void ImplementIValueEnumerable(CodeBuilder builder, EnumerableSymbols enumerableSymbols, string enumeratorTypeString, string itemTypeString, bool enumeratorIsIEnumerator) + { + var getEnumeratorReturnType = enumerableSymbols.GetEnumerator.ReturnType; + var getEnumeratorReturnTypeString = getEnumeratorReturnType.ToDisplayString(); + + _ = builder + .Line() + .Line($"// Implement IValueEnumerable<{itemTypeString}, {enumeratorTypeString}>") + .Line(); + + if (enumeratorIsIEnumerator) + { + if (getEnumeratorReturnType.IsValueType) + { + // No enumerator wrapper required + _ = builder + .AggressiveInliningAttribute() + .Line($"public {enumeratorTypeString} GetEnumerator()") + .Indent().Line($"=> source.GetEnumerator();") + .Line() + .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator()") + .Indent().Line($"=> source2.GetEnumerator();") + .Line() + .Line($"IEnumerator IEnumerable.GetEnumerator()") + .Indent().Line($"=> source2.GetEnumerator();"); + } + else if (enumerableSymbols.GetEnumerator.ContainingType.IsInterface()) + { + // Use the ValueEnumerator<> enumerator wrapper + _ = builder + .AggressiveInliningAttribute() + .Line($"public ValueEnumerator<{itemTypeString}> GetEnumerator()") + .Indent().Line($"=> new(source2.GetEnumerator());") + .Line() + .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator()") + .Indent().Line($"=> source2.GetEnumerator();") + .Line() + .Line($"IEnumerator IEnumerable.GetEnumerator()") + .Indent().Line($"=> source2.GetEnumerator();"); + } + else + { + // Use the ValueEnumerator<> enumerator wrapper + _ = builder + .AggressiveInliningAttribute() + .Line($"public ValueEnumerator<{itemTypeString}> GetEnumerator()") + .Indent().Line($"=> new(source.GetEnumerator());") + .Line() + .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator()") + .Indent().Line($"=> source2.GetEnumerator();") + .Line() + .Line($"IEnumerator IEnumerable.GetEnumerator()") + .Indent().Line($"source2.GetEnumerator();"); + } + } + else + { + // A custom enumerator wrapper is required + + _ = builder + .AggressiveInliningAttribute() + .Line($"public Enumerator GetEnumerator()") + .Indent().Line($"=> new(source.GetEnumerator());") + .Line() + .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator()") + .Indent().Line($"=> new Enumerator(source.GetEnumerator());") + .Line() + .Line($"IEnumerator IEnumerable.GetEnumerator()") + .Indent().Line($"=> new Enumerator(source.GetEnumerator());") + .Line(); + + // define a value type enumerator wrapper + using (builder.Block($"public struct Enumerator : IEnumerator<{itemTypeString}>")) + { + _ = builder + .Line($"readonly {getEnumeratorReturnTypeString} source;") + .Line() + .Line($"internal Enumerator({getEnumeratorReturnTypeString} source)") + .Indent().Line("=> this.source = source;") + .Line() + .Line($"public {itemTypeString} Current") + .Indent().Line($"=> source.Current;") + .Line() + .Line("object? IEnumerator.Current") + .Indent().Line("=> source.Current;") + .Line() + .AggressiveInliningAttribute() + .Line("public bool MoveNext()") + .Indent().Line("=> source.MoveNext();") + .Line(); + + _ = enumerableSymbols.EnumeratorSymbols.Reset is null + ? builder + .Line("public void Reset()") + .Indent().Line("=> throw new NotSupportedException();") + : builder + .AggressiveInliningAttribute() + .Line("public void Reset()") + .Indent().Line("=> source.Reset();"); + + _ = enumerableSymbols.EnumeratorSymbols.Dispose is null + ? builder + .Line() + .AggressiveInliningAttribute() + .Line("public void Dispose() { }") + : builder + .Line() + .AggressiveInliningAttribute() + .Line("public void Dispose()") + .Indent().Line("=> source.Dispose();"); + } + } + } + + static void ImplementICollection(CodeBuilder builder, string itemTypeString, bool itemTypeIsValueType, bool sourceIsICollection) + { + _ = builder + .Line() + .Line($"// Implement ICollection<{itemTypeString}>") + .Line() + .Line("public int Count => source2.Count;") + .Line() + .Line("public bool IsReadOnly => true;") + .Line() + .Line($"void ICollection<{itemTypeString}>.Add({itemTypeString} item) => throw new NotSupportedException();") + .Line() + .Line($"bool ICollection<{itemTypeString}>.Remove({itemTypeString} item) => throw new NotSupportedException();") + .Line() + .Line($"void ICollection<{itemTypeString}>.Clear() => throw new NotSupportedException();") + .Line(); + + if (sourceIsICollection) + { + // Call the methods implemented by the source + _ = builder + .Line() + .AggressiveInliningAttribute() + .Line($"public bool Contains({itemTypeString} item) => source2.Contains(item);") + .Line() + .AggressiveInliningAttribute() + .Line($"public void CopyTo({itemTypeString}[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex);"); + + return; // nothing else to do + } + + // The source does not implement these methods so we have to add an implementation + _ = builder + .Line() + .MethodBlock($"public bool Contains({itemTypeString}[] value)", + codeBuilder => codeBuilder + .Line("if (Count is 0)") + .Indent().Line("return;") + .Line() + .IfBlock("source is ICollection<{itemTypeString}> collection", + codeBuilder => codeBuilder + .Line("collection.Contains(values);"), + codeBuilder => + { + codeBuilder + .Line("using var enumerator = GetEnumerator();"); + + if (itemTypeIsValueType) // devirtualize the comparer + { + codeBuilder + .WhileBlock("enumerator.MoveNext()", + codeBuilder => codeBuilder + .Line("if (EqualityComparer<{itemTypeString}>.Default.Equals(enumerator.Current, value))") + .Indent().Line("return true;") + ) + .Line("return true;"); + } + else + { + codeBuilder + .Line($"var comparer = EqualityComparer<{itemTypeString}>.Default;") + .WhileBlock("enumerator.MoveNext()", + codeBuilder => codeBuilder + .Line("if (comparer.Equals(enumerator.Current, value))") + .Indent().Line("return true;") + ) + .Line("return true;"); + } + }) + ); + + _ = builder + .Line() + .MethodBlock($"public void CopyTo({itemTypeString}[] array, int arrayIndex)", + codeBuilder => codeBuilder + .Line("if (Count is 0)") + .Indent().Line("return;") + .Line() + .Line("if (array.Length - arrayIndex < Count)") + .Indent().Line("Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array));") + .Line() + .IfBlock("source is ICollection<{itemTypeString}> collection", + codeBuilder => codeBuilder + .Line("collection.CopyTo(array, arrayIndex);"), + codeBuilder => codeBuilder + .Line("using var enumerator = GetEnumerator();") + .IfBlock( + "arrayIndex is 0 && array.Length == Count", // to enable range check elimination + codeBuilder => codeBuilder + .ForBlock("var index = 0; index < array.Length; index++", + codeBuilder => codeBuilder + .Line("_ = enumerator.MoveNext();") + .Line("array[index] = enumerator.Current;") + ), + codeBuilder => codeBuilder + .CheckedBlock( + codeBuilder => codeBuilder + .Line("for (var index = arrayIndex; enumerator.MoveNext(); index++)") + .Indent().Line("array[index] = enumerator.Current;") + ) + ) + ) + ); + } + + static void ImplementIList(CodeBuilder builder, string itemTypeString, bool itemTypeIsValueType, bool sourceIsIList) + { + _ = builder + .Line() + .Line($"// Implement IList<{itemTypeString}>") + .Line() + .Line($"public {itemTypeString} this[int index] => source2[index];") + .Line(); + + using (builder.Block($"{itemTypeString} IList<{itemTypeString}>.this[int index]")) + { + _ = builder + .Line("get => source2[index];") + .Line("set => throw new NotSupportedException();"); + } + + _ = builder + .Line() + .Line($"void IList<{itemTypeString}>.Insert(int index, {itemTypeString} item) => throw new NotSupportedException();") + .Line() + .Line($"void IList<{itemTypeString}>.RemoveAt(int index) => throw new NotSupportedException();") + .Line(); + + if (sourceIsIList) + { + // Call the methods implemented by the source + _ = builder + .AggressiveInliningAttribute() + .Line($"public int IndexOf({itemTypeString} item) => source2.IndexOf(item);"); + + return; + } + + // The source does not implement these methods so we have to add an implementation + builder + .MethodBlock($"public int IndexOf({itemTypeString} item)", + codeBuilder => codeBuilder + .IfBlock("if (Count is not 0)", + codeBuilder => codeBuilder + .IfBlock("source is IList<{itemTypeString}> list", + codeBuilder => codeBuilder + .Line("return list.IndexOf(item);"), + codeBuilder => + { + codeBuilder + .CheckedBlock(codeBuilder => + { + codeBuilder + .Line("var index = 0;"); + + if (itemTypeIsValueType) // devirtualize the comparer + { + codeBuilder + .ForEachBlock("var current in source2", + codeBuilder => codeBuilder + .Line($"if (EqualityComparer<{itemTypeString}>.Default.Equals(current, item))") + .Indent().Line("return index;") + .Line() + .Line("checked { index++; }") + ); + } + else + { + codeBuilder + .Line($"var comparer = EqualityComparer<{itemTypeString}>.Default;") + .ForEachBlock("var current in source2", + codeBuilder => codeBuilder + .Line($"if (comparer.Equals(current, item))") + .Indent().Line("return index;") + .Line() + .Line("checked { index++; }") + ); + } + }); + }) + ) + .Line("return -1;") + ); + } + } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Generator.cs b/NetFabric.Hyperlinq/Generator.cs index 597b81e64..0a636e725 100644 --- a/NetFabric.Hyperlinq/Generator.cs +++ b/NetFabric.Hyperlinq/Generator.cs @@ -153,20 +153,20 @@ internal static void GenerateSource(Compilation compilation, TypeSymbolsCache ty var generatedMethods = new Dictionary(); _ = builder - .AppendLine("#nullable enable") - .AppendLine() - .AppendLine("using System;") - .AppendLine("using System.CodeDom.Compiler;") - .AppendLine("using System.Collections;") - .AppendLine("using System.Collections.Generic;") - .AppendLine("using System.ComponentModel;") - .AppendLine("using System.Diagnostics;") - .AppendLine("using System.Diagnostics.CodeAnalysis;") - .AppendLine("using System.Runtime.CompilerServices;") - .AppendLine(); - - using (builder.AppendBlock("namespace NetFabric.Hyperlinq")) - using (builder.AppendBlock("static partial class GeneratedExtensionMethods")) + .Line("#nullable enable") + .Line() + .Line("using System;") + .Line("using System.CodeDom.Compiler;") + .Line("using System.Collections;") + .Line("using System.Collections.Generic;") + .Line("using System.ComponentModel;") + .Line("using System.Diagnostics;") + .Line("using System.Diagnostics.CodeAnalysis;") + .Line("using System.Runtime.CompilerServices;") + .Line(); + + using (builder.Block("namespace NetFabric.Hyperlinq")) + using (builder.Block("static partial class GeneratedExtensionMethods")) { foreach (var expressionSyntax in memberAccessExpressions) { @@ -271,12 +271,12 @@ internal static void GenerateSource(Compilation compilation, TypeSymbolsCache ty ? $"{hyperlinqMethod.ReturnType.ContainingType}.{hyperlinqMethod.ReturnType.Name}<{typeArgumentsString}>" : hyperlinqMethod.ReturnType.ToDisplayString(); _ = builder - .AppendLine() - .AppendGeneratedCodeMethodAttributes() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public static {returnTypeString} {methodSymbol.Name}(this {parametersString})") - .AppendIndentation() - .AppendLine($"=> {containingClassString}.{methodSymbol.Name}<{typeArgumentsString}>({argumentsString});"); + .Line() + .GeneratedCodeMethodAttributes() + .Line("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .Line($"public static {returnTypeString} {methodSymbol.Name}(this {parametersString})") + .Indent() + .Line($"=> {containingClassString}.{methodSymbol.Name}<{typeArgumentsString}>({argumentsString});"); } // The method is not yet defined @@ -301,10 +301,10 @@ internal static void GenerateSource(Compilation compilation, TypeSymbolsCache ty // new string[] { "source" } // .Concat(methodSymbol.Parameters.Select(parameter => parameter.Name))); //_ = builder - // .AppendLine() - // .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - // .AppendLine($"public static {hyperlinqMethod.ReturnType.ToDisplayString()} {methodSymbol.Name}(this {parametersString})") - // .AppendIndentation().AppendLine($"=> {containingClassString}.{methodSymbol.Name}<{receiverType.Name}, {receiverType.EnumeratorType}, {receiverType.ItemType}>({argumentsString});"); + // .Line() + // .Line("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + // .Line($"public static {hyperlinqMethod.ReturnType.ToDisplayString()} {methodSymbol.Name}(this {parametersString})") + // .Indent().Line($"=> {containingClassString}.{methodSymbol.Name}<{receiverType.Name}, {receiverType.EnumeratorType}, {receiverType.ItemType}>({argumentsString});"); //generatedMethods.Add(methodSignature, returnType); //return returnType; diff --git a/NetFabric.Hyperlinq/Utils/CodeBuilder.cs b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs index 6a5980ff6..7d4074a89 100644 --- a/NetFabric.Hyperlinq/Utils/CodeBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs @@ -14,7 +14,7 @@ class CodeBuilder public bool IsUnitTest { get; init; } = false; - StringBuilder Indent() + StringBuilder AppendIndents() { for (var level = 0; level < currentLevel; level++) _ = builder.Append(indentation); @@ -22,48 +22,115 @@ StringBuilder Indent() return builder; } - public CodeBuilder AppendIndentation() + public CodeBuilder Indent() { _ = builder.Append(indentation); return this; } - public CodeBuilder AppendLine() + public CodeBuilder Line() { _ = builder.AppendLine(); return this; } - public CodeBuilder AppendLine(char text) + public CodeBuilder Line(char text) { - _ = Indent().Append(text).AppendLine(); + _ = AppendIndents().Append(text).AppendLine(); return this; } - public CodeBuilder AppendLine(string text) + public CodeBuilder Line(string text) { - _ = Indent().AppendLine(text); + _ = AppendIndents().AppendLine(text); return this; } - public CodeBuilder AppendLine(Action line) + public CodeBuilder Line(Action line) { - _ = Indent(); + _ = AppendIndents(); line(builder); - _ = AppendLine(); + _ = Line(); return this; } - public IDisposable AppendBlock() + public IDisposable Block() { - _ = AppendLine('{'); + _ = Line('{'); currentLevel++; // ReSharper disable once HeapView.ObjectAllocation.Evident return new CloseBlock(this); } - public IDisposable AppendBlock(string text) - => AppendLine(text).AppendBlock(); + public IDisposable Block(string text) + => Line(text).Block(); + + public CodeBuilder MethodBlock(string header, Action block) + { + using (Block(header)) + { + block(this); + } + return this; + } + + public CodeBuilder IfBlock(string condition, Action block) + { + using (Block($"if ({condition})")) + { + block(this); + } + return this; + } + + public CodeBuilder IfBlock(string condition, Action trueBlock, Action falseBlock) + { + using (Block($"if ({condition}))")) + { + trueBlock(this); + } + using (Block("else")) + { + falseBlock(this); + } + return this; + } + + public CodeBuilder ForEachBlock(string text, Action block) + { + using (Block($"foreach ({text})")) + { + block(this); + } + return this; + } + + public CodeBuilder ForBlock(string text, Action block) + { + using (Block($"for ({text})")) + { + block(this); + } + return this; + } + + public CodeBuilder WhileBlock(string text, Action block) + { + using (Block($"while ({text})")) + { + block(this); + } + return this; + } + + public CodeBuilder CheckedBlock(Action block) + { + using (Block("checked")) + { + block(this); + } + return this; + } class CloseBlock : IDisposable { @@ -75,7 +142,7 @@ public CloseBlock(CodeBuilder builder) public void Dispose() { builder.currentLevel--; - _ = builder.AppendLine('}'); + _ = builder.Line('}'); } } diff --git a/NetFabric.Hyperlinq/Utils/CodeBuilderExtensions.cs b/NetFabric.Hyperlinq/Utils/CodeBuilderExtensions.cs index 7eb27b89c..8c9725da7 100644 --- a/NetFabric.Hyperlinq/Utils/CodeBuilderExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/CodeBuilderExtensions.cs @@ -11,12 +11,15 @@ static class CodeBuilderExtensions .GetCustomAttribute()?.InformationalVersion ?? string.Empty; - public static CodeBuilder AppendGeneratedCodeMethodAttributes(this CodeBuilder builder) + public static CodeBuilder GeneratedCodeMethodAttributes(this CodeBuilder builder) => builder.IsUnitTest ? builder // do nothing - : builder.AppendLine($"[GeneratedCode(\"{assemblyName}\", \"{assemblyVersion}\")]") - .AppendLine("[DebuggerNonUserCode]") - .AppendLine("[ExcludeFromCodeCoverage]") - .AppendLine("[EditorBrowsable(EditorBrowsableState.Never)]"); + : builder.Line($"[GeneratedCode(\"{assemblyName}\", \"{assemblyVersion}\")]") + .Line("[DebuggerNonUserCode]") + .Line("[ExcludeFromCodeCoverage]") + .Line("[EditorBrowsable(EditorBrowsableState.Never)]"); + + public static CodeBuilder AggressiveInliningAttribute(this CodeBuilder builder) + => builder.Line("[MethodImpl(MethodImplOptions.AggressiveInlining)]"); } } From 60a345613ce6f51da72130d11ad42995ead1bda7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anta=CC=83o=20Almada?= Date: Fri, 8 Oct 2021 23:22:44 +0100 Subject: [PATCH 61/61] Fix code generation --- .editorconfig | 7 +- .../NetFabric.Hyperlinq.Benchmarks.csproj | 10 +- NetFabric.Hyperlinq.Core/Resource.resx | 2 +- ...e.TestEnumerableWithValueTypeEnumerator.cs | 45 ++- .../AsValueEnumerable.IReadOnlyList.cs | 136 ++++--- .../Results/AsValueEnumerable.Repeat.cs | 13 +- .../AsValueEnumerable.TestCollection.cs | 70 ++-- ...erableWithInterfacelessPublicEnumerator.cs | 65 ++-- ...umerable.TestEnumerableWithNoInterfaces.cs | 63 ++-- ...erfacesButEnumeratorWithResetAndDispose.cs | 65 ++-- ...stEnumerableWithReferenceTypeEnumerator.cs | 37 +- ...e.TestEnumerableWithValueTypeEnumerator.cs | 37 +- .../Results/AsValueEnumerable.TestList.cs | 92 ++--- ...umerable.TestListWithExplicitInterfaces.cs | 100 +++-- ...sValueEnumerable.TestReadOnlyCollection.cs | 92 ++--- .../AsValueEnumerable.TestReadOnlyList.cs | 126 ++++--- .../AsValueEnumerable.TestValueEnumerable.cs | 13 +- .../TestData/Results/Count.Array.cs | 13 +- .../TestData/Results/Count.Span.cs | 13 +- .../TestData/Results/Empty.cs | 7 +- .../TestData/Results/Select.Array.cs | 13 +- ...t.TestEnumerableWithValueTypeEnumerator.cs | 47 ++- .../TestData/Results/Skip.Take.Array.cs | 19 +- .../TestData/Results/Where.Array.cs | 13 +- .../Generator.AsValueEnumerable.cs | 346 ++++++++---------- NetFabric.Hyperlinq/Generator.cs | 3 +- .../NetFabric.Hyperlinq.csproj | 15 + NetFabric.Hyperlinq/Resource.Designer.cs | 54 +++ NetFabric.Hyperlinq/Resource.resx | 24 ++ NetFabric.Hyperlinq/Utils/CodeBuilder.cs | 2 +- 30 files changed, 800 insertions(+), 742 deletions(-) create mode 100644 NetFabric.Hyperlinq/Resource.Designer.cs create mode 100644 NetFabric.Hyperlinq/Resource.resx diff --git a/.editorconfig b/.editorconfig index b4a841bef..57d0ce66a 100755 --- a/.editorconfig +++ b/.editorconfig @@ -12,7 +12,7 @@ indent_style = space tab_width = 4 # New line preferences -end_of_line = crlf +# end_of_line = crlf insert_final_newline = false #### .NET Coding Conventions #### @@ -58,7 +58,7 @@ dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error dotnet_style_readonly_field = true:error # Parameter preferences -dotnet_code_quality_unused_parameters = all:error +dotnet_code_quality_unused_parameters = all:warning #### C# Coding Conventions #### @@ -216,6 +216,3 @@ dotnet_naming_style.camel_case.required_prefix = dotnet_naming_style.camel_case.required_suffix = dotnet_naming_style.camel_case.word_separator = dotnet_naming_style.camel_case.capitalization = camel_case - -[*.{cs,vb}] -dotnet_code_quality_unused_parameters=all:warning \ No newline at end of file diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index cc4e2de24..88176afb2 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -3,14 +3,8 @@ Exe net6.0 false - true - true - - - - AnyCPU - pdbonly - true + Release + false diff --git a/NetFabric.Hyperlinq.Core/Resource.resx b/NetFabric.Hyperlinq.Core/Resource.resx index 260aed1d5..05b1efb3f 100644 --- a/NetFabric.Hyperlinq.Core/Resource.resx +++ b/NetFabric.Hyperlinq.Core/Resource.resx @@ -121,7 +121,7 @@ The array in the ArraySegment is null - Destination array was not long enough. Check the destination index, length, and the rentedArray's lower bounds. + Destination array was not long enough. Check the destination index, length, and the array's lower bounds. Sequence contains no elements diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs index 1e4cfa4c6..c5d1c5ad6 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -9,36 +9,35 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) - // => new(source, source); + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) + // => new(source, source); - //public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ - // : IValueEnumerable.Enumerator> - // where TEnumerable : IEnumerable - //{ - // readonly TestEnumerableWithValueTypeEnumerator source; - // readonly TEnumerable source2; + //public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ + // : IValueEnumerable.Enumerator> + // where TEnumerable : IEnumerable + //{ + // readonly TestEnumerableWithValueTypeEnumerator source; + // readonly TEnumerable source2; - // internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) - // => (this.source, this.source2) = (source, source2); + // internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) + // => (this.source, this.source2) = (source, source2); - // // Implement IValueEnumerable.Enumerator> + // // Implement IValueEnumerable.Enumerator> - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); - // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); - // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); - //} + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + //} - public static GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsEnumerable(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.AsEnumerable>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType>(source); - } + public static GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ AsEnumerable(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ source) + => NetFabric.Hyperlinq.ValueEnumerableExtensions.AsEnumerable.Enumerator, TestValueType>(source); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs index 1929432ec..fc53886f4 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs @@ -9,99 +9,125 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_ AsValueEnumerable(this System.Collections.Generic.IReadOnlyList source) + => new(source); + + public readonly struct AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_ + : IValueReadOnlyList>, IList { + readonly System.Collections.Generic.IReadOnlyList source; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_> AsValueEnumerable(this System.Collections.Generic.IReadOnlyList source) - => new(source, source); + internal AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_(System.Collections.Generic.IReadOnlyList source) + => this.source = source; - public readonly struct AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_ - : IValueReadOnlyList>, IList - where TEnumerable : IReadOnlyList - { - readonly System.Collections.Generic.IReadOnlyList source; - readonly TEnumerable source2; + // Implement IValueEnumerable> - internal AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_(System.Collections.Generic.IReadOnlyList source, TEnumerable source2) - => (this.source, this.source2) = (source, source2); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() => new(source.GetEnumerator()); - // Implement IValueEnumerable> + IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator GetEnumerator() => new(source2.GetEnumerator()); + IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + // Implement ICollection - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + public int Count => source.Count; - // Implement ICollection + public bool IsReadOnly => true; - public int Count => source2.Count; + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); - public bool IsReadOnly => true; + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); - void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + void ICollection.Clear() => throw new NotSupportedException(); - bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + public bool Contains(TestValueType item) + { + if (Count is 0) + return false; - void ICollection.Clear() => throw new NotSupportedException(); + if (source is ICollection collection) + return collection.Contains(item); - public void CopyTo(Span span) + using var enumerator = GetEnumerator(); + while (enumerator.MoveNext()) { - if (Count is 0) return; - if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + if (EqualityComparer.Default.Equals(enumerator.Current, item)) + return true; + } + return false; + } - var index = 0; - foreach (var current in this) - { - span[index] = current; - checked { index++; } - } + public void CopyTo(TestValueType[] array, int arrayIndex) + { + if (Count is 0) + return; + + if (array.Length - arrayIndex < Count) + throw new ArgumentException("Destination array was not long enough. Check the destination index, length, and the array's lower bounds.", nameof(array)); + + if (source is ICollection collection) + { + collection.CopyTo(array, arrayIndex); + return; } - public bool Contains(TestValueType item) + using var enumerator = GetEnumerator(); + if (arrayIndex is 0 && array.Length == Count) + { + for (var index = 0; index < array.Length && enumerator.MoveNext(); index++) + array[index] = enumerator.Current; + } + else { - foreach (var current in this) + checked { - if (EqualityComparer.Default.Equals(current, item)) return true; + for (var index = arrayIndex; enumerator.MoveNext(); index++) + array[index] = enumerator.Current; } - return true; } + } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TestValueType[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex)); - - // Implement IList + // Implement IList - public TestValueType this[int index] => source2[index]; + public TestValueType this[int index] => source[index]; - TestValueType IList.this[int index] - { - get => source2[index]; - set => throw new NotSupportedException(); - } + TestValueType IList.this[int index] + { + get => source[index]; + set => throw new NotSupportedException(); + } - void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); - void IList.RemoveAt(int index) => throw new NotSupportedException(); + void IList.RemoveAt(int index) => throw new NotSupportedException(); - public int IndexOf(TestValueType item) + public int IndexOf(TestValueType item) + { + if (Count is not 0) { - if (Count is not 0) + if (source is IList list) + return list.IndexOf(item); + + checked { var index = 0; - foreach (var current in this) + foreach (var current in source) { - if (EqualityComparer.Default.Equals(current, item)) return index; + if (EqualityComparer.Default.Equals(current, item)) + return index; - checked { index++; } + index++; } } - return -1; } + return -1; } } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs index a365ec5c8..0c28f1d9f 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs @@ -9,13 +9,12 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable AsValueEnumerable(this NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable source) - => source; - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable AsValueEnumerable(this NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable source) + => source; } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs index 83d7baae0..b7dd4b562 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs @@ -9,64 +9,48 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq -{ - static partial class GeneratedExtensionMethods - { +namespace NetFabric.Hyperlinq; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestCollection_TestValueType_> AsValueEnumerable(this TestCollection source) - => new(source, source); - - public readonly struct AsValueEnumerable_TestCollection_TestValueType_ - : IValueReadOnlyCollection.Enumerator>, ICollection - where TEnumerable : ICollection - { - readonly TestCollection source; - readonly TEnumerable source2; +static partial class GeneratedExtensionMethods +{ - internal AsValueEnumerable_TestCollection_TestValueType_(TestCollection source, TEnumerable source2) - => (this.source, this.source2) = (source, source2); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestCollection_TestValueType_ AsValueEnumerable(this TestCollection source) + => new(source); - // Implement IValueEnumerable.Enumerator> + public readonly struct AsValueEnumerable_TestCollection_TestValueType_ + : IValueReadOnlyCollection.Enumerator>, ICollection + { + readonly TestCollection source; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TestCollection.Enumerator GetEnumerator() => source.GetEnumerator(); + internal AsValueEnumerable_TestCollection_TestValueType_(TestCollection source) + => this.source = source; - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + // Implement IValueEnumerable.Enumerator> - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestCollection.Enumerator GetEnumerator() => source.GetEnumerator(); - // Implement ICollection + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public int Count => source2.Count; + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public bool IsReadOnly => true; + // Implement ICollection - void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + public int Count => source.Count; - bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + public bool IsReadOnly => true; - void ICollection.Clear() => throw new NotSupportedException(); + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); - public void CopyTo(Span span) - { - if (Count is 0) return; - if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); - var index = 0; - foreach (var current in this) - { - span[index] = current; - checked { index++; } - } - } + void ICollection.Clear() => throw new NotSupportedException(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TestValueType item) => source2.Contains(item); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TestValueType item) => source.Contains(item); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TestValueType[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => source.CopyTo(array, arrayIndex); } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs index 558336e44..8b7764809 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs @@ -9,53 +9,54 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithInterfacelessPublicEnumerator source) - => new(source, source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_ AsValueEnumerable(this TestEnumerableWithInterfacelessPublicEnumerator source) + => new(source); - public readonly struct AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_ - : IValueEnumerable.Enumerator> - where TEnumerable : IEnumerable - { - readonly TestEnumerableWithInterfacelessPublicEnumerator source; - readonly TEnumerable source2; + public readonly struct AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_ + : IValueEnumerable + { + readonly TestEnumerableWithInterfacelessPublicEnumerator source; - internal AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_(TestEnumerableWithInterfacelessPublicEnumerator source, TEnumerable source2) - => (this.source, this.source2) = (source, source2); + internal AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_(TestEnumerableWithInterfacelessPublicEnumerator source) + => this.source = source; - // Implement IValueEnumerable.Enumerator> + // Implement IValueEnumerable - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() => new(source.GetEnumerator()); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public struct Enumerator : IEnumerator - { - readonly TestEnumerableWithInterfacelessPublicEnumerator.Enumerator source; + public struct Enumerator : IEnumerator + { + readonly TestEnumerableWithInterfacelessPublicEnumerator.Enumerator source; - internal Enumerator(TestEnumerableWithInterfacelessPublicEnumerator.Enumerator source) - => this.source = source; + internal Enumerator(TestEnumerableWithInterfacelessPublicEnumerator.Enumerator source) + => this.source = source; - public TestValueType Current => source.Current; + public TestValueType Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source.Current; + } - object? IEnumerator.Current => source.Current; + object? IEnumerator.Current => source.Current; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() => source.MoveNext(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() => source.MoveNext(); - public void Reset() => throw new NotSupportedException(); + public void Reset() => throw new NotSupportedException(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Dispose() { } - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() { } } } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs index 44402293e..ac52dc301 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs @@ -9,51 +9,54 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfaces source) - => new(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfaces source) + => new(source); - public readonly struct AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ - : IValueEnumerable - { - readonly TestEnumerableWithNoInterfaces source; + public readonly struct AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ + : IValueEnumerable + { + readonly TestEnumerableWithNoInterfaces source; - internal AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_(TestEnumerableWithNoInterfaces source) - => this.source = source; + internal AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_(TestEnumerableWithNoInterfaces source) + => this.source = source; - // Implement IValueEnumerable + // Implement IValueEnumerable - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() => new(source.GetEnumerator()); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public struct Enumerator : IEnumerator - { - readonly TestEnumerableWithNoInterfaces.Enumerator source; + public struct Enumerator : IEnumerator + { + readonly TestEnumerableWithNoInterfaces.Enumerator source; - internal Enumerator(TestEnumerableWithNoInterfaces.Enumerator source) - => this.source = source; + internal Enumerator(TestEnumerableWithNoInterfaces.Enumerator source) + => this.source = source; - public TestValueType Current => source.Current; + public TestValueType Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source.Current; + } - object? IEnumerator.Current => source.Current; + object? IEnumerator.Current => source.Current; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() => source.MoveNext(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() => source.MoveNext(); - public void Reset() => throw new NotSupportedException(); + public void Reset() => throw new NotSupportedException(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Dispose() { } - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() { } } } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs index 08756161f..13eca99d5 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs @@ -9,52 +9,55 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) - => new(source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) + => new(source); - public readonly struct AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ - : IValueEnumerable - { - readonly TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source; + public readonly struct AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ + : IValueEnumerable + { + readonly TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source; - internal AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_(TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) - => this.source = source; + internal AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_(TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) + => this.source = source; - // Implement IValueEnumerable + // Implement IValueEnumerable - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() => new(source.GetEnumerator()); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public struct Enumerator : IEnumerator - { - readonly TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.Enumerator source; + public struct Enumerator : IEnumerator + { + readonly TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.Enumerator source; - internal Enumerator(TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.Enumerator source) - => this.source = source; + internal Enumerator(TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.Enumerator source) + => this.source = source; - public TestValueType Current => source.Current; + public TestValueType Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source.Current; + } - object? IEnumerator.Current => source.Current; + object? IEnumerator.Current => source.Current; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() => source.MoveNext(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() => source.MoveNext(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Reset() => source.Reset(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Reset() => source.Reset(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Dispose() => source.Dispose(); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() => source.Dispose(); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs index 272d6366d..407d1fa67 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs @@ -9,33 +9,30 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithReferenceTypeEnumerator source) - => new(source, source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_ AsValueEnumerable(this TestEnumerableWithReferenceTypeEnumerator source) + => new(source); - public readonly struct AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_ - : IValueEnumerable> - where TEnumerable : IEnumerable - { - readonly TestEnumerableWithReferenceTypeEnumerator source; - readonly TEnumerable source2; + public readonly struct AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_ + : IValueEnumerable> + { + readonly TestEnumerableWithReferenceTypeEnumerator source; - internal AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_(TestEnumerableWithReferenceTypeEnumerator source, TEnumerable source2) - => (this.source, this.source2) = (source, source2); + internal AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_(TestEnumerableWithReferenceTypeEnumerator source) + => this.source = source; - // Implement IValueEnumerable> + // Implement IValueEnumerable> - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator GetEnumerator() => new(source.GetEnumerator()); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs index cfd783034..2e787b696 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -9,33 +9,30 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) - => new(source, source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) + => new(source); - public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ - : IValueEnumerable.Enumerator> - where TEnumerable : IEnumerable - { - readonly TestEnumerableWithValueTypeEnumerator source; - readonly TEnumerable source2; + public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ + : IValueEnumerable.Enumerator> + { + readonly TestEnumerableWithValueTypeEnumerator source; - internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) - => (this.source, this.source2) = (source, source2); + internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source) + => this.source = source; - // Implement IValueEnumerable.Enumerator> + // Implement IValueEnumerable.Enumerator> - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs index e4911478e..fcbae6d1f 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs @@ -9,81 +9,65 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq -{ - static partial class GeneratedExtensionMethods - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestList_TestValueType_> AsValueEnumerable(this TestList source) - => new(source, source); +namespace NetFabric.Hyperlinq; - public readonly struct AsValueEnumerable_TestList_TestValueType_ - : IValueReadOnlyList.Enumerator>, IList - where TEnumerable : IList - { - readonly TestList source; - readonly TEnumerable source2; +static partial class GeneratedExtensionMethods +{ - internal AsValueEnumerable_TestList_TestValueType_(TestList source, TEnumerable source2) - => (this.source, this.source2) = (source, source2); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestList_TestValueType_ AsValueEnumerable(this TestList source) + => new(source); - // Implement IValueEnumerable.Enumerator> + public readonly struct AsValueEnumerable_TestList_TestValueType_ + : IValueReadOnlyList.Enumerator>, IList + { + readonly TestList source; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TestList.Enumerator GetEnumerator() => source.GetEnumerator(); + internal AsValueEnumerable_TestList_TestValueType_(TestList source) + => this.source = source; - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + // Implement IValueEnumerable.Enumerator> - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestList.Enumerator GetEnumerator() => source.GetEnumerator(); - // Implement ICollection + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public int Count => source2.Count; + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public bool IsReadOnly => true; + // Implement ICollection - void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + public int Count => source.Count; - bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + public bool IsReadOnly => true; - void ICollection.Clear() => throw new NotSupportedException(); + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); - public void CopyTo(Span span) - { - if (Count is 0) return; - if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); - var index = 0; - foreach (var current in this) - { - span[index] = current; - checked { index++; } - } - } + void ICollection.Clear() => throw new NotSupportedException(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TestValueType item) => source2.Contains(item); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TestValueType item) => source.Contains(item); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TestValueType[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => source.CopyTo(array, arrayIndex); - // Implement IList + // Implement IList - public TestValueType this[int index] => source2[index]; + public TestValueType this[int index] => source[index]; - TestValueType IList.this[int index] - { - get => source2[index]; - set => throw new NotSupportedException(); - } + TestValueType IList.this[int index] + { + get => source[index]; + set => throw new NotSupportedException(); + } - void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); - void IList.RemoveAt(int index) => throw new NotSupportedException(); + void IList.RemoveAt(int index) => throw new NotSupportedException(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int IndexOf(TestValueType item) => source2.IndexOf(item); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int IndexOf(TestValueType item) => source.IndexOf(item); } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs index be6765b3b..c1a97176e 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs @@ -9,81 +9,79 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_> AsValueEnumerable(this TestListWithExplicitInterfaces source) - => new(source, source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_> AsValueEnumerable(this TestListWithExplicitInterfaces source) + => new(source); - public readonly struct AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_ - : IValueReadOnlyList>, IList - where TEnumerable : IList - { - readonly TestListWithExplicitInterfaces source; - readonly TEnumerable source2; + public readonly struct AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_ + : IValueReadOnlyList>, IList + where TEnumerable : IList + { + readonly TEnumerable source; - internal AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_(TestListWithExplicitInterfaces source, TEnumerable source2) - => (this.source, this.source2) = (source, source2); + internal AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_(TEnumerable source) + => this.source = source; - // Implement IValueEnumerable> + // Implement IValueEnumerable> - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator GetEnumerator() => new(source2.GetEnumerator()); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() => new(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + // Implement ICollection - // Implement ICollection + public int Count => source.Count; - public int Count => source2.Count; + public bool IsReadOnly => true; - public bool IsReadOnly => true; + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); - void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); - bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + void ICollection.Clear() => throw new NotSupportedException(); - void ICollection.Clear() => throw new NotSupportedException(); + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); - public void CopyTo(Span span) + var index = 0; + foreach (var current in this) { - if (Count is 0) return; - if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); - - var index = 0; - foreach (var current in this) - { - span[index] = current; - checked { index++; } - } + span[index] = current; + checked { index++; } } + } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TestValueType item) => source2.Contains(item); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TestValueType item) => source.Contains(item); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TestValueType[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => source.CopyTo(array, arrayIndex); - // Implement IList + // Implement IList - public TestValueType this[int index] => source2[index]; + public TestValueType this[int index] => source[index]; - TestValueType IList.this[int index] - { - get => source2[index]; - set => throw new NotSupportedException(); - } + TestValueType IList.this[int index] + { + get => source[index]; + set => throw new NotSupportedException(); + } - void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); - void IList.RemoveAt(int index) => throw new NotSupportedException(); + void IList.RemoveAt(int index) => throw new NotSupportedException(); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int IndexOf(TestValueType item) => source2.IndexOf(item); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int IndexOf(TestValueType item) => source.IndexOf(item); } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs index 3e8a3356f..a1e9b7b6c 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs @@ -9,70 +9,80 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestReadOnlyCollection_TestValueType_ AsValueEnumerable(this TestReadOnlyCollection source) + => new(source); + + public readonly struct AsValueEnumerable_TestReadOnlyCollection_TestValueType_ + : IValueReadOnlyCollection.Enumerator>, ICollection { + readonly TestReadOnlyCollection source; + + internal AsValueEnumerable_TestReadOnlyCollection_TestValueType_(TestReadOnlyCollection source) + => this.source = source; + + // Implement IValueEnumerable.Enumerator> [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestReadOnlyCollection_TestValueType_> AsValueEnumerable(this TestReadOnlyCollection source) - => new(source, source); + public TestReadOnlyCollection.Enumerator GetEnumerator() => source.GetEnumerator(); - public readonly struct AsValueEnumerable_TestReadOnlyCollection_TestValueType_ - : IValueReadOnlyCollection.Enumerator>, ICollection - where TEnumerable : IReadOnlyCollection - { - readonly TestReadOnlyCollection source; - readonly TEnumerable source2; + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - internal AsValueEnumerable_TestReadOnlyCollection_TestValueType_(TestReadOnlyCollection source, TEnumerable source2) - => (this.source, this.source2) = (source, source2); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - // Implement IValueEnumerable.Enumerator> + // Implement ICollection - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TestReadOnlyCollection.Enumerator GetEnumerator() => source.GetEnumerator(); + public int Count => source.Count; - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + public bool IsReadOnly => true; - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); - // Implement ICollection + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); - public int Count => source2.Count; + void ICollection.Clear() => throw new NotSupportedException(); - public bool IsReadOnly => true; + public bool Contains(TestValueType item) + { + if (Count is 0) + return false; - void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + using var enumerator = GetEnumerator(); + while (enumerator.MoveNext()) + { + if (EqualityComparer.Default.Equals(enumerator.Current, item)) + return true; + } + return false; + } - bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + public void CopyTo(TestValueType[] array, int arrayIndex) + { + if (Count is 0) + return; - void ICollection.Clear() => throw new NotSupportedException(); + if (array.Length - arrayIndex < Count) + throw new ArgumentException("Destination array was not long enough. Check the destination index, length, and the array's lower bounds.", nameof(array)); - public void CopyTo(Span span) + using var enumerator = GetEnumerator(); + if (arrayIndex is 0 && array.Length == Count) { - if (Count is 0) return; - if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); - - var index = 0; - foreach (var current in this) - { - span[index] = current; - checked { index++; } - } + for (var index = 0; index < array.Length && enumerator.MoveNext(); index++) + array[index] = enumerator.Current; } - - public bool Contains(TestValueType item) + else { - foreach (var current in this) + checked { - if (EqualityComparer.Default.Equals(current, item)) return true; + for (var index = arrayIndex; enumerator.MoveNext(); index++) + array[index] = enumerator.Current; } - return true; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TestValueType[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex)); } } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs index b542189f3..2aa13a609 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs @@ -9,99 +9,113 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestReadOnlyList_TestValueType_ AsValueEnumerable(this TestReadOnlyList source) + => new(source); + + public readonly struct AsValueEnumerable_TestReadOnlyList_TestValueType_ + : IValueReadOnlyList.Enumerator>, IList { + readonly TestReadOnlyList source; + + internal AsValueEnumerable_TestReadOnlyList_TestValueType_(TestReadOnlyList source) + => this.source = source; + + // Implement IValueEnumerable.Enumerator> [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static AsValueEnumerable_TestReadOnlyList_TestValueType_> AsValueEnumerable(this TestReadOnlyList source) - => new(source, source); + public TestReadOnlyList.Enumerator GetEnumerator() => source.GetEnumerator(); - public readonly struct AsValueEnumerable_TestReadOnlyList_TestValueType_ - : IValueReadOnlyList.Enumerator>, IList - where TEnumerable : IReadOnlyList - { - readonly TestReadOnlyList source; - readonly TEnumerable source2; + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - internal AsValueEnumerable_TestReadOnlyList_TestValueType_(TestReadOnlyList source, TEnumerable source2) - => (this.source, this.source2) = (source, source2); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - // Implement IValueEnumerable.Enumerator> + // Implement ICollection - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TestReadOnlyList.Enumerator GetEnumerator() => source.GetEnumerator(); + public int Count => source.Count; - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + public bool IsReadOnly => true; - IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); - // Implement ICollection + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); - public int Count => source2.Count; + void ICollection.Clear() => throw new NotSupportedException(); - public bool IsReadOnly => true; + public bool Contains(TestValueType item) + { + if (Count is 0) + return false; - void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + using var enumerator = GetEnumerator(); + while (enumerator.MoveNext()) + { + if (EqualityComparer.Default.Equals(enumerator.Current, item)) + return true; + } + return false; + } - bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + public void CopyTo(TestValueType[] array, int arrayIndex) + { + if (Count is 0) + return; - void ICollection.Clear() => throw new NotSupportedException(); + if (array.Length - arrayIndex < Count) + throw new ArgumentException("Destination array was not long enough. Check the destination index, length, and the array's lower bounds.", nameof(array)); - public void CopyTo(Span span) + using var enumerator = GetEnumerator(); + if (arrayIndex is 0 && array.Length == Count) { - if (Count is 0) return; - if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); - - var index = 0; - foreach (var current in this) - { - span[index] = current; - checked { index++; } - } + for (var index = 0; index < array.Length && enumerator.MoveNext(); index++) + array[index] = enumerator.Current; } - - public bool Contains(TestValueType item) + else { - foreach (var current in this) + checked { - if (EqualityComparer.Default.Equals(current, item)) return true; + for (var index = arrayIndex; enumerator.MoveNext(); index++) + array[index] = enumerator.Current; } - return true; } + } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TestValueType[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex)); - - // Implement IList + // Implement IList - public TestValueType this[int index] => source2[index]; + public TestValueType this[int index] => source[index]; - TestValueType IList.this[int index] - { - get => source2[index]; - set => throw new NotSupportedException(); - } + TestValueType IList.this[int index] + { + get => source[index]; + set => throw new NotSupportedException(); + } - void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); - void IList.RemoveAt(int index) => throw new NotSupportedException(); + void IList.RemoveAt(int index) => throw new NotSupportedException(); - public int IndexOf(TestValueType item) + public int IndexOf(TestValueType item) + { + if (Count is not 0) { - if (Count is not 0) + checked { var index = 0; - foreach (var current in this) + foreach (var current in source) { - if (EqualityComparer.Default.Equals(current, item)) return index; + if (EqualityComparer.Default.Equals(current, item)) + return index; - checked { index++; } + index++; } } - return -1; } + return -1; } } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs index 8dca1ed6c..c3f0ec230 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs @@ -9,13 +9,12 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TestValueEnumerable AsValueEnumerable(this TestValueEnumerable source) - => source; - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static TestValueEnumerable AsValueEnumerable(this TestValueEnumerable source) + => source; } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs index b29d02dd2..a640141f5 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Array.cs @@ -9,13 +9,12 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func predicate) - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper>(source, predicate); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func predicate) + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper>(source, predicate); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs index e398ee800..53c5b7c63 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Count.Span.cs @@ -9,13 +9,12 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.SpanValueEnumerable source, Func predicate) - => NetFabric.Hyperlinq.ArrayExtensions.Count(source.Span, predicate); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.SpanValueEnumerable source, Func predicate) + => NetFabric.Hyperlinq.ArrayExtensions.Count(source.Span, predicate); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Empty.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Empty.cs index 8b9f8f882..dbe7e1354 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Empty.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Empty.cs @@ -9,9 +9,8 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - } } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs index 2c0e61834..af70ff565 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.Array.cs @@ -9,13 +9,12 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static NetFabric.Hyperlinq.ValueReadOnlyListExtensions.SelectEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper> Select(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Select, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType>(source, selector); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueReadOnlyListExtensions.SelectEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper> Select(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Select, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, TestReferenceType>(source, selector); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs index 4bdc3cdff..2410968fe 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Select.TestEnumerableWithValueTypeEnumerator.cs @@ -9,38 +9,37 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) - // => new(source, source); + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) + // => new(source, source); - //public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ - // : IValueEnumerable.Enumerator> - // where TEnumerable : IEnumerable - //{ - // readonly TestEnumerableWithValueTypeEnumerator source; - // readonly TEnumerable source2; + //public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ + // : IValueEnumerable.Enumerator> + // where TEnumerable : IEnumerable + //{ + // readonly TestEnumerableWithValueTypeEnumerator source; + // readonly TEnumerable source2; - // internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) - // => (this.source, this.source2) = (source, source2); + // internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) + // => (this.source, this.source2) = (source, source2); - // // Implement IValueEnumerable.Enumerator> + // // Implement IValueEnumerable.Enumerator> - // [MethodImpl(MethodImplOptions.AggressiveInlining)] - // public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); - // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); - // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); - //} + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + //} - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerableExtensions.SelectEnumerable>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper> Select(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source, System.Func selector) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select>, TestEnumerableWithValueTypeEnumerator.Enumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper>(source, selector); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ValueEnumerableExtensions.SelectEnumerable.Enumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper> Select(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ source, System.Func selector) + => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select.Enumerator, TestValueType, TestReferenceType, NetFabric.Hyperlinq.FunctionWrapper>(source, selector); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs index fc5247cdd..b26994268 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Skip.Take.Array.cs @@ -9,17 +9,16 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Skip(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Skip, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Skip(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Skip, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Take(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) - => NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.Take, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.SkipTakeEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType> Take(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, int count) + => NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.Take, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType>(source, count); } diff --git a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs index ddc70003c..e3626ae0d 100644 --- a/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs +++ b/NetFabric.Hyperlinq.UnitTests/TestData/Results/Where.Array.cs @@ -9,13 +9,12 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace NetFabric.Hyperlinq +namespace NetFabric.Hyperlinq; + +static partial class GeneratedExtensionMethods { - static partial class GeneratedExtensionMethods - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.WhereEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper> Where(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Where, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper>(source, selector); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueReadOnlyCollectionExtensions.WhereEnumerable, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper> Where(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func selector) + => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Where, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable.DisposableEnumerator, TestValueType, NetFabric.Hyperlinq.FunctionWrapper>(source, selector); } diff --git a/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs b/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs index 8624452ba..99d722e67 100644 --- a/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Generator.AsValueEnumerable.cs @@ -100,25 +100,15 @@ public partial class Generator // Define what value enumerator type will be used var enumeratorIsIEnumerator = getEnumeratorReturnType.ImplementsInterface(SpecialType.System_Collections_Generic_IEnumerator_T, out _); - var useConstraints = enumerableIsIEnumerable; var enumeratorTypeString = enumeratorIsIEnumerator ? getEnumeratorReturnType.IsValueType ? getEnumeratorReturnTypeString : $"ValueEnumerator<{itemTypeString}>" - : useConstraints - ? $"{enumerableTypeString}.Enumerator" - : $"{enumerableTypeString}.Enumerator"; + : $"{enumerableTypeString}.Enumerator"; // Generate the method - _ = useConstraints - ? builder - .Line() - .GeneratedCodeMethodAttributes() - .AggressiveInliningAttribute() - .Line($"public static {enumerableTypeString}<{receiverTypeString}> AsValueEnumerable(this {receiverTypeString} source)") - .Indent().Line($"=> new(source, source);") - : builder + _ = builder .Line() .GeneratedCodeMethodAttributes() .AggressiveInliningAttribute() @@ -126,14 +116,9 @@ public partial class Generator .Indent().Line($"=> new(source);"); // Generate the value enumerable wrapper - string valueEnumerableTypeName; - valueEnumerableTypeName = useConstraints - ? $"{enumerableTypeString}" - : enumerableTypeString; - _ = builder .Line() - .Line($"public readonly struct {valueEnumerableTypeName}"); + .Line($"public readonly struct {enumerableTypeString}"); // Define what interfaces the wrapper implements if (enumerableIsIList || enumerableIsIReadOnlyList) @@ -143,34 +128,11 @@ public partial class Generator else _ = builder.Indent().Line($": IValueEnumerable<{itemTypeString}, {enumeratorTypeString}>"); - if (useConstraints) - { - if (enumerableIsIList) - _ = builder.Indent().Line($"where TEnumerable : IList"); - else if (enumerableIsIReadOnlyList) - _ = builder.Indent().Line($"where TEnumerable : IReadOnlyList"); - else if (enumerableIsICollection) - _ = builder.Indent().Line($"where TEnumerable : ICollection"); - else if (enumerableIsIReadOnlyCollection) - _ = builder.Indent().Line($"where TEnumerable : IReadOnlyCollection"); - else if (enumerableIsIEnumerable) - _ = builder.Indent().Line($"where TEnumerable : IEnumerable"); - } - using (builder.Block()) { - // Define fields - _ = builder.Line($"readonly {receiverTypeString} source;"); - if (useConstraints) - _ = builder.Line($"readonly TEnumerable source2;"); - - // Define constructor - _ = useConstraints - ? builder - .Line() - .Line($"internal {enumerableTypeString}({receiverTypeString} source, TEnumerable source2)") - .Indent().Line($"=> (this.source, this.source2) = (source, source2);") - : builder + // Define field and constructor + _ = builder + .Line($"readonly {receiverTypeString} source;") .Line() .Line($"internal {enumerableTypeString}({receiverTypeString} source)") .Indent().Line($"=> this.source = source;"); @@ -179,16 +141,17 @@ public partial class Generator ImplementIValueEnumerable(builder, enumerableSymbols, enumeratorTypeString, itemTypeString, enumeratorIsIEnumerator); if (enumerableIsICollection || enumerableIsIReadOnlyCollection) { - var isValueType = itemType.IsValueType; - ImplementICollection(builder, itemTypeString, isValueType, enumerableIsICollection); + var sourceIsReferenceType = receiverTypeSymbol.IsReferenceType; + var itemIsReferenceType = itemType.IsReferenceType; + ImplementICollection(builder, itemTypeString, sourceIsReferenceType, itemIsReferenceType, enumerableIsICollection); if (enumerableIsIList || enumerableIsIReadOnlyList) - ImplementIList(builder, itemTypeString, isValueType, enumerableIsIList); + ImplementIList(builder, itemTypeString, sourceIsReferenceType, itemIsReferenceType, enumerableIsIList); } // A new AsValueEnumerable() method has been generated valueEnumerableType = new ValueEnumerableType( - Name: valueEnumerableTypeName, + Name: enumerableTypeString, EnumeratorType: enumeratorTypeString, ItemType: itemTypeString, IsCollection: enumerableIsICollection || enumerableIsIReadOnlyCollection, @@ -218,42 +181,33 @@ static void ImplementIValueEnumerable(CodeBuilder builder, EnumerableSymbols enu // No enumerator wrapper required _ = builder .AggressiveInliningAttribute() - .Line($"public {enumeratorTypeString} GetEnumerator()") - .Indent().Line($"=> source.GetEnumerator();") + .Line($"public {enumeratorTypeString} GetEnumerator() => source.GetEnumerator();") .Line() - .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator()") - .Indent().Line($"=> source2.GetEnumerator();") + .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => GetEnumerator();") .Line() - .Line($"IEnumerator IEnumerable.GetEnumerator()") - .Indent().Line($"=> source2.GetEnumerator();"); + .Line($"IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();"); } else if (enumerableSymbols.GetEnumerator.ContainingType.IsInterface()) { // Use the ValueEnumerator<> enumerator wrapper _ = builder .AggressiveInliningAttribute() - .Line($"public ValueEnumerator<{itemTypeString}> GetEnumerator()") - .Indent().Line($"=> new(source2.GetEnumerator());") + .Line($"public ValueEnumerator<{itemTypeString}> GetEnumerator() => new(source.GetEnumerator());") .Line() - .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator()") - .Indent().Line($"=> source2.GetEnumerator();") + .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source.GetEnumerator();") .Line() - .Line($"IEnumerator IEnumerable.GetEnumerator()") - .Indent().Line($"=> source2.GetEnumerator();"); + .Line($"IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator();"); } else { // Use the ValueEnumerator<> enumerator wrapper _ = builder .AggressiveInliningAttribute() - .Line($"public ValueEnumerator<{itemTypeString}> GetEnumerator()") - .Indent().Line($"=> new(source.GetEnumerator());") + .Line($"public ValueEnumerator<{itemTypeString}> GetEnumerator() => new(source.GetEnumerator());") .Line() - .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator()") - .Indent().Line($"=> source2.GetEnumerator();") + .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source.GetEnumerator();") .Line() - .Line($"IEnumerator IEnumerable.GetEnumerator()") - .Indent().Line($"source2.GetEnumerator();"); + .Line($"IEnumerator IEnumerable.GetEnumerator() => source.GetEnumerator();"); } } else @@ -262,14 +216,11 @@ static void ImplementIValueEnumerable(CodeBuilder builder, EnumerableSymbols enu _ = builder .AggressiveInliningAttribute() - .Line($"public Enumerator GetEnumerator()") - .Indent().Line($"=> new(source.GetEnumerator());") + .Line($"public Enumerator GetEnumerator() => new(source.GetEnumerator());") .Line() - .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator()") - .Indent().Line($"=> new Enumerator(source.GetEnumerator());") + .Line($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => GetEnumerator();") .Line() - .Line($"IEnumerator IEnumerable.GetEnumerator()") - .Indent().Line($"=> new Enumerator(source.GetEnumerator());") + .Line($"IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();") .Line(); // define a value type enumerator wrapper @@ -282,24 +233,23 @@ static void ImplementIValueEnumerable(CodeBuilder builder, EnumerableSymbols enu .Indent().Line("=> this.source = source;") .Line() .Line($"public {itemTypeString} Current") - .Indent().Line($"=> source.Current;") + .Line("{") + .Indent().AggressiveInliningAttribute() + .Indent().Line($"get => source.Current;") + .Line("}") .Line() - .Line("object? IEnumerator.Current") - .Indent().Line("=> source.Current;") + .Line("object? IEnumerator.Current => source.Current;") .Line() .AggressiveInliningAttribute() - .Line("public bool MoveNext()") - .Indent().Line("=> source.MoveNext();") + .Line("public bool MoveNext() => source.MoveNext();") .Line(); _ = enumerableSymbols.EnumeratorSymbols.Reset is null ? builder - .Line("public void Reset()") - .Indent().Line("=> throw new NotSupportedException();") + .Line("public void Reset() => throw new NotSupportedException();") : builder .AggressiveInliningAttribute() - .Line("public void Reset()") - .Indent().Line("=> source.Reset();"); + .Line("public void Reset() => source.Reset();"); _ = enumerableSymbols.EnumeratorSymbols.Dispose is null ? builder @@ -309,19 +259,18 @@ static void ImplementIValueEnumerable(CodeBuilder builder, EnumerableSymbols enu : builder .Line() .AggressiveInliningAttribute() - .Line("public void Dispose()") - .Indent().Line("=> source.Dispose();"); + .Line("public void Dispose() => source.Dispose();"); } } } - static void ImplementICollection(CodeBuilder builder, string itemTypeString, bool itemTypeIsValueType, bool sourceIsICollection) + static void ImplementICollection(CodeBuilder builder, string itemTypeString, bool sourceIsReferenceType, bool itemIsReferenceType, bool sourceIsICollection) { _ = builder .Line() .Line($"// Implement ICollection<{itemTypeString}>") .Line() - .Line("public int Count => source2.Count;") + .Line("public int Count => source.Count;") .Line() .Line("public bool IsReadOnly => true;") .Line() @@ -329,8 +278,7 @@ static void ImplementICollection(CodeBuilder builder, string itemTypeString, boo .Line() .Line($"bool ICollection<{itemTypeString}>.Remove({itemTypeString} item) => throw new NotSupportedException();") .Line() - .Line($"void ICollection<{itemTypeString}>.Clear() => throw new NotSupportedException();") - .Line(); + .Line($"void ICollection<{itemTypeString}>.Clear() => throw new NotSupportedException();"); if (sourceIsICollection) { @@ -338,10 +286,10 @@ static void ImplementICollection(CodeBuilder builder, string itemTypeString, boo _ = builder .Line() .AggressiveInliningAttribute() - .Line($"public bool Contains({itemTypeString} item) => source2.Contains(item);") + .Line($"public bool Contains({itemTypeString} item) => source.Contains(item);") .Line() .AggressiveInliningAttribute() - .Line($"public void CopyTo({itemTypeString}[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex);"); + .Line($"public void CopyTo({itemTypeString}[] array, int arrayIndex) => source.CopyTo(array, arrayIndex);"); return; // nothing else to do } @@ -349,90 +297,104 @@ static void ImplementICollection(CodeBuilder builder, string itemTypeString, boo // The source does not implement these methods so we have to add an implementation _ = builder .Line() - .MethodBlock($"public bool Contains({itemTypeString}[] value)", - codeBuilder => codeBuilder - .Line("if (Count is 0)") - .Indent().Line("return;") - .Line() - .IfBlock("source is ICollection<{itemTypeString}> collection", - codeBuilder => codeBuilder - .Line("collection.Contains(values);"), - codeBuilder => + .MethodBlock($"public bool Contains({itemTypeString} item)", + codeBuilder => + { + _ = codeBuilder + .Line("if (Count is 0)") + .Indent().Line("return false;"); + + if (sourceIsReferenceType) { - codeBuilder - .Line("using var enumerator = GetEnumerator();"); + _ = codeBuilder + .Line() + .Line($"if (source is ICollection<{itemTypeString}> collection)") + .Indent().Line("return collection.Contains(item);"); + } - if (itemTypeIsValueType) // devirtualize the comparer - { - codeBuilder - .WhileBlock("enumerator.MoveNext()", - codeBuilder => codeBuilder - .Line("if (EqualityComparer<{itemTypeString}>.Default.Equals(enumerator.Current, value))") - .Indent().Line("return true;") - ) - .Line("return true;"); - } - else - { - codeBuilder - .Line($"var comparer = EqualityComparer<{itemTypeString}>.Default;") - .WhileBlock("enumerator.MoveNext()", - codeBuilder => codeBuilder - .Line("if (comparer.Equals(enumerator.Current, value))") - .Indent().Line("return true;") - ) - .Line("return true;"); - } - }) - ); + if (itemIsReferenceType) + { + _ = codeBuilder + .Line() + .Line($"var comparer = EqualityComparer<{itemTypeString}>.Default;") + .Line("using var enumerator = GetEnumerator();") + .WhileBlock("enumerator.MoveNext()", + codeBuilder => _ = codeBuilder + .Line("if (comparer.Equals(enumerator.Current, item))") + .Indent().Line("return true;") + ); + } + else // devirtualize the comparer + { + _ = codeBuilder + .Line() + .Line("using var enumerator = GetEnumerator();") + .WhileBlock("enumerator.MoveNext()", + codeBuilder => _ = codeBuilder + .Line($"if (EqualityComparer<{itemTypeString}>.Default.Equals(enumerator.Current, item))") + .Indent().Line("return true;") + ); + } + + _ = codeBuilder + .Line("return false;"); + }); _ = builder .Line() .MethodBlock($"public void CopyTo({itemTypeString}[] array, int arrayIndex)", - codeBuilder => codeBuilder - .Line("if (Count is 0)") - .Indent().Line("return;") - .Line() - .Line("if (array.Length - arrayIndex < Count)") - .Indent().Line("Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(array));") - .Line() - .IfBlock("source is ICollection<{itemTypeString}> collection", - codeBuilder => codeBuilder - .Line("collection.CopyTo(array, arrayIndex);"), - codeBuilder => codeBuilder - .Line("using var enumerator = GetEnumerator();") - .IfBlock( - "arrayIndex is 0 && array.Length == Count", // to enable range check elimination - codeBuilder => codeBuilder - .ForBlock("var index = 0; index < array.Length; index++", - codeBuilder => codeBuilder - .Line("_ = enumerator.MoveNext();") - .Line("array[index] = enumerator.Current;") - ), - codeBuilder => codeBuilder - .CheckedBlock( - codeBuilder => codeBuilder - .Line("for (var index = arrayIndex; enumerator.MoveNext(); index++)") - .Indent().Line("array[index] = enumerator.Current;") - ) - ) - ) - ); + codeBuilder => + { + _ = codeBuilder + .Line("if (Count is 0)") + .Indent().Line("return;") + .Line() + .Line("if (array.Length - arrayIndex < Count)") + .Indent().Line($"throw new ArgumentException(\"{Resource.DestinationNotLongEnough}\", nameof(array));"); + + if (sourceIsReferenceType) + { + codeBuilder + .Line() + .IfBlock($"source is ICollection<{itemTypeString}> collection", + codeBuilder => _ = codeBuilder + .Line("collection.CopyTo(array, arrayIndex);") + .Line("return;")); + } + + _ = codeBuilder + .Line() + .Line("using var enumerator = GetEnumerator();") + .IfBlock( + "arrayIndex is 0 && array.Length == Count", // to enable range check elimination + codeBuilder => _ = codeBuilder + .Line( + "for (var index = 0; index < array.Length && enumerator.MoveNext(); index++)") + .Indent().Line("array[index] = enumerator.Current;"), + codeBuilder => _ = codeBuilder + .CheckedBlock( + codeBuilder => _ = codeBuilder + .Line( + "for (var index = arrayIndex; enumerator.MoveNext(); index++)") + .Indent().Line("array[index] = enumerator.Current;") + ) + ); + }); } - static void ImplementIList(CodeBuilder builder, string itemTypeString, bool itemTypeIsValueType, bool sourceIsIList) + static void ImplementIList(CodeBuilder builder, string itemTypeString, bool sourceIsReferenceType, bool itemIsReferenceType, bool sourceIsIList) { _ = builder .Line() .Line($"// Implement IList<{itemTypeString}>") .Line() - .Line($"public {itemTypeString} this[int index] => source2[index];") + .Line($"public {itemTypeString} this[int index] => source[index];") .Line(); using (builder.Block($"{itemTypeString} IList<{itemTypeString}>.this[int index]")) { _ = builder - .Line("get => source2[index];") + .Line("get => source[index];") .Line("set => throw new NotSupportedException();"); } @@ -448,7 +410,7 @@ static void ImplementIList(CodeBuilder builder, string itemTypeString, bool item // Call the methods implemented by the source _ = builder .AggressiveInliningAttribute() - .Line($"public int IndexOf({itemTypeString} item) => source2.IndexOf(item);"); + .Line($"public int IndexOf({itemTypeString} item) => source.IndexOf(item);"); return; } @@ -457,45 +419,49 @@ static void ImplementIList(CodeBuilder builder, string itemTypeString, bool item builder .MethodBlock($"public int IndexOf({itemTypeString} item)", codeBuilder => codeBuilder - .IfBlock("if (Count is not 0)", - codeBuilder => codeBuilder - .IfBlock("source is IList<{itemTypeString}> list", - codeBuilder => codeBuilder - .Line("return list.IndexOf(item);"), + .IfBlock("Count is not 0", codeBuilder => { - codeBuilder - .CheckedBlock(codeBuilder => - { - codeBuilder - .Line("var index = 0;"); + if (sourceIsReferenceType) + { + codeBuilder + .Line($"if (source is IList<{itemTypeString}> list)") + .Indent().Line("return list.IndexOf(item);") + .Line(); + } - if (itemTypeIsValueType) // devirtualize the comparer - { - codeBuilder - .ForEachBlock("var current in source2", - codeBuilder => codeBuilder - .Line($"if (EqualityComparer<{itemTypeString}>.Default.Equals(current, item))") - .Indent().Line("return index;") - .Line() - .Line("checked { index++; }") - ); - } - else + codeBuilder + .CheckedBlock( + codeBuilder => { - codeBuilder - .Line($"var comparer = EqualityComparer<{itemTypeString}>.Default;") - .ForEachBlock("var current in source2", - codeBuilder => codeBuilder - .Line($"if (comparer.Equals(current, item))") - .Indent().Line("return index;") - .Line() - .Line("checked { index++; }") - ); - } - }); + if (itemIsReferenceType) + { + codeBuilder + .Line($"var comparer = EqualityComparer<{itemTypeString}>.Default;") + .Line("var index = 0;") + .ForEachBlock("var current in source", + codeBuilder => codeBuilder + .Line($"if (comparer.Equals(current, item))") + .Indent().Line("return index;") + .Line() + .Line("index++;") + ); + } + else // devirtualize the comparer + { + codeBuilder + .Line("var index = 0;") + .ForEachBlock("var current in source", + codeBuilder => codeBuilder + .Line( + $"if (EqualityComparer<{itemTypeString}>.Default.Equals(current, item))") + .Indent().Line("return index;") + .Line() + .Line("index++;") + ); + } + }); }) - ) .Line("return -1;") ); } diff --git a/NetFabric.Hyperlinq/Generator.cs b/NetFabric.Hyperlinq/Generator.cs index 0a636e725..8bebaa42d 100644 --- a/NetFabric.Hyperlinq/Generator.cs +++ b/NetFabric.Hyperlinq/Generator.cs @@ -163,9 +163,10 @@ internal static void GenerateSource(Compilation compilation, TypeSymbolsCache ty .Line("using System.Diagnostics;") .Line("using System.Diagnostics.CodeAnalysis;") .Line("using System.Runtime.CompilerServices;") + .Line() + .Line("namespace NetFabric.Hyperlinq;") .Line(); - using (builder.Block("namespace NetFabric.Hyperlinq")) using (builder.Block("static partial class GeneratedExtensionMethods")) { foreach (var expressionSyntax in memberAccessExpressions) diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 90454e7e8..ff22ce1c4 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -66,5 +66,20 @@ runtime; build; native; contentfiles; analyzers + + + + ResXFileCodeGenerator + Resource.Designer.cs + + + + + + True + True + Resources.resx + + diff --git a/NetFabric.Hyperlinq/Resource.Designer.cs b/NetFabric.Hyperlinq/Resource.Designer.cs new file mode 100644 index 000000000..f8a357e32 --- /dev/null +++ b/NetFabric.Hyperlinq/Resource.Designer.cs @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace NetFabric.Hyperlinq { + using System; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resource { + + private static System.Resources.ResourceManager resourceMan; + + private static System.Globalization.CultureInfo resourceCulture; + + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resource() { + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { + get { + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("NetFabric.Hyperlinq.Resource", typeof(Resource).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + internal static string DestinationNotLongEnough { + get { + return ResourceManager.GetString("DestinationNotLongEnough", resourceCulture); + } + } + } +} diff --git a/NetFabric.Hyperlinq/Resource.resx b/NetFabric.Hyperlinq/Resource.resx new file mode 100644 index 000000000..d217097c0 --- /dev/null +++ b/NetFabric.Hyperlinq/Resource.resx @@ -0,0 +1,24 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Destination array was not long enough. Check the destination index, length, and the array's lower bounds. + + \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Utils/CodeBuilder.cs b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs index 7d4074a89..1d81877fb 100644 --- a/NetFabric.Hyperlinq/Utils/CodeBuilder.cs +++ b/NetFabric.Hyperlinq/Utils/CodeBuilder.cs @@ -85,7 +85,7 @@ public CodeBuilder IfBlock(string condition, Action block) public CodeBuilder IfBlock(string condition, Action trueBlock, Action falseBlock) { - using (Block($"if ({condition}))")) + using (Block($"if ({condition})")) { trueBlock(this); }