Skip to content

Commit ced4b9c

Browse files
committed
Merge rust-bitcoin#4969: perf: optimize Vec creation in bip152 tests
22b4331 perf: optimize Vec creation in bip152 tests (Conger Rassen) Pull request description: Replace `[0u8; 32].to_vec()` with `vec![0u8; 32]` to avoid unnecessary intermediate array allocation on the stack. The `vec!` macro directly allocates on the heap, eliminating the copy operation and improving both memory usage and performance. ACKs for top commit: apoelstra: ACK 22b4331; successfully ran local tests Tree-SHA512: db19d32643377a740a223f2058b66534a0955cff2c0c3e6013b9e31afa28f16527775d43a690dc9cfe95fd7a0a2a25b88ef89b6365f80e3d8e75aaacbdb46f67
2 parents 795ac3e + 22b4331 commit ced4b9c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bitcoin/src/bip152.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ mod test {
544544
for testcase in testcases {
545545
{
546546
// test deserialization
547-
let mut raw: Vec<u8> = [0u8; 32].to_vec();
547+
let mut raw: Vec<u8> = vec![0u8; 32];
548548
raw.extend(testcase.0.clone());
549549
let btr: BlockTransactionsRequest = deserialize(&raw.to_vec()).unwrap();
550550
assert_eq!(testcase.1, btr.indexes);

0 commit comments

Comments
 (0)