File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
compiler/rustc_data_structures/src Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,18 @@ impl<H: Hasher> FingerprintHasher for H {
103
103
impl FingerprintHasher for crate :: unhash:: Unhasher {
104
104
#[ inline]
105
105
fn write_fingerprint ( & mut self , fingerprint : & Fingerprint ) {
106
- // `Unhasher` only wants a single `u64`
106
+ // Even though both halves of the fingerprint are expected to be good
107
+ // quality hash values, let's still combine the two values because the
108
+ // Fingerprints in DefPathHash have the StableCrateId portion which is
109
+ // the same for all DefPathHashes from the same crate. Combining the
110
+ // two halfs makes sure we get a good quality hash in such cases too.
111
+ //
112
+ // Since `Unhasher` is used only in the context of HashMaps, it is OK
113
+ // to combine the two components in an order-independent way (which is
114
+ // cheaper than the more robust Fingerprint::to_smaller_hash()). For
115
+ // HashMaps we don't really care if Fingerprint(x,y) and
116
+ // Fingerprint(y, x) result in the same hash value. Collision
117
+ // probability will still be much better than with FxHash.
107
118
self . write_u64 ( fingerprint. 0 . wrapping_add ( fingerprint. 1 ) ) ;
108
119
}
109
120
}
You can’t perform that action at this time.
0 commit comments