-
Notifications
You must be signed in to change notification settings - Fork 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
Avoid allocations due to use of Keys/Values instead of GetEnumerator #19126
Conversation
@dotnet/roslyn-compiler for review (let me know if anyone else should be added) Please note the comment regarding the first commit overlapping with #19125. |
{ | ||
isSuppressed = diagnosticOptions[diag.Id] == ReportDiagnostic.Suppress; |
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.
We really sohuld have an analyzer fro that pattern
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.
We really should.
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.
LGTM
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.
LGTM
@MeiChin-Tsai for ask mode (at the request of @jaredpar) |
approved. |
Nice |
@jcouv I think this is my favorite use of C# 7 to date. It totally resolved something I previously found rather frustrating. 😄 |
ImmutableDictionary<TKey, TValue>
provides a non-allocating implementation ofGetEnumerator()
, but does not offer non-allocating implementations of theKeys
orValues
properties (dotnet/corefx#249 and linked issues). This pull request adds aDeconstruct
extension method forKeyValuePair<TKey, TValue>
, leveraging a new C# feature to provide almost identical use-site code for these properties without actually incurring the allocation overhead.📝 This pull request builds on the change in #19125 to avoid merge conflicts (
the first commit in the branch overlaps) (edit: no longer applies).Ask Mode
Customer scenario
No observable changes.
GetEnumerator()
instead ofKeys
where applicableGetEnumerator()
instead ofValues
where applicableDeconstruct
extension method so the above changes can be implemented with minimal changes to the actual code structureBugs this fixes:
N/A
Workarounds, if any
None needed.
Risk
Low (no behavior changes).
Performance impact
Performance is improved by eliminating unnecessary allocations.
Is this a regression from a previous update?
No.
Root cause analysis:
Missed during code review?
How was the bug found?
Internal code review.