removed unsafe code (#1466)
This commit is contained in:
parent
6895a56099
commit
4f56f8b27c
@ -557,7 +557,7 @@ macro_rules! construct_uint {
|
|||||||
($name:ident, $n_words:expr) => (
|
($name:ident, $n_words:expr) => (
|
||||||
/// Little-endian large integer type
|
/// Little-endian large integer type
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct $name(pub [u64; $n_words]);
|
pub struct $name(pub [u64; $n_words]);
|
||||||
|
|
||||||
impl Uint for $name {
|
impl Uint for $name {
|
||||||
@ -1126,14 +1126,6 @@ macro_rules! construct_uint {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature="dev", allow(derive_hash_xor_eq))] // We are pretty sure it's ok.
|
|
||||||
impl Hash for $name {
|
|
||||||
fn hash<H>(&self, state: &mut H) where H: Hasher {
|
|
||||||
unsafe { state.write(::std::slice::from_raw_parts(self.0.as_ptr() as *mut u8, self.0.len() * 8)); }
|
|
||||||
state.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,15 +132,10 @@ macro_rules! impl_hash {
|
|||||||
$size
|
$size
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove once slice::clone_from_slice is stable
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone_from_slice(&mut self, src: &[u8]) -> usize {
|
fn clone_from_slice(&mut self, src: &[u8]) -> usize {
|
||||||
let min = ::std::cmp::min($size, src.len());
|
let min = cmp::min($size, src.len());
|
||||||
let dst = &mut self.deref_mut()[.. min];
|
self.0[..min].copy_from_slice(&src[..min]);
|
||||||
let src = &src[.. min];
|
|
||||||
for i in 0..min {
|
|
||||||
dst[i] = src[i];
|
|
||||||
}
|
|
||||||
min
|
min
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +146,7 @@ macro_rules! impl_hash {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn copy_to(&self, dest: &mut[u8]) {
|
fn copy_to(&self, dest: &mut[u8]) {
|
||||||
let min = ::std::cmp::min($size, dest.len());
|
let min = cmp::min($size, dest.len());
|
||||||
dest[..min].copy_from_slice(&self.0[..min]);
|
dest[..min].copy_from_slice(&self.0[..min]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,14 +258,7 @@ impl <T>FromBytes for T where T: FixedHash {
|
|||||||
Ordering::Equal => ()
|
Ordering::Equal => ()
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
Ok(T::from_slice(bytes))
|
||||||
use std::{mem, ptr};
|
|
||||||
|
|
||||||
let mut res: T = mem::uninitialized();
|
|
||||||
ptr::copy(bytes.as_ptr(), res.as_slice_mut().as_mut_ptr(), T::len());
|
|
||||||
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user