More efficient padding (#11656)

This commit is contained in:
Jack May
2020-08-17 10:24:34 -07:00
committed by GitHub
parent 750e5344f1
commit f1ba2387d3
4 changed files with 10 additions and 11 deletions

View File

@ -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