Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit adeb730

Browse files
committedFeb 28, 2014
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

Lines changed: 6 additions & 6 deletions
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
}

5 commit comments

Comments
 (5)

bors commented on Feb 28, 2014

@bors
Collaborator

saw approval from acrichto
at erickt@adeb730

bors commented on Feb 28, 2014

@bors
Collaborator

merging erickt/rust/hash = adeb730 into auto

bors commented on Feb 28, 2014

@bors
Collaborator

erickt/rust/hash = adeb730 merged ok, testing candidate = 31e9c94

bors commented on Feb 28, 2014

@bors
Collaborator

bors commented on Feb 28, 2014

@bors
Collaborator

fast-forwarding master to auto = 31e9c94

Please sign in to comment.