From 665bc0b149a2445af24f3636c93da142af055557 Mon Sep 17 00:00:00 2001 From: cactter Date: Fri, 22 Jul 2022 09:52:21 +0800 Subject: [PATCH 1/2] Shrink unsafe block --- src/atom.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/atom.rs b/src/atom.rs index 321b0a4..17863ef 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -361,28 +361,28 @@ 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 { + 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) } + } From 7c7044b8712271baf58d45f29d0ec79b703ae867 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Mon, 11 Mar 2024 10:49:53 +0100 Subject: [PATCH 2/2] Remove empty lines --- src/atom.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/atom.rs b/src/atom.rs index 17863ef..a55d6ae 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -361,7 +361,6 @@ impl Atom { #[inline(always)] fn inline_atom_slice(x: &NonZeroU64) -> &[u8] { - 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. @@ -369,13 +368,11 @@ fn inline_atom_slice(x: &NonZeroU64) -> &[u8] { data = unsafe { data.offset(1) }; } let len = 7; - unsafe { 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] { - +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. @@ -384,5 +381,4 @@ fn inline_atom_slice_mut(x: &mut u64) -> &mut [u8] { } let len = 7; unsafe { slice::from_raw_parts_mut(data, len) } - }