Permalink
Browse files

Use Array.Empty<T> for LINQ's Enumerable.Empty<TResult>

  • Loading branch information...
justinvp committed Jul 9, 2015
1 parent 3279ca8 commit 8e51ee0bbd2979a15b361f4abfd95e1b2e4b2935
Showing with 2 additions and 11 deletions.
  1. +2 −11 src/System.Linq/src/System/Linq/Enumerable.cs
@@ -1452,7 +1452,7 @@ private static IEnumerable<TResult> RepeatIterator<TResult>(TResult element, int
public static IEnumerable<TResult> Empty<TResult>()
{
return EmptyEnumerable<TResult>.Instance;
return Array.Empty<TResult>();
}
public static bool Any<TSource>(this IEnumerable<TSource> source)
@@ -2500,15 +2500,6 @@ public static decimal Average<TSource>(this IEnumerable<TSource> source, Func<TS
}
}
//
// This is a more memory-intensive EmptyEnumerable<TElement> that allocates a new Enumerator each time. Unfortunately, we have to retain it
// for desktop platforms to avoid breaking scenarios that serialize an empty enumerable on 4.5 and deserialize it on 4.0.
//
internal class EmptyEnumerable<TElement>
{
public static readonly TElement[] Instance = new TElement[0];
}
internal class IdentityFunction<TElement>
{
public static Func<TElement, TElement> Instance
@@ -2583,7 +2574,7 @@ public int Count
{
Grouping<TKey, TElement> grouping = GetGrouping(key, false);
if (grouping != null) return grouping;
return EmptyEnumerable<TElement>.Instance;
return Array.Empty<TElement>();
}
}

0 comments on commit 8e51ee0

Please sign in to comment.