Skip to content

Commit adeb730

Browse files
committed
std: cut down on the memory usage of SipHasher
1 parent 72b5e30 commit adeb730

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/libstd/hash/sip.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -231,31 +231,31 @@ impl Default for SipState {
231231
/// `SipHasher` computes the SipHash algorithm from a stream of bytes.
232232
#[deriving(Clone)]
233233
pub struct SipHasher {
234-
priv state: SipState,
234+
priv k0: u64,
235+
priv k1: u64,
235236
}
236237

237238
impl SipHasher {
238239
/// Create a `Sip`.
239240
#[inline]
240241
pub fn new() -> SipHasher {
241-
SipHasher {
242-
state: SipState::new(),
243-
}
242+
SipHasher::new_with_keys(0, 0)
244243
}
245244

246245
/// Create a `Sip` that is keyed off the provided keys.
247246
#[inline]
248247
pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher {
249248
SipHasher {
250-
state: SipState::new_with_keys(key0, key1),
249+
k0: key0,
250+
k1: key1,
251251
}
252252
}
253253
}
254254

255255
impl Hasher<SipState> for SipHasher {
256256
#[inline]
257257
fn hash<T: Hash<SipState>>(&self, value: &T) -> u64 {
258-
let mut state = self.state.clone();
258+
let mut state = SipState::new_with_keys(self.k0, self.k1);
259259
value.hash(&mut state);
260260
state.result()
261261
}

0 commit comments

Comments
 (0)