mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 13:51:50 +01:00
remove unnecessary unsafes
This commit is contained in:
parent
756227896b
commit
d1318a35a0
@ -85,7 +85,7 @@ flate2 = { version="1.0", optional = true, default-features = false }
|
|||||||
mio = "^0.6.13"
|
mio = "^0.6.13"
|
||||||
net2 = "0.2"
|
net2 = "0.2"
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
byteorder = "1"
|
byteorder = "1.2"
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
futures-cpupool = "0.1"
|
futures-cpupool = "0.1"
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::any::{Any, TypeId};
|
use std::any::{Any, TypeId};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::hash::{BuildHasherDefault, Hasher};
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::hash::{BuildHasherDefault, Hasher};
|
||||||
|
|
||||||
struct IdHasher {
|
struct IdHasher {
|
||||||
id: u64,
|
id: u64,
|
||||||
@ -16,7 +16,7 @@ impl Default for IdHasher {
|
|||||||
impl Hasher for IdHasher {
|
impl Hasher for IdHasher {
|
||||||
fn write(&mut self, bytes: &[u8]) {
|
fn write(&mut self, bytes: &[u8]) {
|
||||||
for &x in bytes {
|
for &x in bytes {
|
||||||
self.id.wrapping_add(x as u64);
|
self.id.wrapping_add(u64::from(x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
|
use byteorder::{ByteOrder, LittleEndian, NetworkEndian};
|
||||||
use byteorder::{ByteOrder, NetworkEndian};
|
|
||||||
use bytes::{BufMut, Bytes, BytesMut};
|
use bytes::{BufMut, Bytes, BytesMut};
|
||||||
use futures::{Async, Poll, Stream};
|
use futures::{Async, Poll, Stream};
|
||||||
use rand;
|
use rand;
|
||||||
use std::{fmt, ptr};
|
use std::fmt;
|
||||||
|
|
||||||
use body::Binary;
|
use body::Binary;
|
||||||
use error::PayloadError;
|
use error::PayloadError;
|
||||||
@ -115,8 +114,7 @@ impl Frame {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mask: &[u8] = &buf[idx..idx + 4];
|
let mask: &[u8] = &buf[idx..idx + 4];
|
||||||
let mask_u32: u32 =
|
let mask_u32 = LittleEndian::read_u32(mask);
|
||||||
unsafe { ptr::read_unaligned(mask.as_ptr() as *const u32) };
|
|
||||||
idx += 4;
|
idx += 4;
|
||||||
Some(mask_u32)
|
Some(mask_u32)
|
||||||
} else {
|
} else {
|
||||||
@ -185,8 +183,7 @@ impl Frame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mask: &[u8] = &chunk[idx..idx + 4];
|
let mask: &[u8] = &chunk[idx..idx + 4];
|
||||||
let mask_u32: u32 =
|
let mask_u32 = LittleEndian::read_u32(mask);
|
||||||
unsafe { ptr::read_unaligned(mask.as_ptr() as *const u32) };
|
|
||||||
idx += 4;
|
idx += 4;
|
||||||
Some(mask_u32)
|
Some(mask_u32)
|
||||||
} else {
|
} else {
|
||||||
@ -323,15 +320,10 @@ impl Frame {
|
|||||||
|
|
||||||
if genmask {
|
if genmask {
|
||||||
let mask = rand::random::<u32>();
|
let mask = rand::random::<u32>();
|
||||||
unsafe {
|
buf.put_u32_le(mask);
|
||||||
{
|
buf.extend_from_slice(payload.as_ref());
|
||||||
let buf_mut = buf.bytes_mut();
|
let pos = buf.len() - payload_len;
|
||||||
*(buf_mut as *mut _ as *mut u32) = mask;
|
apply_mask(&mut buf[pos..], mask);
|
||||||
buf_mut[4..payload_len + 4].copy_from_slice(payload.as_ref());
|
|
||||||
apply_mask(&mut buf_mut[4..], mask);
|
|
||||||
}
|
|
||||||
buf.advance_mut(payload_len + 4);
|
|
||||||
}
|
|
||||||
buf.into()
|
buf.into()
|
||||||
} else {
|
} else {
|
||||||
buf.put_slice(payload.as_ref());
|
buf.put_slice(payload.as_ref());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user