get rid of unnecessary data copy (#16214)
* get rid of unnecessary data copy * preserve rent_epoch
This commit is contained in:
committed by
GitHub
parent
e57975de26
commit
a5dcee254d
@ -204,17 +204,9 @@ impl PreAccount {
|
|||||||
|
|
||||||
pub fn update(&mut self, account: &AccountSharedData) {
|
pub fn update(&mut self, account: &AccountSharedData) {
|
||||||
let mut pre = self.account.borrow_mut();
|
let mut pre = self.account.borrow_mut();
|
||||||
|
let rent_epoch = pre.rent_epoch();
|
||||||
pre.lamports = account.lamports;
|
*pre = account.clone();
|
||||||
pre.owner = account.owner;
|
pre.set_rent_epoch(rent_epoch);
|
||||||
pre.executable = account.executable;
|
|
||||||
if pre.data().len() != account.data().len() {
|
|
||||||
// Only system account can change data size, copy with alloc
|
|
||||||
pre.set_data(account.data().clone());
|
|
||||||
} else {
|
|
||||||
// Copy without allocate
|
|
||||||
pre.data_as_mut_slice().clone_from_slice(&account.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
self.changed = true;
|
self.changed = true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user