Reduce defensive copying in PublicKey #97108
Merged
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.
The bypasses a few more defensive copies in
PublicKey
.AsnEncodedData(AsnEncodedData)
makes a defensive copy of the data for itself, which the constructor ofPublicKey
uses. However, there are a few factory methods inPublicKey
that create anAsnEncodedData
solely for the purpose of transferring toPublicKey
. In that circumstance, we can bypass the copy since the creation of theAsnEncodedData
already made the defensive copy.Likewise for
X509Certificate2.PublicKey
. This shaves several hundred bytes in allocation, scaling with the key size.