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

Add Enumerable.Concat & Enumerable.Flatten methods #61230

Closed

Conversation

eiriktsarpalis
Copy link
Member

@eiriktsarpalis eiriktsarpalis commented Nov 4, 2021

Note to reviewers: the feature is implemented in dfd7d00 and should be reviewed separately from 231b537 which contains infrastructural cleanups.

Fixes #54220.

Removes the ExceptionArgument mechanism that
seems to predate the nameof language feature.
@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone Nov 4, 2021
@eiriktsarpalis eiriktsarpalis self-assigned this Nov 4, 2021
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Nov 4, 2021

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

Issue Details

Fixes #54220.

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Linq

Milestone: 7.0.0

@stephentoub
Copy link
Member

Removes the unneeded ExceptionMessage enum infrastructure.

Why is it "unneeded"?

ThrowHelper.ThrowArgumentNullException(nameof(sources));
}

return FlattenIterator(sources);
Copy link
Member

@stephentoub stephentoub Nov 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider just doing:

return sources.SelectMany(e => e);

rather than implementing another iterator?

Copy link
Member Author

@eiriktsarpalis eiriktsarpalis Nov 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, ultimately it's tradeoff between this and a closure allocation and a few virtual calls. I should point out that the simple SelectMany implementation does inherit from Iterator<T>, but ultimately I didn't find any of the speed optimizations offered in this particular case to be useful in practice.

Copy link
Member

@stephentoub stephentoub Nov 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, ultimately it's tradeoff between this and a closure allocation and a few virtual calls

There's no closure allocation with sources.SelectMany(e => e). There is one delegate per T allocated for the process. And an extra delegate invocation per enumerable. From my perspective, I'd rather have less code to maintain and a smaller binary (and implicitly pick up any optimizations SelectMany adds in the future, e.g. if it were to special case T[]). Up to you, though.

@eiriktsarpalis
Copy link
Member Author

Removes the unneeded ExceptionMessage enum infrastructure.

Why is it "unneeded"?

I would guess it's a mechanism that predates nameof. It's simply mapping predefined argument names to strings.

@stephentoub
Copy link
Member

stephentoub commented Nov 5, 2021

I would guess it's a mechanism that predates nameof

It's not. It's reducing the size of the generated generic instantiations. It's possible it's no longer the right tradeoff, but that would benefit from numbers.

@eiriktsarpalis
Copy link
Member Author

eiriktsarpalis commented Nov 5, 2021

It's not. It's reducing the size of the generated generic instantiations. It's possible it's no longer the right tradeoff, but that would benefit from numbers.

If I understand this correctly, it's an optimization replacing an ldstr instruction with an ldc.i4 in generic methods?

https://sharplab.io/#v2:C4LghgzgtgPgAgBgARwIwBYDcBYAUIpAZQAswAnABwBkwAjAOgCUBXAO2AEsoBTHXPOAGYUAJiQBhJAG88SOSmHdWzKEgByYHhGlIwAGlp6AxnoAme7noBmegOZ7iejnoBWegNZ6ANnqh7WegD2ehR6AI56ZHoQesB6zEgAvnzySLLyANoAUhzAAOJK3GQcRgAUwACeFNyBVqUc7ACUjQC66XJCKKjIALIAPAAqAHylaIKDQ0jujUgAvJOsmjV10ymZOfmFxWWV1bX1Ta3tCupL2moTo6jjw1Mz86da9O58iUA==

@ghost ghost locked as resolved and limited conversation to collaborators Dec 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add Enumerable.Concat & Flatten overloads
2 participants