Use initialCapacity in ASN.1 templates for some primitives #81626
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.
In our ASN.1 templated encoding, we encode managed values with
AsnWriterto determine if they are equal todefaultDerInit.For some primitives types, like an ASN.1 Boolean and ASN.1 Integer (where the integer is known to be a managed
int) this has some waste asAsnWriterhas an initial capacity of 1024 bytes.For booleans, we know the encoded length is always going to be 3 bytes for DER. For integers (where the backing type is
int) we know it will encode to at most 6 bytes.Where possible, let's give these size hints to reduce the initial allocation size. For example, the
Criticalboolean in X.509 extensions has a default. Before and after of encoding a basic constraints extension: