about summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2019-11-15 18:36:20 +0900
committerGitHub <noreply@github.com>2019-11-15 18:36:20 +0900
commit22c0f628df2353e121650b7618dd4bd71535c2bf (patch)
treea25a20bdd2fe1a8ab7d79bf64d84d01a22cf8d36 /src/librustc_data_structures
parent00c0c31554bec14a05f38e15fa698bcb839e998c (diff)
parent1aceaaa969d85195966e453590cbfc68771bf904 (diff)
downloadrust-22c0f628df2353e121650b7618dd4bd71535c2bf.tar.gz
rust-22c0f628df2353e121650b7618dd4bd71535c2bf.zip
Rollup merge of #66013 - nnethercote:avoid-hashing-twice-in-get_query, r=Zoxc
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`.

r? @Zoxc
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>();