Skip to content

Commit 093f9fb

Browse files
committed
Hold a reference to byte arrays when serializing to bech32
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.
1 parent 052e7c3 commit 093f9fb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lightning-invoice/src/ser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) trait Base32Len: Base32Iterable {
2929

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

0 commit comments

Comments
 (0)