From d56d12ca23d154c26490e6a4220afe0eea7b254a Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Fri, 31 Mar 2023 15:07:08 +0100 Subject: [PATCH] perf: lazily yield additional value This prevents an allocation of the array, saving approximately half. Initial benchmarks also show this implementation to be ~100ns faster --- X10D/src/Linq/EnumerableExtensions.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/X10D/src/Linq/EnumerableExtensions.cs b/X10D/src/Linq/EnumerableExtensions.cs index c94f10a..99b6773 100644 --- a/X10D/src/Linq/EnumerableExtensions.cs +++ b/X10D/src/Linq/EnumerableExtensions.cs @@ -31,7 +31,12 @@ public static class EnumerableExtensions } #endif - return source.Concat(new[] {value}); + foreach (TSource item in source) + { + yield return item; + } + + yield return value; } ///