Skip to content

Commit

Permalink
blockstore: Use Vec::from() instead of slice::to_vec() (#4047)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
steviez authored Dec 11, 2024
1 parent a929aa6 commit 484b8f3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}"),
)))
Expand Down Expand Up @@ -2410,7 +2410,7 @@ impl Blockstore {
) -> std::result::Result<Vec<Shred>, 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()
}

Expand Down

0 comments on commit 484b8f3

Please sign in to comment.