Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use copy_from_slice() over clone_from_slice() for u8 slice copies #33536

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ledger/src/blockstore_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ impl Column for columns::TransactionStatus {
fn key((index, signature, slot): (u64, Signature, Slot)) -> Vec<u8> {
let mut key = vec![0; 8 + 64 + 8]; // size_of u64 + size_of Signature + size_of Slot
BigEndian::write_u64(&mut key[0..8], index);
key[8..72].clone_from_slice(&signature.as_ref()[0..64]);
key[8..72].copy_from_slice(&signature.as_ref()[0..64]);
BigEndian::write_u64(&mut key[72..80], slot);
key
}
Expand Down Expand Up @@ -777,9 +777,9 @@ impl Column for columns::AddressSignatures {
fn key((index, pubkey, slot, signature): (u64, Pubkey, Slot, Signature)) -> Vec<u8> {
let mut key = vec![0; 8 + 32 + 8 + 64]; // size_of u64 + size_of Pubkey + size_of Slot + size_of Signature
BigEndian::write_u64(&mut key[0..8], index);
key[8..40].clone_from_slice(&pubkey.as_ref()[0..32]);
key[8..40].copy_from_slice(&pubkey.as_ref()[0..32]);
BigEndian::write_u64(&mut key[40..48], slot);
key[48..112].clone_from_slice(&signature.as_ref()[0..64]);
key[48..112].copy_from_slice(&signature.as_ref()[0..64]);
key
}

Expand Down Expand Up @@ -812,7 +812,7 @@ impl Column for columns::TransactionMemos {

fn key(signature: Signature) -> Vec<u8> {
let mut key = vec![0; 64]; // size_of Signature
key[0..64].clone_from_slice(&signature.as_ref()[0..64]);
key[0..64].copy_from_slice(&signature.as_ref()[0..64]);
key
}

Expand Down Expand Up @@ -905,7 +905,7 @@ impl Column for columns::ProgramCosts {

fn key(pubkey: Pubkey) -> Vec<u8> {
let mut key = vec![0; 32]; // size_of Pubkey
key[0..32].clone_from_slice(&pubkey.as_ref()[0..32]);
key[0..32].copy_from_slice(&pubkey.as_ref()[0..32]);
key
}

Expand Down