Skip to content

Commit 1d6ea73

Browse files
nkysgnkysggsy
authored andcommittedMar 22, 2025
test: use Vec::with_capacity avoid realloc mem
1 parent 4019a50 commit 1d6ea73

File tree

1 file changed

+2
-2
lines changed
  • crates/starknet-types-core/src/felt

1 file changed

+2
-2
lines changed
 

‎crates/starknet-types-core/src/felt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ mod test {
10761076
// Helper function to generate a vector of bits for testing purposes
10771077
fn generate_be_bits(x: &Felt) -> Vec<bool> {
10781078
// Initialize an empty vector to store the expected bits
1079-
let mut bits = Vec::new();
1079+
let mut bits = Vec::with_capacity(x.0.representative().limbs.len() * 8 * 8);
10801080

10811081
// Iterate over each limb in the representative of x
10821082
for limb in x.0.representative().limbs {
@@ -1831,7 +1831,7 @@ mod test {
18311831
bytes[31 - (i >> 1)] |= 15 << (4 * (i & 1));
18321832
}
18331833
let h = Felt::from_bytes_be(&bytes);
1834-
let mut res = Vec::new();
1834+
let mut res = Vec::with_capacity(enc_len(n_nibbles));
18351835
assert!(h.serialize(&mut res).is_ok());
18361836
assert_eq!(res.len(), enc_len(n_nibbles));
18371837
let mut reader = &res[..];

0 commit comments

Comments
 (0)