Skip to content

Commit 99a7964

Browse files
authored
Derive OrderedEnumerable from Iterator (#98874)
* Move OrderedEnumerable to be nested in Enumerable * Derive OrderedEnumerable from Iterator The OrderedEnumerable implementation today doesn't derive from Iterator, and it has a GetEnumerator method implemented with yield. That means the optimization that allows the enumerable to be reused as the enumerator doesn't kick in, and we end up allocating a separate enumerator object in order to iterate through an Order{By} enumerable.
1 parent 6f10be6 commit 99a7964

File tree

5 files changed

+848
-776
lines changed

5 files changed

+848
-776
lines changed

src/libraries/System.Linq/src/System/Linq/Distinct.SpeedOpt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static partial class Enumerable
99
{
1010
private sealed partial class DistinctIterator<TSource> : IIListProvider<TSource>
1111
{
12-
public TSource[] ToArray() => Enumerable.HashSetToArray(new HashSet<TSource>(_source, _comparer));
12+
public TSource[] ToArray() => HashSetToArray(new HashSet<TSource>(_source, _comparer));
1313

1414
public List<TSource> ToList() => new List<TSource>(new HashSet<TSource>(_source, _comparer));
1515

0 commit comments

Comments
 (0)