More strongly-type multiple fields and return types#2242
Merged
Conversation
Some of these, like JsonClaimSet._jsonClaims, help to avoid allocation by ensuring that when the collection is enumerated, we're using its struct enumerator. In other cases, like with CreateClaimFromObject, we reduce the overhead of calls to the object. And other cases are just good hygiene.
19c1c7a to
652de25
Compare
brentschmaltz
approved these changes
Aug 22, 2023
saviour123
reviewed
Aug 28, 2023
| return _claims; | ||
| } | ||
|
|
||
| internal IList<Claim> CreateClaims(string issuer) |
There was a problem hiding this comment.
@stephentoub Notice you changed all Interfaces to Concrete Subtypes. Just curious what is the benefit or advantage of this.
Collaborator
Author
There was a problem hiding this comment.
Some of the advantages were noted in the PR description.
For example, if you have:
IList<T> list = ...;
foreach (T item in list) { ... }that allocates an IEnumerator<T> object. If you instead have:
List<T> list = ...;
foreach (T item in list) { ... }it doesn't, instead using the List<T>.Enumerator struct for enumeration.
But even just simple accesses, e.g.
IList<T> list = ...;
return list[2];That involves interface dispatch, which is not only slower than a regular method invocation:
List<T> list = ...;
return list[2];but without a technology like dynamic PGO, it can't be inlined.
Contributor
|
Included in preview4 release |
brentschmaltz
pushed a commit
that referenced
this pull request
Sep 6, 2023
Some of these, like JsonClaimSet._jsonClaims, help to avoid allocation by ensuring that when the collection is enumerated, we're using its struct enumerator. In other cases, like with CreateClaimFromObject, we reduce the overhead of calls to the object. And other cases are just good hygiene.
brentschmaltz
pushed a commit
that referenced
this pull request
Sep 7, 2023
Some of these, like JsonClaimSet._jsonClaims, help to avoid allocation by ensuring that when the collection is enumerated, we're using its struct enumerator. In other cases, like with CreateClaimFromObject, we reduce the overhead of calls to the object. And other cases are just good hygiene.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Some of these, like JsonClaimSet._jsonClaims, help to avoid allocation by ensuring that when the collection is enumerated, we're using its struct enumerator. In other cases, like with CreateClaimFromObject, we reduce the overhead of calls to the object. And other cases are just good hygiene.