More efficient padding (#11656)
This commit is contained in:
parent
750e5344f1
commit
f1ba2387d3
|
@ -147,9 +147,10 @@ pub fn serialize_parameters_aligned(
|
|||
v.write_u64::<LittleEndian>(keyed_account.data_len()? as u64)
|
||||
.unwrap();
|
||||
v.write_all(&keyed_account.try_account_ref()?.data).unwrap();
|
||||
for _ in 0..16 - (v.len() % 16) {
|
||||
v.write_u8(0).unwrap(); // 128 bit aligned again
|
||||
}
|
||||
v.resize(
|
||||
v.len() + (v.len() as *const u8).align_offset(align_of::<u128>()),
|
||||
0,
|
||||
);
|
||||
v.write_u64::<LittleEndian>(keyed_account.rent_epoch()? as u64)
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -188,7 +189,7 @@ pub fn deserialize_parameters_aligned(
|
|||
.data
|
||||
.clone_from_slice(&buffer[start..end]);
|
||||
start += keyed_account.data_len()?; // data
|
||||
start += 16 - (start % 16); // padding
|
||||
start += (start as *const u8).align_offset(align_of::<u128>());
|
||||
start += mem::size_of::<u64>(); // rent_epoch
|
||||
} else {
|
||||
start += 7; // padding
|
||||
|
|
Binary file not shown.
|
@ -297,7 +297,7 @@ static bool sol_deserialize(
|
|||
uint64_t data_len = *(uint64_t *) input;
|
||||
input += sizeof(uint64_t);
|
||||
input += data_len;
|
||||
input += 16 - (data_len % 16); // padding
|
||||
input = (uint8_t*)(((uint64_t)input + 8 - 1) & ~(8 - 1)); // padding
|
||||
input += sizeof(uint64_t);
|
||||
}
|
||||
continue;
|
||||
|
@ -334,8 +334,7 @@ static bool sol_deserialize(
|
|||
input += sizeof(uint64_t);
|
||||
params->ka[i].data = (uint8_t *) input;
|
||||
input += params->ka[i].data_len;
|
||||
|
||||
input += 16 - (params->ka[i].data_len % 16); // padding
|
||||
input = (uint8_t*)(((uint64_t)input + 8 - 1) & ~(8 - 1)); // padding
|
||||
|
||||
// rent epoch
|
||||
params->ka[i].rent_epoch = *(uint64_t *) input;
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubk
|
|||
use alloc::vec::Vec;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
mem::size_of,
|
||||
mem::{align_of, size_of},
|
||||
rc::Rc,
|
||||
// Hide Result from bindgen gets confused about generics in non-generic type declarations
|
||||
result::Result as ResultGeneric,
|
||||
|
@ -80,7 +80,7 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
|
|||
let executable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
offset += 4; // padding
|
||||
offset += size_of::<u32>(); // padding to u64
|
||||
|
||||
let key: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
@ -100,8 +100,7 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
|
|||
from_raw_parts_mut(input.add(offset), data_len)
|
||||
}));
|
||||
offset += data_len;
|
||||
|
||||
offset += 16 - (offset % 16); // padding
|
||||
offset += (offset as *const u8).align_offset(align_of::<u128>()); // padding
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let rent_epoch = *(input.add(offset) as *const u64);
|
||||
|
|
Loading…
Reference in New Issue