about summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-02-14 01:37:50 +0000
committerbors <bors@rust-lang.org>2020-02-14 01:37:50 +0000
commit21ed50522ddb998f5367229984a4510af578899f (patch)
tree1b6195db57d69b4b442e4542dd45db6cea77b305 /src/librustc_data_structures
parent10104085e4f9f52f405fa1cc5e5e18c4c4cc72d1 (diff)
parent5206827933177ab83e91c38042597b9061c85b96 (diff)
downloadrust-21ed50522ddb998f5367229984a4510af578899f.tar.gz
rust-21ed50522ddb998f5367229984a4510af578899f.zip
Auto merge of #68693 - Zoxc:query-no-arc, r=michaelwoerister
Construct query job latches on-demand

r? @michaelwoerister
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r--src/librustc_data_structures/sharded.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/librustc_data_structures/sharded.rs b/src/librustc_data_structures/sharded.rs
index ee3f88ff167..15d1e2dd0b6 100644
--- a/src/librustc_data_structures/sharded.rs
+++ b/src/librustc_data_structures/sharded.rs
@@ -69,12 +69,21 @@ impl<T> Sharded<T> {
     /// `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> {
+    pub fn get_shard_index_by_hash(&self, hash: u64) -> usize {
         let hash_len = mem::size_of::<usize>();
         // Ignore the top 7 bits as hashbrown uses these and get the next SHARD_BITS highest bits.
         // hashbrown also uses the lowest bits, so we can't use those
         let bits = (hash >> (hash_len * 8 - 7 - SHARD_BITS)) as usize;
-        let i = bits % SHARDS;
+        bits % SHARDS
+    }
+
+    #[inline]
+    pub fn get_shard_by_hash(&self, hash: u64) -> &Lock<T> {
+        &self.shards[self.get_shard_index_by_hash(hash)].0
+    }
+
+    #[inline]
+    pub fn get_shard_by_index(&self, i: usize) -> &Lock<T> {
         &self.shards[i].0
     }