break apart AccountInfo (#30505)

This commit is contained in:
Jeff Washington (jwash) 2023-02-24 13:35:27 -06:00 committed by GitHub
parent 7c086ca42d
commit efc5cc4a48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 4 deletions

View File

@ -87,6 +87,11 @@ pub struct AccountInfo {
/// index identifying the append storage
store_id: AppendVecId,
account_offset_and_flags: AccountOffsetAndFlags,
}
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)]
pub struct AccountOffsetAndFlags {
/// offset = 'packed_offset_and_flags.offset_reduced()' * ALIGN_BOUNDARY_OFFSET into the storage
/// Note this is a smaller type than 'Offset'
packed_offset_and_flags: PackedOffsetAndFlags,
@ -94,13 +99,18 @@ pub struct AccountInfo {
impl ZeroLamport for AccountInfo {
fn is_zero_lamport(&self) -> bool {
self.packed_offset_and_flags.is_zero_lamport()
self.account_offset_and_flags
.packed_offset_and_flags
.is_zero_lamport()
}
}
impl IsCached for AccountInfo {
fn is_cached(&self) -> bool {
self.packed_offset_and_flags.offset_reduced() == CACHED_OFFSET
self.account_offset_and_flags
.packed_offset_and_flags
.offset_reduced()
== CACHED_OFFSET
}
}
@ -137,9 +147,12 @@ impl AccountInfo {
}
};
packed_offset_and_flags.set_is_zero_lamport(lamports == 0);
let account_offset_and_flags = AccountOffsetAndFlags {
packed_offset_and_flags,
};
Self {
store_id,
packed_offset_and_flags,
account_offset_and_flags,
}
}
@ -154,7 +167,11 @@ impl AccountInfo {
}
pub fn offset(&self) -> Offset {
Self::reduced_offset_to_offset(self.packed_offset_and_flags.offset_reduced())
Self::reduced_offset_to_offset(
self.account_offset_and_flags
.packed_offset_and_flags
.offset_reduced(),
)
}
fn reduced_offset_to_offset(reduced_offset: OffsetReduced) -> Offset {