-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Optimized struct enumerators #3341
Optimized struct enumerators #3341
Conversation
Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
- The one for rows is not needed from .NET Core 2.1 and above - The other has the extra ToArray API which needs the initial values to remain available, and the type to be readonly
…Sergio0694/WindowsCommunityToolkit into optimization/struct-enumerators
Thanks @Sergio0694, I'm still inclined to move this to 7.0 since we're trying to close down 6.1 still... @azchohfi thoughts? This still seems pretty straight-forward and should have test coverage (which pass). |
Yeah, I'm not worried. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up for #3128 and #3273
PR Type
What kind of change does this PR introduce?
@michael-hawker NOTE: this PR has no functional changes, I literally just shuffled some code around and removed some unnecessary types (as I've moved the code to the parent types). All the existing methods and operations are exactly the same as before, I didn't change anything at all there.
What is the current behavior?
The
Span<T>
/T[]
/T[,]
enumerators use a secondary enumerator type to perform the actual enumeration. This causes an unnecessary initial copy of the captured values, and introduces a second generic type with a couple method that the JIT compiler has to compile to native code (for value types).What is the new behavior?
The
GetEnumerator()
now simply returnsthis
, so the second type is no longer needed. All the enumeration methods are added directly to the first type. The enumerator types are no longer marked asreadonly
to allow direct enumeration on them. This is not a problem since those were always supposed to be used once anyway and never store anywhere (as they'reref struct
types).PR Checklist
Please check if your PR fulfills the following requirements:
Pull Request has been submitted to the documentation repository instructions. Link:Sample in sample app has been added / updated (for bug fixes / features)Icon has been created (if new sample) following the Thumbnail Style Guide and templates