Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b219b8d

Browse files
committed
Merge pull request #2290 from justinvp/linqempty
Use Array.Empty<T> for LINQ's Enumerable.Empty<TResult>
2 parents d9f76a8 + 8e51ee0 commit b219b8d

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/System.Linq/src/System/Linq/Enumerable.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ private static IEnumerable<TResult> RepeatIterator<TResult>(TResult element, int
14521452

14531453
public static IEnumerable<TResult> Empty<TResult>()
14541454
{
1455-
return EmptyEnumerable<TResult>.Instance;
1455+
return Array.Empty<TResult>();
14561456
}
14571457

14581458
public static bool Any<TSource>(this IEnumerable<TSource> source)
@@ -2500,15 +2500,6 @@ public static decimal Average<TSource>(this IEnumerable<TSource> source, Func<TS
25002500
}
25012501
}
25022502

2503-
//
2504-
// This is a more memory-intensive EmptyEnumerable<TElement> that allocates a new Enumerator each time. Unfortunately, we have to retain it
2505-
// for desktop platforms to avoid breaking scenarios that serialize an empty enumerable on 4.5 and deserialize it on 4.0.
2506-
//
2507-
internal class EmptyEnumerable<TElement>
2508-
{
2509-
public static readonly TElement[] Instance = new TElement[0];
2510-
}
2511-
25122503
internal class IdentityFunction<TElement>
25132504
{
25142505
public static Func<TElement, TElement> Instance
@@ -2583,7 +2574,7 @@ public IEnumerable<TElement> this[TKey key]
25832574
{
25842575
Grouping<TKey, TElement> grouping = GetGrouping(key, false);
25852576
if (grouping != null) return grouping;
2586-
return EmptyEnumerable<TElement>.Instance;
2577+
return Array.Empty<TElement>();
25872578
}
25882579
}
25892580

0 commit comments

Comments
 (0)