From 484b8f3ba878336fd1d66dd78798f6e1fef6ead2 Mon Sep 17 00:00:00 2001 From: steviez Date: Wed, 11 Dec 2024 11:49:42 -0600 Subject: [PATCH] blockstore: Use Vec::from() instead of slice::to_vec() (#4047) Vec::from() on a Box<[T]> takes over the heap allocation whereas slice::to_vec() copies the contents into a new Vec. We don't need the old Box<[u8]> so transferring ownership is sufficient here --- ledger/src/blockstore.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 7731925f6b4417..363218488f5dec 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -2350,7 +2350,7 @@ impl Blockstore { self.slot_data_iterator(slot, start_index) .expect("blockstore couldn't fetch iterator") .map(|(_, bytes)| { - Shred::new_from_serialized_shred(bytes.to_vec()).map_err(|err| { + Shred::new_from_serialized_shred(Vec::from(bytes)).map_err(|err| { BlockstoreError::InvalidShredData(Box::new(bincode::ErrorKind::Custom( format!("Could not reconstruct shred from shred payload: {err:?}"), ))) @@ -2410,7 +2410,7 @@ impl Blockstore { ) -> std::result::Result, shred::Error> { self.slot_coding_iterator(slot, start_index) .expect("blockstore couldn't fetch iterator") - .map(|code| Shred::new_from_serialized_shred(code.1.to_vec())) + .map(|(_, bytes)| Shred::new_from_serialized_shred(Vec::from(bytes))) .collect() }