Skip to content

Commit 204d0c7

Browse files
committed
---
yaml --- r: 235904 b: refs/heads/stable c: f910d27 h: refs/heads/master v: v3
1 parent 68595d7 commit 204d0c7

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
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 381d2ed70d3f3c2913e19a950dee0da0149dae1d
32+
refs/heads/stable: f910d27f87419e17cc59034265f6795db5247dfa
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/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)