Skip to content

Commit 2288165

Browse files
committed
---
yaml --- r: 228833 b: refs/heads/try c: f910d27 h: refs/heads/master i: 228831: be406c4 v: v3
1 parent 81e5356 commit 2288165

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 381d2ed70d3f3c2913e19a950dee0da0149dae1d
4+
refs/heads/try: f910d27f87419e17cc59034265f6795db5247dfa
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/libcore/hash/sip.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
//! An implementation of SipHash 2-4.
1212
13+
use ptr;
1314
use prelude::*;
1415
use super::Hasher;
1516

@@ -65,6 +66,20 @@ macro_rules! u8to64_le {
6566
});
6667
}
6768

69+
/// Load a full u64 word from a byte stream, in LE order. Use
70+
/// `copy_nonoverlapping` to let the compiler generate the most efficient way
71+
/// to load u64 from a possibly unaligned address.
72+
///
73+
/// Unsafe because: unchecked indexing at i..i+8
74+
#[inline]
75+
unsafe fn load_u64_le(buf: &[u8], i: usize) -> u64 {
76+
debug_assert!(i + 8 <= buf.len());
77+
let mut data = 0u64;
78+
ptr::copy_nonoverlapping(buf.get_unchecked(i),
79+
&mut data as *mut _ as *mut u8, 8);
80+
data.to_le()
81+
}
82+
6883
macro_rules! rotl {
6984
($x:expr, $b:expr) =>
7085
(($x << $b) | ($x >> (64_i32.wrapping_sub($b))))
@@ -151,7 +166,7 @@ impl SipHasher {
151166

152167
let mut i = needed;
153168
while i < end {
154-
let mi = u8to64_le!(msg, i);
169+
let mi = unsafe { load_u64_le(msg, i) };
155170

156171
self.v3 ^= mi;
157172
compress!(self.v0, self.v1, self.v2, self.v3);

0 commit comments

Comments
 (0)