]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_data_structures/sharded.rs
Rollup merge of #66789 - eddyb:mir-source-scope-local-data, r=oli-obk
[rust.git] / src / librustc_data_structures / sharded.rs
index 2f972eeccdcbd2494477483ea16c3ba14abf4b8d..a28a5e0f0415a575a8c32683f36153c7674b3b9f 100644 (file)
@@ -60,6 +60,7 @@ pub fn new(mut value: impl FnMut() -> T) -> Self {
         }
     }
 
+    /// 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 @@ pub fn get_shard_by_value<K: Hash + ?Sized>(&self, val: &K) -> &Lock<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>();