diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2021-02-04 10:37:11 +0100 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2021-02-04 10:37:11 +0100 |
| commit | d4d8bdf52bd2a3ae0f581e6f7c347f6222a0f14c (patch) | |
| tree | 010fb4af3af784b5b769a8e31d827098f2354fa3 | |
| parent | 6a4878f61f80dd779102797007548f4c28a477ee (diff) | |
| download | rust-d4d8bdf52bd2a3ae0f581e6f7c347f6222a0f14c.tar.gz rust-d4d8bdf52bd2a3ae0f581e6f7c347f6222a0f14c.zip | |
Add documentation to Unhasher impl for Fingerprint.
| -rw-r--r-- | compiler/rustc_data_structures/src/fingerprint.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_data_structures/src/fingerprint.rs b/compiler/rustc_data_structures/src/fingerprint.rs index fecc51324cc..681b49e2ea9 100644 --- a/compiler/rustc_data_structures/src/fingerprint.rs +++ b/compiler/rustc_data_structures/src/fingerprint.rs @@ -103,7 +103,18 @@ impl<H: Hasher> FingerprintHasher for H { impl FingerprintHasher for crate::unhash::Unhasher { #[inline] fn write_fingerprint(&mut self, fingerprint: &Fingerprint) { - // `Unhasher` only wants a single `u64` + // Even though both halves of the fingerprint are expected to be good + // quality hash values, let's still combine the two values because the + // Fingerprints in DefPathHash have the StableCrateId portion which is + // the same for all DefPathHashes from the same crate. Combining the + // two halfs makes sure we get a good quality hash in such cases too. + // + // Since `Unhasher` is used only in the context of HashMaps, it is OK + // to combine the two components in an order-independent way (which is + // cheaper than the more robust Fingerprint::to_smaller_hash()). For + // HashMaps we don't really care if Fingerprint(x,y) and + // Fingerprint(y, x) result in the same hash value. Collision + // probability will still be much better than with FxHash. self.write_u64(fingerprint.0.wrapping_add(fingerprint.1)); } } |
