Skip to content

Commit cccf958

Browse files
committed
fix: on-chain serialization pre-allocates Vec (to avoid reallocations)
Add test for 5 Felt struct to the super roundtrip tests
1 parent ba60fd6 commit cccf958

File tree

8 files changed

+4295
-2447
lines changed

8 files changed

+4295
-2447
lines changed

felt-repr/onchain/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ pub trait ToFeltRepr {
9494

9595
/// Convenience method that allocates and returns a `Vec<Felt>`.
9696
fn to_felt_repr(&self) -> Vec<Felt> {
97-
let mut data = Vec::new();
97+
// Allocate ahead to avoid reallocations
98+
let mut data = Vec::with_capacity(256);
9899
self.write_felt_repr(&mut FeltWriter::new(&mut data));
99100
data
100101
}

felt-repr/tests/expected/onchain_five_felts_struct.hir

Lines changed: 1087 additions & 825 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)