Skip to content

Commit

Permalink
Refactors TieredStorageFile read/write methods (#34147)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Nov 17, 2023
1 parent 9bb82a3 commit e23bfb5
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions accounts-db/src/tiered_storage/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@ impl TieredStorageFile {

pub fn write_type<T>(&self, value: &T) -> IoResult<usize> {
let ptr = value as *const _ as *const u8;
let slice = unsafe { std::slice::from_raw_parts(ptr, mem::size_of::<T>()) };
(&self.0).write_all(slice)?;

Ok(std::mem::size_of::<T>())
let bytes = unsafe { std::slice::from_raw_parts(ptr, mem::size_of::<T>()) };
self.write_bytes(bytes)
}

pub fn read_type<T>(&self, value: &mut T) -> IoResult<()> {
let ptr = value as *mut _ as *mut u8;
let slice = unsafe { std::slice::from_raw_parts_mut(ptr, mem::size_of::<T>()) };
(&self.0).read_exact(slice)?;

Ok(())
let bytes = unsafe { std::slice::from_raw_parts_mut(ptr, mem::size_of::<T>()) };
self.read_bytes(bytes)
}

pub fn seek(&self, offset: u64) -> IoResult<u64> {
Expand All @@ -65,8 +61,6 @@ impl TieredStorageFile {
}

pub fn read_bytes(&self, buffer: &mut [u8]) -> IoResult<()> {
(&self.0).read_exact(buffer)?;

Ok(())
(&self.0).read_exact(buffer)
}
}

0 comments on commit e23bfb5

Please sign in to comment.