about summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2019-11-01 08:52:14 +1100
committerNicholas Nethercote <nnethercote@mozilla.com>2019-11-04 10:15:55 +1100
commit1aceaaa969d85195966e453590cbfc68771bf904 (patch)
tree532279a17abc0c00c22481366e65954081e7e47f /src/librustc_data_structures
parentb497e18995d6b6992f97512c6b86b5cb3f2f34f5 (diff)
downloadrust-1aceaaa969d85195966e453590cbfc68771bf904.tar.gz
rust-1aceaaa969d85195966e453590cbfc68771bf904.zip
Avoid hashing the key twice in `get_query()`.
For a single-threaded parallel compiler, this reduces instruction counts
across several benchmarks, by up to 2.8%.

The commit also adds documentation about `Sharded`'s use of `FxHasher`.
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r--src/librustc_data_structures/sharded.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/librustc_data_structures/sharded.rs b/src/librustc_data_structures/sharded.rs
index 2f972eeccdc..a28a5e0f041 100644
--- a/src/librustc_data_structures/sharded.rs
+++ b/src/librustc_data_structures/sharded.rs
@@ -60,6 +60,7 @@ impl<T> Sharded<T> {
         }
     }
 
+    /// The shard is selected by hashing `val` with `FxHasher`.
     #[inline]
     pub fn get_shard_by_value<K: Hash + ?Sized>(&self, val: &K) -> &Lock<T> {
         if SHARDS == 1 {
@@ -69,6 +70,11 @@ impl<T> Sharded<T> {
         }
     }
 
+    /// Get a shard with a pre-computed hash value. If `get_shard_by_value` is
+    /// ever used in combination with `get_shard_by_hash` on a single `Sharded`
+    /// instance, then `hash` must be computed with `FxHasher`. Otherwise,
+    /// `hash` can be computed with any hasher, so long as that hasher is used
+    /// consistently for each `Sharded` instance.
     #[inline]
     pub fn get_shard_by_hash(&self, hash: u64) -> &Lock<T> {
         let hash_len = mem::size_of::<usize>();