Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private sealed partial class DistinctIterator<TSource> : IIListProvider<TSource>
{
public TSource[] ToArray() => Enumerable.HashSetToArray(new HashSet<TSource>(_source, _comparer));

public List<TSource> ToList() => Enumerable.HashSetToList(new HashSet<TSource>(_source, _comparer));
public List<TSource> ToList() => new List<TSource>(new HashSet<TSource>(_source, _comparer));

public int GetCount(bool onlyIfCheap) => onlyIfCheap ? -1 : new HashSet<TSource>(_source, _comparer).Count;
}
Expand Down
22 changes: 0 additions & 22 deletions src/libraries/System.Linq/src/System/Linq/ToCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,27 +253,5 @@ private static TSource[] HashSetToArray<TSource>(HashSet<TSource> set)
set.CopyTo(result);
return result;
}

private static List<TSource> HashSetToList<TSource>(HashSet<TSource> set)
{
int count = set.Count;

var result = new List<TSource>(count);
if (count > 0)
{
Span<TSource> span = SetCountAndGetSpan(result, count);

int index = 0;
foreach (TSource item in set)
{
span[index] = item;
++index;
}

Debug.Assert(index == span.Length, "All list elements were not initialized.");
}

return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private HashSet<TSource> FillSet()

public TSource[] ToArray() => Enumerable.HashSetToArray(FillSet());

public List<TSource> ToList() => Enumerable.HashSetToList(FillSet());
public List<TSource> ToList() => new List<TSource>(FillSet());

public int GetCount(bool onlyIfCheap) => onlyIfCheap ? -1 : FillSet().Count;
}
Expand Down