remove all use of mem::uninitialized and mem::copy_nonoverlapping
This commit is contained in:
parent
deda031975
commit
9f092a6f31
|
@ -82,15 +82,9 @@ macro_rules! impl_array_newtype {
|
|||
impl<'a> From<&'a [$ty]> for $thing {
|
||||
fn from(data: &'a [$ty]) -> $thing {
|
||||
assert_eq!(data.len(), $len);
|
||||
unsafe {
|
||||
use std::intrinsics::copy_nonoverlapping;
|
||||
use std::mem;
|
||||
let mut ret: $thing = mem::uninitialized();
|
||||
copy_nonoverlapping(data.as_ptr(),
|
||||
ret.as_mut_ptr(),
|
||||
$len);
|
||||
ret
|
||||
}
|
||||
let mut ret = [0; $len];
|
||||
ret.copy_from_slice(&data[..]);
|
||||
$thing(ret)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,18 +187,15 @@ macro_rules! impl_array_newtype_encodable {
|
|||
fn visit_seq<V>(&mut self, mut v: V) -> Result<$thing, V::Error>
|
||||
where V: ::serde::de::SeqVisitor
|
||||
{
|
||||
unsafe {
|
||||
use std::mem;
|
||||
let mut ret: [$ty; $len] = mem::uninitialized();
|
||||
for item in ret.iter_mut() {
|
||||
*item = match try!(v.visit()) {
|
||||
Some(c) => c,
|
||||
None => return Err(::serde::de::Error::end_of_stream())
|
||||
};
|
||||
}
|
||||
try!(v.end());
|
||||
Ok($thing(ret))
|
||||
let mut ret: [$ty; $len] = [0; $len];
|
||||
for item in ret.iter_mut() {
|
||||
*item = match try!(v.visit()) {
|
||||
Some(c) => c,
|
||||
None => return Err(::serde::de::Error::end_of_stream())
|
||||
};
|
||||
}
|
||||
try!(v.end());
|
||||
Ok($thing(ret))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,14 +68,10 @@ impl fmt::Debug for Address {
|
|||
|
||||
impl Clone for Address {
|
||||
fn clone(&self) -> Address {
|
||||
unsafe {
|
||||
use std::intrinsics::copy_nonoverlapping;
|
||||
use std::mem;
|
||||
let mut ret = mem::uninitialized();
|
||||
copy_nonoverlapping(self,
|
||||
&mut ret,
|
||||
mem::size_of::<Address>());
|
||||
ret
|
||||
Address {
|
||||
services: self.services,
|
||||
address: self.address,
|
||||
port: self.port,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ impl Sha256dHash {
|
|||
}
|
||||
|
||||
let bytes = s.as_bytes();
|
||||
let mut ret: [u8; 32] = unsafe { mem::uninitialized() };
|
||||
let mut ret = [0; 32];
|
||||
for i in 0..32 {
|
||||
let hi = match bytes[2*i] {
|
||||
b @ b'0'...b'9' => (b - b'0') as u8,
|
||||
|
@ -314,9 +314,9 @@ impl serde::Serialize for Sha256dHash {
|
|||
where S: serde::Serializer,
|
||||
{
|
||||
unsafe {
|
||||
use std::{char, mem, str};
|
||||
use std::{char, str};
|
||||
|
||||
let mut string: [u8; 64] = mem::uninitialized();
|
||||
let mut string = [0; 64];
|
||||
for i in 0..32 {
|
||||
string[2 * i] = char::from_digit((self.0[31 - i] / 0x10) as u32, 16).unwrap() as u8;
|
||||
string[2 * i + 1] = char::from_digit((self.0[31 - i] & 0x0f) as u32, 16).unwrap() as u8;
|
||||
|
|
Loading…
Reference in New Issue