This repository was archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 191
Improve performance and reduce allocations in RouteValueDictionary. #1062
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Doesn’t this case leave the
_arrayStorageuninitialized now? All other cases have an explicit initialization but this case does not.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.
It does indeed leave array storage uninitialized, but that's not an issue as either:
-or-
When initialized, we always prefer property storage over array storage. Array storage can remain uninitialized when property storage is initialized.
When property storage is initialized, but we want to manipulate the values, then the property storage is transformed to array storage. This is done using
RouteValueDictionary.EnsureCapacitySlow(int capacity).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.
Ah cool, I missed that every use of the array storage would ensure the capacity before which would cause an initialization of the storage.
Since the checks always check whether the property storage is set (instead of checking when the array storage is not set), does it really make such a difference to not initialize the array storage to an empty array by default? All those
_arrayStorage = Array.Empty…lines really seem verbose when they are always executed except in the one case where an explicit array is being set, or when the property storage is being set which does not need the array storage to be not set though.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.
I just thought it would be clearer when either
_propertyStorageor_arrayStoragewould be initialized, and not both.