Skip to content

Commit

Permalink
The scope of the unsafe block can be appropriately reduced (#263)
Browse files Browse the repository at this point in the history
* Shrink unsafe block

* Remove empty lines

---------

Co-authored-by: Martin Robinson <[email protected]>
  • Loading branch information
cactter and mrobinson authored Aug 9, 2024
1 parent 021012e commit 471ca0d
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,28 +383,24 @@ impl<Static: StaticAtomSet> Atom<Static> {

#[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) }
}

0 comments on commit 471ca0d

Please sign in to comment.