Skip to content

Use serialize() instead of to_vec() for signatures - #1050

Merged
apoelstra merged 2 commits into
rust-bitcoin:masterfrom
vadim-anfv:refactor/serialize-signatures
Sep 18, 2026
Merged

apoelstra merged 2 commits into
rust-bitcoin:masterfrom
vadim-anfv:refactor/serialize-signatures

Conversation

@vadim-anfv

Copy link
Copy Markdown
Contributor

Replace to_vec() with serialize() on signatures where an owned Vec<u8> is not needed.

The remaining to_vec() calls on signatures are left as is: an owned Vec<u8> is required there by public API or by surrounding code.

Closes #687

`to_vec()` allocated a `Vec` just to read its length.
`serialize()` yields the same bytes on the stack,
without a heap allocation.
The helper built signature bytes via `to_vec()` and by appending
the sighash byte to DER by hand. Tests only need `&[u8]`, so store
`SerializedSignature` instead.

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 80fe83b; successfully ran local tests

@apoelstra
apoelstra merged commit fc2bd50 into rust-bitcoin:master Sep 18, 2026
13 checks passed
@vadim-anfv
vadim-anfv deleted the refactor/serialize-signatures branch September 18, 2026 13:48
Sign up for free to 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.

Remove unnecessary allocations in signatures.to_vec

2 participants