]> git.lizzy.rs Git - rust.git/commitdiff
Stop using an upgradeable read lock in interning
authorJonas Schievink <jonasschievink@gmail.com>
Fri, 2 Apr 2021 18:46:37 +0000 (20:46 +0200)
committerJonas Schievink <jonasschievink@gmail.com>
Fri, 2 Apr 2021 18:46:37 +0000 (20:46 +0200)
Only one upgradeable read lock can be handed out at the same time, and
we never acquire a non-upgradeable read lock, so this has no benefit
over just using a write lock in the first place.

crates/hir_def/src/intern.rs

index cc0b5d3503916ae471c80737288476252a380972..bc0307dbc9acd786731eb304e3f295699cb25495 100644 (file)
@@ -25,7 +25,7 @@ pub fn new(obj: T) -> Self {
         let storage = T::storage().get();
         let shard_idx = storage.determine_map(&obj);
         let shard = &storage.shards()[shard_idx];
-        let shard = shard.upgradeable_read();
+        let mut shard = shard.write();
 
         // Atomically,
         // - check if `obj` is already in the map
@@ -43,10 +43,7 @@ pub fn new(obj: T) -> Self {
         let arc = Arc::new(obj);
         let arc2 = arc.clone();
 
-        {
-            let mut shard = shard.upgrade();
-            shard.insert(arc2, SharedValue::new(()));
-        }
+        shard.insert(arc2, SharedValue::new(()));
 
         Self { arc }
     }