Skip to content

Avoid unnecessary enumerator allocations in XamlDirective.GetHashCode#6265

Merged
dipeshmsft merged 1 commit intodotnet:mainfrom
stephentoub:xamldirectivegethashcode
May 5, 2022
Merged

Avoid unnecessary enumerator allocations in XamlDirective.GetHashCode#6265
dipeshmsft merged 1 commit intodotnet:mainfrom
stephentoub:xamldirectivegethashcode

Conversation

@stephentoub
Copy link
Member

Description

We can just index into the ReadOnlyCollection rather than iterating it via IEnumerator. We can also avoid unnecessary collection allocations when all of our internal usage that already has an immutable ReadOnlyCollection goes through the internal constructor.

Customer Impact

These XamlDirective instances are frequently stored in Dictionary's, resulting in every GetHashCode call by the dictionary allocating an enumerator.

Regression

No

Testing

CI

Risk

Minimal.

We can just index into the ReadOnlyCollection rather than iterating it via IEnumerator.  We can also avoid unnecessary collection allocations when all of our internal usage that already has an immutable ReadOnlyCollection goes through the internal constructor.
@stephentoub stephentoub requested a review from a team as a code owner March 16, 2022 22:08
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Mar 16, 2022
@ghost ghost requested review from SamBent, dipeshmsft and singhashish-wpf March 16, 2022 22:08
@anjaligupta-dev anjaligupta-dev self-assigned this Mar 27, 2022
@dipeshmsft dipeshmsft merged commit abddc4b into dotnet:main May 5, 2022
@ghost ghost assigned stephentoub May 5, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants