ReadableAccount.data returns slice (#16686)

* ReadAbleAccount.data returns slice

* more slice fixup

* more slice

* slice
This commit is contained in:
Jeff Washington (jwash) 2021-04-20 16:41:16 -05:00 committed by GitHub
parent 08d5253651
commit 03f7b251b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 18 deletions

View File

@ -420,7 +420,7 @@ mod tests {
assert_eq!(key, *account_info.key); assert_eq!(key, *account_info.key);
let account = account.borrow(); let account = account.borrow();
assert_eq!(account.lamports, account_info.lamports()); assert_eq!(account.lamports, account_info.lamports());
assert_eq!(&account.data()[..], &account_info.data.borrow()[..]); assert_eq!(account.data(), &account_info.data.borrow()[..]);
assert_eq!(&account.owner, account_info.owner); assert_eq!(&account.owner, account_info.owner);
assert_eq!(account.executable, account_info.executable); assert_eq!(account.executable, account_info.executable);
assert_eq!(account.rent_epoch, account_info.rent_epoch); assert_eq!(account.rent_epoch, account_info.rent_epoch);
@ -466,8 +466,8 @@ mod tests {
let account = account.borrow(); let account = account.borrow();
assert_eq!(account.lamports, de_keyed_account.lamports().unwrap()); assert_eq!(account.lamports, de_keyed_account.lamports().unwrap());
assert_eq!( assert_eq!(
&account.data()[..], account.data(),
&de_keyed_account.try_account_ref().unwrap().data()[..] de_keyed_account.try_account_ref().unwrap().data()
); );
assert_eq!(account.owner, de_keyed_account.owner().unwrap()); assert_eq!(account.owner, de_keyed_account.owner().unwrap());
assert_eq!(account.executable, de_keyed_account.executable().unwrap()); assert_eq!(account.executable, de_keyed_account.executable().unwrap());
@ -492,7 +492,7 @@ mod tests {
assert_eq!(key, *account_info.key); assert_eq!(key, *account_info.key);
let account = account.borrow(); let account = account.borrow();
assert_eq!(account.lamports, account_info.lamports()); assert_eq!(account.lamports, account_info.lamports());
assert_eq!(&account.data()[..], &account_info.data.borrow()[..]); assert_eq!(account.data(), &account_info.data.borrow()[..]);
assert_eq!(&account.owner, account_info.owner); assert_eq!(&account.owner, account_info.owner);
assert_eq!(account.executable, account_info.executable); assert_eq!(account.executable, account_info.executable);
assert_eq!(account.rent_epoch, account_info.rent_epoch); assert_eq!(account.rent_epoch, account_info.rent_epoch);
@ -525,8 +525,8 @@ mod tests {
let account = account.borrow(); let account = account.borrow();
assert_eq!(account.lamports, de_keyed_account.lamports().unwrap()); assert_eq!(account.lamports, de_keyed_account.lamports().unwrap());
assert_eq!( assert_eq!(
&account.data()[..], account.data(),
&de_keyed_account.try_account_ref().unwrap().data()[..] de_keyed_account.try_account_ref().unwrap().data()
); );
assert_eq!(account.owner, de_keyed_account.owner().unwrap()); assert_eq!(account.owner, de_keyed_account.owner().unwrap());
assert_eq!(account.executable, de_keyed_account.executable().unwrap()); assert_eq!(account.executable, de_keyed_account.executable().unwrap());

View File

@ -51,7 +51,7 @@ fn append_vec_sequential_read(bencher: &mut Bencher) {
println!("reading pos {} {}", sample, pos); println!("reading pos {} {}", sample, pos);
let (account, _next) = vec.get_account(pos).unwrap(); let (account, _next) = vec.get_account(pos).unwrap();
let (_meta, test) = create_test_account(sample); let (_meta, test) = create_test_account(sample);
assert_eq!(account.data, test.data().as_slice()); assert_eq!(account.data, test.data());
indexes.push((sample, pos)); indexes.push((sample, pos));
}); });
} }
@ -66,7 +66,7 @@ fn append_vec_random_read(bencher: &mut Bencher) {
let (sample, pos) = &indexes[random_index]; let (sample, pos) = &indexes[random_index];
let (account, _next) = vec.get_account(*pos).unwrap(); let (account, _next) = vec.get_account(*pos).unwrap();
let (_meta, test) = create_test_account(*sample); let (_meta, test) = create_test_account(*sample);
assert_eq!(account.data, test.data().as_slice()); assert_eq!(account.data, test.data());
}); });
} }
@ -95,7 +95,7 @@ fn append_vec_concurrent_append_read(bencher: &mut Bencher) {
let (sample, pos) = *indexes.lock().unwrap().get(random_index).unwrap(); let (sample, pos) = *indexes.lock().unwrap().get(random_index).unwrap();
let (account, _next) = vec.get_account(pos).unwrap(); let (account, _next) = vec.get_account(pos).unwrap();
let (_meta, test) = create_test_account(sample); let (_meta, test) = create_test_account(sample);
assert_eq!(account.data, test.data().as_slice()); assert_eq!(account.data, test.data());
}); });
} }
@ -115,7 +115,7 @@ fn append_vec_concurrent_read_append(bencher: &mut Bencher) {
let (sample, pos) = *indexes1.lock().unwrap().get(random_index % len).unwrap(); let (sample, pos) = *indexes1.lock().unwrap().get(random_index % len).unwrap();
let (account, _next) = vec1.get_account(pos).unwrap(); let (account, _next) = vec1.get_account(pos).unwrap();
let (_meta, test) = create_test_account(sample); let (_meta, test) = create_test_account(sample);
assert_eq!(account.data, test.data().as_slice()); assert_eq!(account.data, test.data());
}); });
bencher.iter(|| { bencher.iter(|| {
let sample: usize = thread_rng().gen_range(0, 256); let sample: usize = thread_rng().gen_range(0, 256);

View File

@ -520,7 +520,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
result = self result = self
.account_db .account_db
.load_with_fixed_root(self.ancestors, id) .load_with_fixed_root(self.ancestors, id)
.map(|(account, _)| Rc::new(account.data().clone())); .map(|(account, _)| Rc::new(account.data().to_vec()));
// Cache it // Cache it
self.sysvars.push((*id, result.clone())); self.sysvars.push((*id, result.clone()));
} }
@ -919,7 +919,7 @@ impl MessageProcessor {
dst_keyed_account.try_account_ref_mut()?.owner = src_keyed_account.owner; dst_keyed_account.try_account_ref_mut()?.owner = src_keyed_account.owner;
dst_keyed_account dst_keyed_account
.try_account_ref_mut()? .try_account_ref_mut()?
.set_data(src_keyed_account.data().clone()); .set_data(src_keyed_account.data().to_vec());
} }
} }
} }

View File

@ -154,7 +154,7 @@ impl NativeLoader {
// still exists even after invoke_context.remove_first_keyed_account() is called // still exists even after invoke_context.remove_first_keyed_account() is called
( (
*program.unsigned_key(), *program.unsigned_key(),
&program.try_account_ref()?.data().clone(), &program.try_account_ref()?.data().to_vec(),
) )
}; };

View File

@ -94,7 +94,7 @@ pub trait WritableAccount: ReadableAccount {
pub trait ReadableAccount: Sized { pub trait ReadableAccount: Sized {
fn lamports(&self) -> u64; fn lamports(&self) -> u64;
fn data(&self) -> &Vec<u8>; fn data(&self) -> &[u8];
fn owner(&self) -> &Pubkey; fn owner(&self) -> &Pubkey;
fn executable(&self) -> bool; fn executable(&self) -> bool;
fn rent_epoch(&self) -> Epoch; fn rent_epoch(&self) -> Epoch;
@ -104,7 +104,7 @@ impl ReadableAccount for Account {
fn lamports(&self) -> u64 { fn lamports(&self) -> u64 {
self.lamports self.lamports
} }
fn data(&self) -> &Vec<u8> { fn data(&self) -> &[u8] {
&self.data &self.data
} }
fn owner(&self) -> &Pubkey { fn owner(&self) -> &Pubkey {
@ -189,7 +189,7 @@ impl ReadableAccount for AccountSharedData {
fn lamports(&self) -> u64 { fn lamports(&self) -> u64 {
self.lamports self.lamports
} }
fn data(&self) -> &Vec<u8> { fn data(&self) -> &[u8] {
&self.data &self.data
} }
fn owner(&self) -> &Pubkey { fn owner(&self) -> &Pubkey {
@ -207,7 +207,7 @@ impl ReadableAccount for Ref<'_, AccountSharedData> {
fn lamports(&self) -> u64 { fn lamports(&self) -> u64 {
self.lamports self.lamports
} }
fn data(&self) -> &Vec<u8> { fn data(&self) -> &[u8] {
&self.data &self.data
} }
fn owner(&self) -> &Pubkey { fn owner(&self) -> &Pubkey {
@ -225,7 +225,7 @@ impl ReadableAccount for Ref<'_, Account> {
fn lamports(&self) -> u64 { fn lamports(&self) -> u64 {
self.lamports self.lamports
} }
fn data(&self) -> &Vec<u8> { fn data(&self) -> &[u8] {
&self.data &self.data
} }
fn owner(&self) -> &Pubkey { fn owner(&self) -> &Pubkey {