Skip to content

Commit

Permalink
Hold a reference to byte arrays when serializing to bech32
Browse files Browse the repository at this point in the history
When we serialize from a byte array to bech32 in
`lightning-invoice`, we can either copy the array itself into the
iterator or hold a reference to the array and iterate through that.

In aa2f6b4 we opted to copy the
array into the iterator, which is fine for the current array sizes
we're working with, but does result in additional memory on the
stack if, in the future, we end up writing large arrays.

Instead, here, we switch to using the slice serialization code when
writing arrays, (very marginally) reducing code size and reducing
stack usage.
  • Loading branch information
TheBlueMatt committed Oct 3, 2024
1 parent 052e7c3 commit 093f9fb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lightning-invoice/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) trait Base32Len: Base32Iterable {

impl<const N: usize> Base32Iterable for [u8; N] {
fn fe_iter<'s>(&'s self) -> Box<dyn Iterator<Item = Fe32> + 's> {
Box::new((*self).into_iter().bytes_to_fes())
Box::new(self.iter().copied().bytes_to_fes())
}
}

Expand Down

0 comments on commit 093f9fb

Please sign in to comment.