From 471ca0d8978cf6ce7dbfd170e67a103cfe62b975 Mon Sep 17 00:00:00 2001 From: cactter <109739451+cactter@users.noreply.github.com> Date: Sat, 10 Aug 2024 00:53:57 +0800 Subject: [PATCH] The scope of the unsafe block can be appropriately reduced (#263) * Shrink unsafe block * Remove empty lines --------- Co-authored-by: Martin Robinson --- src/atom.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/atom.rs b/src/atom.rs index 7a3dea9..7e15357 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -383,28 +383,24 @@ impl Atom { #[inline(always)] fn inline_atom_slice(x: &NonZeroU64) -> &[u8] { - unsafe { let x: *const NonZeroU64 = x; let mut data = x as *const u8; // All except the lowest byte, which is first in little-endian, last in big-endian. if cfg!(target_endian = "little") { - data = data.offset(1); + data = unsafe { data.offset(1) }; } let len = 7; - slice::from_raw_parts(data, len) - } + unsafe { slice::from_raw_parts(data, len) } } #[inline(always)] -fn inline_atom_slice_mut(x: &mut u64) -> &mut [u8] { - unsafe { +fn inline_atom_slice_mut(x: &mut u64) -> &mut [u8] { let x: *mut u64 = x; let mut data = x as *mut u8; // All except the lowest byte, which is first in little-endian, last in big-endian. if cfg!(target_endian = "little") { - data = data.offset(1); + data = unsafe { data.offset(1) }; } let len = 7; - slice::from_raw_parts_mut(data, len) - } + unsafe { slice::from_raw_parts_mut(data, len) } }