mirror of
https://github.com/apple/swift-crypto
synced 2026-11-23 04:34:21 +00:00
* Remove array allocation when computing digest Instead of creating a temporary array, the digest bytes are stored in a temporary stack-allocated buffer. This reduces the number of heap allocations needed to hash a message from 7 to 6. * Store digest context inline This reduces the number of heap allocations needed to hash a message from 6 to 2. Before: 1. the DigestContext object is created 2. the EVP_MD_CTX struct is allocated by EVP_MD_CTX_new 3. md_data is allocated when initializing the context After: 1. the DigestContext object is created In both cases, the number is doubled because COW happens during finalize(). * Use temporary variable to finalize context This reduces the number of heap allocations needed to hash a message from 2 to 1. --------- Co-authored-by: Cory Benfield <lukasa@apple.com>