Revert "removed unsafe code in favor of explicit assert"

This reverts commit 479d756c99.

There’s nothing wrong with this patch, but I had never pulled this
commit to my local repository and had completely forgotten about it, and
today removed the unsafe code in a *different* direction that I like
better (`bytes.try_into().map(|bytes| u64::from_ne_bytes(bytes))`), so
reverting it so I can cleanly rebase is just easier for me!
This commit is contained in:
Chris Morgan 2022-01-26 00:12:16 +11:00
parent 6dab74b721
commit 8abad057b0

View file

@ -10,6 +10,7 @@ use std::hash::{Hasher, BuildHasherDefault};
#[cfg(test)] #[cfg(test)]
use std::mem; use std::mem;
use std::ops::{Index, IndexMut}; use std::ops::{Index, IndexMut};
use std::ptr;
use any::{Any, UncheckedAnyExt}; use any::{Any, UncheckedAnyExt};
@ -22,11 +23,10 @@ impl Hasher for TypeIdHasher {
#[inline] #[inline]
fn write(&mut self, bytes: &[u8]) { fn write(&mut self, bytes: &[u8]) {
// This expects to receive one and exactly one 64-bit value // This expects to receive one and exactly one 64-bit value
assert!(bytes.len() == 8); debug_assert!(bytes.len() == 8);
self.value = u64::from(bytes[0]) | u64::from(bytes[1]) << 8 | unsafe {
u64::from(bytes[2]) << 16 | u64::from(bytes[3]) << 24 | ptr::copy_nonoverlapping(&bytes[0] as *const u8 as *const u64, &mut self.value, 1)
u64::from(bytes[4]) << 32 | u64::from(bytes[5]) << 40 | }
u64::from(bytes[6]) << 48 | u64::from(bytes[7]) << 56;
} }
#[inline] #[inline]