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

Commit

Permalink
Merge pull request #2290 from justinvp/linqempty
Browse files Browse the repository at this point in the history
Use Array.Empty<T> for LINQ's Enumerable.Empty<TResult>
  • Loading branch information
stephentoub committed Jul 9, 2015
2 parents d9f76a8 + 8e51ee0 commit b219b8d
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/System.Linq/src/System/Linq/Enumerable.cs
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>();
}
}

Expand Down

0 comments on commit b219b8d

Please sign in to comment.