std: cut down on the memory usage of SipHasher

This commit is contained in:
Erick Tryzelaar 2014-02-26 20:46:57 -08:00
parent 72b5e30f6c
commit adeb730c77

View File

@ -231,23 +231,23 @@ fn default() -> SipState {
/// `SipHasher` computes the SipHash algorithm from a stream of bytes.
#[deriving(Clone)]
pub struct SipHasher {
priv state: SipState,
priv k0: u64,
priv k1: u64,
}
impl SipHasher {
/// Create a `Sip`.
#[inline]
pub fn new() -> SipHasher {
SipHasher {
state: SipState::new(),
}
SipHasher::new_with_keys(0, 0)
}
/// Create a `Sip` that is keyed off the provided keys.
#[inline]
pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher {
SipHasher {
state: SipState::new_with_keys(key0, key1),
k0: key0,
k1: key1,
}
}
}
@ -255,7 +255,7 @@ pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher {
impl Hasher<SipState> for SipHasher {
#[inline]
fn hash<T: Hash<SipState>>(&self, value: &T) -> u64 {
let mut state = self.state.clone();
let mut state = SipState::new_with_keys(self.k0, self.k1);
value.hash(&mut state);
state.result()
}