Skip to content

der_derive: rewrite EncodeValue::value_len as simple addition - #1810

Merged
tarcieri merged 1 commit into
RustCrypto:masterfrom
dishmaker:dishmaker/der_value_len_sum_lengths
May 5, 2025
Merged

der_derive: rewrite EncodeValue::value_len as simple addition#1810
tarcieri merged 1 commit into
RustCrypto:masterfrom
dishmaker:dishmaker/der_value_len_sum_lengths

Conversation

@dishmaker

@dishmakerdishmaker commented May 5, 2025

Copy link
Copy Markdown
Contributor

Fixes#1800

This PR replaces

[..].into_iter().try_fold(..)

with a simple addition.

cargo llvm-lines
Before: 57722
After: 56603
./formats$ cargo llvm-lines --release -p x509-cert | head -20
Lines Copies Function name
----- ------ -------------
56603 1235 (TOTAL)
2065 (3.6%, 3.6%) 59 (4.8%, 4.8%) <T as der::encode::Encode>::encoded_len
1791 (3.2%, 6.8%) 25 (2.0%, 6.8%) core::iter::traits::iterator::Iterator::try_fold
1728 (3.1%, 9.9%) 12 (1.0%, 7.8%) der::ord::iter_cmp
1708 (3.0%, 12.9%) 12 (1.0%, 8.7%) <der::reader::slice::SliceReader as der::reader::Reader>::read_nested
1597 (2.8%, 15.7%) 13 (1.1%, 9.8%) <T as der::decode::Decode>::decode
1343 (2.4%, 18.1%) 14 (1.1%, 10.9%) <der::reader::slice::SliceReader as der::reader::Reader>::finish
1240 (2.2%, 20.3%) 20 (1.6%, 12.6%) <T as der::ord::DerOrd>::der_cmp
1176 (2.1%, 22.3%) 21 (1.7%, 14.3%) der::encode::EncodeValue::header
1155 (2.0%, 24.4%) 1 (0.1%, 14.3%) x509_cert::attr::AttributeTypeAndValue::from_delimited_str
995 (1.8%, 26.1%) 1 (0.1%, 14.4%) <x509_cert::attr::AttributeTypeAndValue as core::fmt::Display>::fmt
852 (1.5%, 27.6%) 12 (1.0%, 15.4%) <der::asn1::context_specific::ContextSpecific<T> as der::tag::Tagged>::tag
837 (1.5%, 29.1%) 3 (0.2%, 15.6%) der::encode::Encode::encode_to_vec
754 (1.3%, 30.5%) 1 (0.1%, 15.7%) <x509_cert::ext::pkix::crl::dp::IssuingDistributionPoint as der::encode::EncodeValue>::value_len
664 (1.2%, 31.6%) 8 (0.6%, 16.4%) <T as der::encode::Encode>::encode
624 (1.1%, 32.7%) 12 (1.0%, 17.3%) <core::iter::adapters::zip::Zip<A,B> as core::iter::adapters::zip::ZipImpl<A,B>>::next
570 (1.0%, 33.7%) 15 (1.2%, 18.5%) <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::next
564 (1.0%, 34.7%) 12 (1.0%, 19.5%) <core::iter::adapters::zip::Zip<A,B> as core::iter::adapters::zip::ZipImpl<A,B>>::new

@tarcieri
tarcieri merged commit 76a97a6 into RustCrypto:masterMay 5, 2025
@tarcieritarcieri mentioned this pull request Feb 11, 2026
tarcieri added a commit that referenced this pull request Feb 11, 2026
## Added
- `Sequence`, `Enumerated` and `Choice` macros now support `#[asn1(error = Ty)]`
attribute that provides a custom error type for `Decode`/`DecodeValue`
implementations (#1560)
- `BitString` macro (#1720, #1733)
- `DecodeValue`, `EncodeValue` macros (#1722)
- Derive support for `APPLICATION` and `PRIVATE` tags (#1825)
- Impl `DecodeValue` for `Choice` (#1986)
## Changed
- Use `TryFrom` conversions for `asn1(type = ...)` (#1562)
- Rewrite `EncodeValue::value_len` as simple addition (#1810)
- Change OctetStringRef `&` handling due to `der` type changes
(#1998, #2040, #2043)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

der: derive(Sequence): value_len: try_fold generates a lot of llvm-ir

2 participants

@dishmaker@tarcieri