From 2abc5284540fbe7069ce24832843dbaae204dad3 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Sun, 26 Feb 2023 23:11:55 +0100 Subject: [PATCH 1/2] Use compiler-generated delegate cache in "AssertCount" --- MoreLinq/AssertCount.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/MoreLinq/AssertCount.cs b/MoreLinq/AssertCount.cs index 0273bf060..6bdd4f234 100644 --- a/MoreLinq/AssertCount.cs +++ b/MoreLinq/AssertCount.cs @@ -24,7 +24,8 @@ static partial class MoreEnumerable { #if MORELINQ - static readonly Func DefaultErrorSelector = OnAssertCountFailure; + internal static string FormatSequenceLengthErrorMessage(int cmp, int count) => + $"Sequence contains too {(cmp < 0 ? "few" : "many")} elements when exactly {count:N0} {(count == 1 ? "was" : "were")} expected."; /// /// Asserts that a source sequence contains a given count of elements. @@ -42,7 +43,7 @@ static partial class MoreEnumerable /// public static IEnumerable AssertCount(this IEnumerable source, int count) => - AssertCountImpl(source, count, DefaultErrorSelector); + AssertCountImpl(source, count, static (cmp, count) => new SequenceException(FormatSequenceLengthErrorMessage(cmp, count))); /// /// Asserts that a source sequence contains a given count of elements. @@ -71,12 +72,6 @@ public static IEnumerable AssertCount(this IEnumerable errorSelector) => AssertCountImpl(source, count, errorSelector); - static Exception OnAssertCountFailure(int cmp, int count) => - new SequenceException(FormatSequenceLengthErrorMessage(cmp, count)); - - internal static string FormatSequenceLengthErrorMessage(int cmp, int count) => - $"Sequence contains too {(cmp < 0 ? "few" : "many")} elements when exactly {count:N0} {(count == 1 ? "was" : "were")} expected."; - #endif static IEnumerable AssertCountImpl(IEnumerable source, From 27e961f679604cbed58ae96fbff253c981a86b3a Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Mon, 27 Feb 2023 07:55:29 +0100 Subject: [PATCH 2/2] Refresh extensions wrappers --- MoreLinq/Extensions.g.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index a19f82c10..e543cbe72 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -498,7 +498,6 @@ public static IEnumerable Assert(this IEnumerable sou [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] public static partial class AssertCountExtension { - /// /// Asserts that a source sequence contains a given count of elements. ///