Skip to content

Commit

Permalink
rename MSIZE to SERIALIZED_LEN (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine authored Mar 20, 2024
1 parent 6d7e02e commit 7b2acf6
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 69 deletions.
4 changes: 2 additions & 2 deletions firewood/benches/hashops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ fn bench_merkle<const N: usize>(criterion: &mut Criterion) {

#[allow(clippy::unwrap_used)]
let merkle_payload_header_ref = StoredView::ptr_to_obj(
&InMemLinearStore::new(2 * CompactHeader::MSIZE, 9),
&InMemLinearStore::new(2 * CompactHeader::SERIALIZED_LEN, 9),
merkle_payload_header,
CompactHeader::MSIZE,
CompactHeader::SERIALIZED_LEN,
)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion firewood/benches/shale-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn serialize<T: CachedStore>(m: &T) {
let compact_header_obj: DiskAddress = DiskAddress::from(0x0);
#[allow(clippy::unwrap_used)]
let _: Obj<CompactSpaceHeader> =
StoredView::ptr_to_obj(m, compact_header_obj, CompactHeader::MSIZE).unwrap();
StoredView::ptr_to_obj(m, compact_header_obj, CompactHeader::SERIALIZED_LEN).unwrap();
}

fn bench_cursors(c: &mut Criterion) {
Expand Down
6 changes: 3 additions & 3 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ impl Db {
let db_header: DiskAddress = DiskAddress::from(offset);
offset += DbHeader::MSIZE as usize;
let merkle_payload_header: DiskAddress = DiskAddress::from(offset);
offset += CompactSpaceHeader::MSIZE as usize;
offset += CompactSpaceHeader::SERIALIZED_LEN as usize;
assert!(offset <= SPACE_RESERVED as usize);

let mut merkle_meta_store = StoreRevMut::new(cached_space.merkle.meta.clone());
Expand Down Expand Up @@ -757,7 +757,7 @@ impl Db {
StoredView::ptr_to_obj(
meta_ref,
payload_header,
shale::compact::CompactHeader::MSIZE,
shale::compact::CompactHeader::SERIALIZED_LEN,
)
.map_err(Into::into)
}
Expand All @@ -777,7 +777,7 @@ impl Db {
// TODO: This should be a compile time check
const DB_OFFSET: u64 = Db::PARAM_SIZE;
let merkle_offset = DB_OFFSET + DbHeader::MSIZE;
assert!(merkle_offset + CompactSpaceHeader::MSIZE <= SPACE_RESERVED);
assert!(merkle_offset + CompactSpaceHeader::SERIALIZED_LEN <= SPACE_RESERVED);

let mut db_header_ref = header_refs.0;
let merkle_payload_header_ref = header_refs.1;
Expand Down
2 changes: 1 addition & 1 deletion firewood/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ mod tests {
let compact_header = shale::StoredView::ptr_to_obj(
&dm,
compact_header,
shale::compact::CompactHeader::MSIZE,
shale::compact::CompactHeader::SERIALIZED_LEN,
)
.unwrap();
let mem_meta = dm;
Expand Down
6 changes: 3 additions & 3 deletions firewood/src/merkle/node/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl BranchNode {

impl Storable for BranchNode {
fn serialized_len(&self) -> u64 {
let children_len = Self::MAX_CHILDREN as u64 * DiskAddress::MSIZE;
let children_len = Self::MAX_CHILDREN as u64 * DiskAddress::SERIALIZED_LEN;
let value_len = optional_value_len::<ValueLen, _>(self.value.as_deref());
let children_encoded_len = self.children_encoded.iter().fold(0, |len, child| {
len + optional_value_len::<EncodedChildLen, _>(child.as_ref())
Expand Down Expand Up @@ -226,7 +226,7 @@ impl Storable for BranchNode {
const PATH_LEN_SIZE: u64 = size_of::<PathLen>() as u64;
const VALUE_LEN_SIZE: usize = size_of::<ValueLen>();
const BRANCH_HEADER_SIZE: u64 =
BranchNode::MAX_CHILDREN as u64 * DiskAddress::MSIZE + VALUE_LEN_SIZE as u64;
BranchNode::MAX_CHILDREN as u64 * DiskAddress::SERIALIZED_LEN + VALUE_LEN_SIZE as u64;

let path_len = mem
.get_view(addr, PATH_LEN_SIZE)
Expand Down Expand Up @@ -270,7 +270,7 @@ impl Storable for BranchNode {

let mut cursor = Cursor::new(node_raw.as_deref());
let mut children = [None; BranchNode::MAX_CHILDREN];
let mut buf = [0u8; DiskAddress::MSIZE as usize];
let mut buf = [0u8; DiskAddress::SERIALIZED_LEN as usize];

for child in &mut children {
cursor.read_exact(&mut buf)?;
Expand Down
9 changes: 6 additions & 3 deletions firewood/src/merkle_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ where
)
.expect("write should succeed");
#[allow(clippy::unwrap_used)]
let compact_header =
StoredView::ptr_to_obj(&dm, compact_header, shale::compact::CompactHeader::MSIZE)
.unwrap();
let compact_header = StoredView::ptr_to_obj(
&dm,
compact_header,
shale::compact::CompactHeader::SERIALIZED_LEN,
)
.unwrap();
let mem_meta = dm;
let mem_payload = InMemLinearStore::new(compact_size, 0x1);

Expand Down
Loading

0 comments on commit 7b2acf6

Please sign in to comment.