From e23bfb5167bab7077615b3537e85738468be3b97 Mon Sep 17 00:00:00 2001 From: Brooks Date: Fri, 17 Nov 2023 14:17:49 -0500 Subject: [PATCH] Refactors TieredStorageFile read/write methods (#34147) --- accounts-db/src/tiered_storage/file.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/accounts-db/src/tiered_storage/file.rs b/accounts-db/src/tiered_storage/file.rs index 6d5397f812b784..43fce184986615 100644 --- a/accounts-db/src/tiered_storage/file.rs +++ b/accounts-db/src/tiered_storage/file.rs @@ -36,18 +36,14 @@ impl TieredStorageFile { pub fn write_type(&self, value: &T) -> IoResult { let ptr = value as *const _ as *const u8; - let slice = unsafe { std::slice::from_raw_parts(ptr, mem::size_of::()) }; - (&self.0).write_all(slice)?; - - Ok(std::mem::size_of::()) + let bytes = unsafe { std::slice::from_raw_parts(ptr, mem::size_of::()) }; + self.write_bytes(bytes) } pub fn read_type(&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::()) }; - (&self.0).read_exact(slice)?; - - Ok(()) + let bytes = unsafe { std::slice::from_raw_parts_mut(ptr, mem::size_of::()) }; + self.read_bytes(bytes) } pub fn seek(&self, offset: u64) -> IoResult { @@ -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) } }