The Wayback Machine - https://web.archive.org/web/20230526135250/https://github.com/dotnet/runtime/pull/86796
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Span to fill List<T> in more ToList scenarios #86796

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brantburnett
Copy link
Contributor

Adds span-based filling of List<T> during calls to ToList using CollectionsMarshal.SetCount to the following additional scenarios:

  • ToList of a Union or Distinct
  • ToList of a Lookup<TKey, TElement> including cases within grouping
  • ToList of a Select projection against an IPartition (i.e. sorted)
  • ToList of an OrderedEnumerable returning a single element (i.e. Skip/Take applied to a sorted list for a single result)
  • ToList of a DefaultIfEmpty where the source is empty and an IIListProvider
  • ToList of Append and Prepend scenarios

Secondary improvements:

  • ToArray of an empty Lookup<TKey, TElement> now uses Array.Empty

Fixes #80760

@msftbot msftbot bot added the community-contribution Indicates that the PR has been added by a community member label May 26, 2023
@msftbot
Copy link
Contributor

msftbot bot commented May 26, 2023

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Issue Details

Adds span-based filling of List<T> during calls to ToList using CollectionsMarshal.SetCount to the following additional scenarios:

  • ToList of a Union or Distinct
  • ToList of a Lookup<TKey, TElement> including cases within grouping
  • ToList of a Select projection against an IPartition (i.e. sorted)
  • ToList of an OrderedEnumerable returning a single element (i.e. Skip/Take applied to a sorted list for a single result)
  • ToList of a DefaultIfEmpty where the source is empty and an IIListProvider
  • ToList of Append and Prepend scenarios

Secondary improvements:

  • ToArray of an empty Lookup<TKey, TElement> now uses Array.Empty

Fixes #80760

Author: brantburnett
Assignees: -
Labels:

area-System.Collections

Milestone: -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Collections community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IListProvider<T>.ToList() implementations use list.Add(element) instead of direct array initialization.
1 participant