Skip to content

Commit 1c9f942

Browse files
Urgaumichaelwoerister
authored andcommitted
Remove StableHasher::finalize by inlining it's routine
1 parent cb8e141 commit 1c9f942

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Unreleased
22

3+
- Remove `StableHasher::finalize` (#4)
34
- Import stable hasher implementation from rustc ([db8aca48129](https://github.com/rust-lang/rust/blob/db8aca48129d86b2623e3ac8cbcf2902d4d313ad/compiler/rustc_data_structures/src/))

src/stable_hasher.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod tests;
1010

1111
/// Trait for retrieving the result of the stable hashing operation.
1212
pub trait StableHasherResult: Sized {
13-
fn finish(hasher: StableHasher) -> Self;
13+
fn finish(hash: (u64, u64)) -> Self;
1414
}
1515

1616
/// When hashing something that ends up affecting properties like symbol names,
@@ -40,12 +40,7 @@ impl StableHasher {
4040

4141
#[inline]
4242
pub fn finish<W: StableHasherResult>(self) -> W {
43-
W::finish(self)
44-
}
45-
46-
#[inline]
47-
pub fn finalize(self) -> (u64, u64) {
48-
self.state.finish128()
43+
W::finish(self.state.finish128())
4944
}
5045
}
5146

src/stable_hasher/tests.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ use super::*;
99
// ways). The expected values depend on the hashing algorithm used, so they
1010
// need to be updated whenever StableHasher changes its hashing algorithm.
1111

12+
#[derive(Debug, PartialEq)]
13+
struct TestHash((u64, u64));
14+
15+
impl StableHasherResult for TestHash {
16+
fn finish(hash: (u64, u64)) -> TestHash {
17+
TestHash(hash)
18+
}
19+
}
20+
1221
#[test]
1322
fn test_hash_integers() {
1423
// Test that integers are handled consistently across platforms.
@@ -41,9 +50,9 @@ fn test_hash_integers() {
4150
test_isize.hash(&mut h);
4251

4352
// This depends on the hashing algorithm. See note at top of file.
44-
let expected = (13997337031081104755, 6178945012502239489);
53+
let expected = TestHash((13997337031081104755, 6178945012502239489));
4554

46-
assert_eq!(h.finalize(), expected);
55+
assert_eq!(expected, h.finish());
4756
}
4857

4958
#[test]
@@ -55,9 +64,9 @@ fn test_hash_usize() {
5564
test_usize.hash(&mut h);
5665

5766
// This depends on the hashing algorithm. See note at top of file.
58-
let expected = (12037165114281468837, 3094087741167521712);
67+
let expected = TestHash((12037165114281468837, 3094087741167521712));
5968

60-
assert_eq!(h.finalize(), expected);
69+
assert_eq!(expected, h.finish());
6170
}
6271

6372
#[test]
@@ -69,15 +78,15 @@ fn test_hash_isize() {
6978
test_isize.hash(&mut h);
7079

7180
// This depends on the hashing algorithm. See note at top of file.
72-
let expected = (3979067582695659080, 2322428596355037273);
81+
let expected = TestHash((3979067582695659080, 2322428596355037273));
7382

74-
assert_eq!(h.finalize(), expected);
83+
assert_eq!(expected, h.finish());
7584
}
7685

77-
fn hash<T: Hash>(t: &T) -> (u64, u64) {
86+
fn hash<T: Hash>(t: &T) -> TestHash {
7887
let mut h = StableHasher::new();
7988
t.hash(&mut h);
80-
h.finalize()
89+
h.finish()
8190
}
8291

8392
// Check that the `isize` hashing optimization does not produce the same hash when permuting two

0 commit comments

Comments
 (0)